http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50

解决方案 »

  1.   

    System.Data.DataSet ds1 = new System.Data.DataSet();
    ds1 = rebind();
    if(ds1.Tables[0].Rows.Count<1)
    {
    lblShow.Text = "无数据可提供生成报表!";
    return;
    }
    rpt.SetDataSource(ds1.Tables[0]);// CrystalDecisions.Shared.ExportOptions crExportOptions = new CrystalDecisions.Shared.ExportOptions();
    CrystalDecisions.Shared.DiskFileDestinationOptions crDiskFileDestinationOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    string path = this.Server.MapPath("..\\...");
    string fname1 = "CrystalReport1" + System.DateTime.Now.Year + System.DateTime.Now.Month + System.DateTime.Now.Day + 
    System.DateTime.Now.Hour + System.DateTime.Now.Minute + System.DateTime.Now.Second + ".xls";
    string fname = path + "\\" + fname1; crDiskFileDestinationOptions.DiskFileName = fname;
    rpt.ExportOptions.DestinationOptions = crDiskFileDestinationOptions;
    rpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
    //格式化输出格式
    rpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
    rpt.Export(); Response.Write("<script language='JavaScript'>"+"\n");
    // Response.Write("window.open('../rpt/"+fname1+"')");
    Response.Write("window.open('" + fname1 + "')");
    Response.Write("</script>"+"\n");
      

  2.   

    好像不能解决我的问题吧。我知道如何把数据生成到一个excel文件的一个sheet中。但是我不知道如何把数据生成到一个excel文件的多个sheet中,并根据每个sheet的内容将sheet1、sheet2等改成与数据内容相对应的名字。
      

  3.   

    Excel.Application oExcel;
    Excel.Workbook oBook;
    Sheets sheets;
    _Worksheet worksheet;
    Range tempRange;
    Object oMissing= System.Reflection.Missing.Value;oExcel = new Excel.Application();
    oExcel.Visible =false;System.Data.DataTable dt=......;

    int i=0;
    while(i<dt.Rows.Count)
    { xlsFileName="Test";        oBook = oExcel.Workbooks.Open(xlsFileName,oMissing,oMissing,oMissing,
    oMissing,oMissing,oMissing,oMissing, oMissing,oMissing,oMissing,oMissing, oMissing,oMissing,oMissing);

             sheets = oBook.Worksheets;
    worksheet = (_Worksheet) sheets.get_Item("Summary"); //Summary是sheet名
    worksheet.Cells[1,1]="写单元格"; tempRange=worksheet.get_Range("A1","D3"); //Cell可以是变量
    worksheet.get_Range(("A1","A1")).EntireRow.Insert(oMissing,tempRange.EntireRow.Copy(oMissing)); worksheet = (_Worksheet) sheets.get_Item(NoOfSheets);
    worksheet.Copy(oMissing,sheets.get_Item(NoOfSheets)); //Change sheet name
    worksheet.Name=currentSubjectCode;
    worksheet.Cells[i,1]=dt.Rows[][].ToString();
    worksheet.Cells[i,2]=dt.Rows[][].ToString();
    worksheet.Cells[i,3]=dt.Rows[][].ToString();
    string strOverMax="=sum("+sheetName+"!AC"+1.ToString()+":AC10"+")"; //增加计算公式
    worksheet.Cells[ii,5]=strOverMax;//Add Hyperlinks of between CourseSessiones
    tempRange=worksheet.get_Range(worksheet.Cells[ii,1],worksheet.Cells[ii,2]);
    string strHyperlinks="#'"+currentSubjectCode+"'!"+tmpAnchorCell;
    worksheet.Hyperlinks.Add(tempRange,strHyperlinks,oMissing,oMissing,oMissing);
      

  4.   

    我给你的只是我的程序中的一些片断,你从里再结合一下帮助应该可以学会;帮助不在msdn上,那上面的不全,在office中
    c:\Program Files\Common Files\Microsoft Shared\Office10\1033
    那些是VBA的语法.