Excel本身可以看作一个DataBase, 你用OleDb连接上之后直接用Sql语句插入更快一点
解决方案 »
- 有用过HubbleDotNet 的吗?做搜索怎么样?
- vs2008 asp.net: Login控件
- 如何设置textbox中的默认值,就是说在注册页面中密码设置为默认值。
- vs2005部署中如何添加系统设备组建
- 今早发现多穿了条裤衩,按规矩散分庆祝.另外请教大家几个关于2005的问题
- 2005中如何在codebihand里引用web.config里的connectionstring节啊
- 请教批量修改得问题(ASP)
- 怎樣顯示一個隨机數呀?
- forms验证问题
- 如何在DATAGRID中加一栏
- netscape和IE6的问题。
- cookies问题 ASP.NET读ASP里的COOKISE,出现“未将对象引用设置到对象的实例”。
Microsoft Office Web Components 9.0using OWC;private void button1_Click(object sender, System.EventArgs e)
{
if(this.saveFileDialog1.ShowDialog() == DialogResult.OK)
{
strSvaeName =this.saveFileDialog1.FileName;
if(strSvaeName.Trim() !="")
{
this.WriteDataGrid2Excel(nu);
}
}
}private void WriteDataGrid2Excel( int num) //num 是字段列数
{
int count = strLie.Length -1;
SpreadsheetClass xlsheet = new SpreadsheetClass();
System.Data.SqlClient.SqlDataReader sqlReader = cb.GetDataReader(sql);
int numbercols = num;
int row=1;
for(int j = 0;j<this.listBox2.Items.Count ;j++)
{
xlsheet.ActiveSheet.Cells[row,j+1] = ((SQLDatabase.GetListbox)this.listBox2.Items[j]).Id;
}
while (sqlReader.Read())
{
for (int i=0;i<numbercols;i++)
{
xlsheet.ActiveSheet.Cells[row+1,i+1] = sqlReader.GetValue(i).ToString();
}
row++;
}
sqlReader.Close();
try
{
xlsheet.ActiveSheet.Export(strSvaeName,OWC.SheetExportActionEnum.ssExportActionNone);
MessageBox.Show(" 数据导出成功!","成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(System.Exception e)
{
MessageBox.Show(e.Message.ToString(),"error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}把sqlserver 记录生成execl文件速度狠快的。