http://xml.sz.luohuedu.net/xml/Content.asp孟子E章的网站你看左侧的链接,

解决方案 »

  1.   

    谢谢,不过是vb的,有没有c#的
      

  2.   

    http://expert.csdn.net/Expert/topic/2068/2068838.xml?temp=.4953424
      

  3.   

    另一个网上的
    首先把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(); } } 
      

  4.   

    补充下:上面说的tlbimp方法对office xp无效,最好直接在vs.net里面直接引用com,很方便