大虾们帮忙:怎样把一个datatable表到处成excel,又没现成的类 http://xml.sz.luohuedu.net/xml/Content.asp孟子E章的网站你看左侧的链接, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢,不过是vb的,有没有c#的 http://expert.csdn.net/Expert/topic/2068/2068838.xml?temp=.4953424 另一个网上的首先把COM组件"EXCEL9.OLB"拷贝到cs文件所在的目录下,然后输入下列命令: tlbimp excel9.olb 目录下面就产生了三个DLL文件:"Excel.dll"、"Office.dll"、"VBIDE.dll"。在产生了上面的三个文件后,这种转换就成功完成了。在下面的程序中,就可以利用这转换好的三个类库编写和Excel表格相关的各种操作了。 using System; using System.Reflection; using System.Data; using System.Data.SqlClient; public class CComDotNet { public static void Main() { try { Excel.Application excel=new Excel.Application( ); string filename="你的文件路径"; excel.Application.Workbooks.Add(filname); excel.Cells[ 1 , 1 ] = "第一行第一列" ; excel.Cells[ 1 , 2 ] = "第一行第二列" ; excel.Cells[ 2 , 1 ] = "第二行第一列" ; excel.Cells[ 2 , 2 ] = "第二行第二列" ; excel.Cells[ 3 , 1 ] = "第三行第一列" ; excel.Cells[ 3 , 2 ] = "第三行第二列" ; Excel.XlSaveAsAccessMode asm=Excel.XlSaveAsAccessMode.xlShared; object Nothing=System.Reflection.Missing.value; excel.Workbooks[1].SaveAs("另存文件的路径",Nothing,Nothing,Nothing,Nothing,Nothing,asm,Nothing,Nothing,Nothing,Nothing); excel.Workbooks.Close(); } catch(Exception e) { Console.WriteLine("Error Stack {0} ", e.Message) ; } finally { ; } } } 用:Csc.exe /r:excel.dll /r:office.dll /r:vbide.dll excel.cs 生成EXE文件 如果需要更多的EXCEL方法,可以用.net的OLE/COM游览器打开EXCEL9.OLE文件,可以看到所提供的详细方法。我现在做的一个东东是和数据库有关的,要把sql数据导出到excel,我已经可以导出来了,但是速度太慢,经常要导很就甚至导不出来,然而用户基本要经常导数据,并且数据量都在5000行以上,甚至更多,不知如何提高程序运行速度??敬请高手指教,定以高分相送!@!!!!我的导出方式:private System.Data.DataTable GetData() { SqlConnection conn= new SqlConnection(@"server=(local)\vste;uid=sa;pwd=;database=northwind;"); SqlDataAdapter adapter= new SqlDataAdapter("select * from Customers",conn); DataSet myDataSet= new DataSet(); try { adapter.Fill(myDataSet,"Customer"); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } return myDataSet.Tables[0]; } foreach(DataColumn col in table.Columns) { colIndex++; excel.Cells[1,colIndex]=col.ColumnName; } foreach(DataRow row in table.Rows) { rowIndex++; colIndex=0; foreach(DataColumn col in table.Columns) { colIndex++; excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString(); } } 补充下:上面说的tlbimp方法对office xp无效,最好直接在vs.net里面直接引用com,很方便 下载文件时如何知道是已更新的文件呢? 如何实现WINFORM中LABEL控件实现自定义进度条 求助,C#异步线程时间控制 winform连接数据库 C# 截屏问题 C#.net 应用程序如何打包安装 请教下现在的vs用哪一版比较好 在C#中怎么实现模糊查询 头痛的问题!! DataGrid问题,谢谢 第一次决定用C#.NTE做项目(B/S),想问一下高手们是怎么分工合作的? 将listbox绑定后要更改item内容的问题
首先把COM组件"EXCEL9.OLB"拷贝到cs文件所在的目录下,然后输入下列命令:
tlbimp excel9.olb
目录下面就产生了三个DLL文件:"Excel.dll"、"Office.dll"、"VBIDE.dll"。在产生了上面的三个文件后,这种转换就成功完成了。在下面的程序中,就可以利用这转换好的三个类库编写和Excel表格相关的各种操作了。 using System;
using System.Reflection;
using System.Data;
using System.Data.SqlClient; public class CComDotNet
{
public static void Main()
{
try
{
Excel.Application excel=new Excel.Application( );
string filename="你的文件路径";
excel.Application.Workbooks.Add(filname);
excel.Cells[ 1 , 1 ] = "第一行第一列" ;
excel.Cells[ 1 , 2 ] = "第一行第二列" ;
excel.Cells[ 2 , 1 ] = "第二行第一列" ;
excel.Cells[ 2 , 2 ] = "第二行第二列" ;
excel.Cells[ 3 , 1 ] = "第三行第一列" ;
excel.Cells[ 3 , 2 ] = "第三行第二列" ;
Excel.XlSaveAsAccessMode asm=Excel.XlSaveAsAccessMode.xlShared;
object Nothing=System.Reflection.Missing.value;
excel.Workbooks[1].SaveAs("另存文件的路径",Nothing,Nothing,Nothing,Nothing,Nothing,asm,Nothing,Nothing,Nothing,Nothing);
excel.Workbooks.Close();
}
catch(Exception e)
{
Console.WriteLine("Error Stack {0} ", e.Message) ;
}
finally
{
;
}
}
}
用:Csc.exe /r:excel.dll /r:office.dll /r:vbide.dll excel.cs 生成EXE文件 如果需要更多的EXCEL方法,可以用.net的OLE/COM游览器打开EXCEL9.OLE文件,可以看到所提供的详细方法。
我现在做的一个东东是和数据库有关的,要把sql数据导出到excel,我已经可以导出来了,但是速度太慢,经常要导很就甚至导不出来,然而用户基本要经常导数据,并且数据量都在5000行以上,甚至更多,不知如何提高程序运行速度??敬请高手指教,定以高分相送!@!!!!
我的导出方式:private System.Data.DataTable GetData() { SqlConnection conn= new SqlConnection(@"server=(local)\vste;uid=sa;pwd=;database=northwind;"); SqlDataAdapter adapter= new SqlDataAdapter("select * from Customers",conn); DataSet myDataSet= new DataSet(); try { adapter.Fill(myDataSet,"Customer"); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } return myDataSet.Tables[0]; }
foreach(DataColumn col in table.Columns) { colIndex++; excel.Cells[1,colIndex]=col.ColumnName; } foreach(DataRow row in table.Rows) { rowIndex++; colIndex=0; foreach(DataColumn col in table.Columns) { colIndex++; excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString(); } }