excel相关的代码
来源:互联网 发布:洛江网络布线 编辑:程序博客网 时间:2024/05/01 21:48
string SheetName = "sheet1";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/guanxi.xls" +
@";Extended Properties=""Excel 8.0;HDR=YES;""";
DbConnection connection = null;
DbProviderFactory factory =
DbProviderFactories.GetFactory("System.Data.OleDb");
using (connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
connection.Open();
try
{
command.CommandText = "CREATE TABLE [" + SheetName + "] (" +
"[phone] text,[msg] text,[result] text,[start] text,[spname] text,[ids] text)";
command.ExecuteNonQuery();
}
catch (Exception)
{
}
////////////////////////////////////////////////////////////
string strPath = Application.StartupPath;
// 用于保存没有标注Poi的路
FileStream fileUnMarkedPois = new FileStream(strPath + @"/error.txt",
FileMode.Create | FileMode.Append, FileAccess.Write);
StreamWriter swUnMarkedPois = new StreamWriter(fileUnMarkedPois,
System.Text.Encoding.GetEncoding("GB2312"));
string str;
int n = 0; ClientResult result;
DateTime t1 = DateTime.Now;
DateTime t2 = DateTime.Now;
for (int i = start; i < cl.Count && Running; i++)
{
CaseInfo info = null;
try
{
info = cl.Get(i);
if (info == null)
continue;
string temp = info.msg;
//sms.RecvMsg(int.Parse(info.moid), info.phoneNum, info.msg);
t1 = DateTime.Now;
command.CommandText = "INSERT INTO [" + SheetName + "$] (phone,msg,result,start,spname,ids) Values(";
command.CommandText += "'" + info.phoneNum + "',";
command.CommandText += "'" + SQLEscape(temp) + "',";
command.CommandText += "'" + SQLEscape(Result) + "',";
command.CommandText += "'" + ts.TotalMilliseconds.ToString() + "',";
command.CommandText += "'" + SQLEscape(result.SpName) + "',";
command.CommandText += "'" + SQLEscape(result.IDs) + "')";
command.ExecuteNonQuery();
str = i.ToString() + "/" + cl.Count.ToString();
textBoxInfo.Invoke(new DelegateTestAll(UpdateInfo), new object[] { str });
//n++;
//if (n >= 2000)
//{
// break;
//}
}
catch (Exception exp )
{
swUnMarkedPois.WriteLine(info.msg + " " + info.phoneNum);
swUnMarkedPois.WriteLine(exp.Message + exp.Source);
swUnMarkedPois.Flush();
}
}
swUnMarkedPois.Close();
fileUnMarkedPois.Close();
connection.Close();
}
}
}
catch (Exception exp)
{
// MessageBox.Show("打开excel出错");
throw exp;
}
- excel相关的代码
- Excel合并单元格相关代码
- 在写php时遇到的PHPExcel相关问题记录(含excel与mysql交互代码)
- Excel控件的相关属性
- python excel 的相关操作
- python excel 的相关操作
- Excel导入的相关问题
- python excel 的相关操作
- python excel 的相关操作
- 一段换汤不换药的代码-Excel和数据库中数据匹配并根据条件刷新数据相关数据的代码
- FSO 相关的代码
- FSO 相关的代码
- 博客的相关代码!
- 多线程相关的代码
- findpanel的相关代码
- 股票相关的代码
- 代码相关的用法
- C# Excel CSV DataTable DataSet 相关代码及资料整理
- [健康]饭后,你有这样的坏习惯吗?
- 人民币“破7”意味着什么
- 云风个人好书推荐 云风的blog:blog.codingnow.com
- 通告所有已婚男士:
- Java自学笔记之面向对象思想
- excel相关的代码
- J2EE架构的6个最佳实践
- 123
- 如何在MySQL中导入数据库
- 五月感想-3snews
- 4545455
- dsp版遗留物检测基本完工
- Fedora8下OCCI环境搭建
- uyjuyjj76j76j6