是写Excel
还是读Excel
我有实例
MSN:[email protected]

解决方案 »

  1.   

    Excel.ApplicationClass  xlapp = new Excel .ApplicationClass ();
    Excel.WorkbookClass xlbook=new Excel .WorkbookClass ();
    Excel.WorksheetClass sheet=new Excel .WorksheetClass ();        
                               //检索数据            //自定义的 
    SqlDataReader Reader=SqlString(sql1);
    int Row=1;
    int Col=1;
    while(Reader.Read ())
    {
        if(Col<Reader.FieldCount )
      xlapp.ActiveCell [1,Col]=Reader.GetName (Col-1).ToString ();
                    for(int i=0;i<Reader.FieldCount ;i++)
    xlapp.ActiveCell [Row+1,i+1]=Reader.GetValue (i).ToString ();
    Row++;
    Col++;
    }
        sheet.get_Range (sheet.Cells [1,1],sheet.Cells [1,Col-1]).Font.Name ="黑体";
                sheet.get_Range (sheet.Cells [1,1],sheet.Cells [1,Col-1]).Font.Bold  =true;
                sheet.get_Range (sheet.Cells [1,1],sheet.Cells [1,1]).Borders .LineStyle =1;
            xlapp.Visible =true;