Excel问题请教 http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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"); 好像不能解决我的问题吧。我知道如何把数据生成到一个excel文件的一个sheet中。但是我不知道如何把数据生成到一个excel文件的多个sheet中,并根据每个sheet的内容将sheet1、sheet2等改成与数据内容相对应的名字。 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 CourseSessionestempRange=worksheet.get_Range(worksheet.Cells[ii,1],worksheet.Cells[ii,2]);string strHyperlinks="#'"+currentSubjectCode+"'!"+tmpAnchorCell;worksheet.Hyperlinks.Add(tempRange,strHyperlinks,oMissing,oMissing,oMissing); 我给你的只是我的程序中的一些片断,你从里再结合一下帮助应该可以学会;帮助不在msdn上,那上面的不全,在office中c:\Program Files\Common Files\Microsoft Shared\Office10\1033那些是VBA的语法. 求一段无边框窗口改变打下的代码? 求教导出word的问题 更改基类? 不安全代码只会在使用 /unsafe 编译的情况下出现 B/S VS2005安装与MS SQL2000冲突.. DataGridView设置当前位置 C#关于数据库的问题 Dispose 和Close 以及null的区别 vs 2008中添加sql2000数据库错误 C# 利用性能计数器PerformanceCounter获取单进程CPU/RAM,在win7上可以,但在XP和windows 2003上报错,解决方法 C#入门经典 和 Visual C#入门经典有什么区别? 这两本书? 新手求助!
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");
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);
c:\Program Files\Common Files\Microsoft Shared\Office10\1033
那些是VBA的语法.