利用OWC组件生成EXCEL表(c#)
2007-02-05 10:49
525 查看
Microsoft.Office.Interop.Owc11.SpreadsheetClass oSheet= new SpreadsheetClass( );
XmlDocument xmlDoc = new XmlDocument( );
xmlDoc.Load(Server.MapPath("./Reports/")+"abc.xml");
string strXml =xmlDoc.DocumentElement.OuterXml;
oSheet.XMLData = strXml;
oSheet.Cells[2,12]=DateTime.Now.ToString("yyyyMMdd");//制表日期
int i=4;
if (Session["datatable"] != null)
oSheet.get_Range(oSheet.Cells[4,1], oSheet.Cells[i-1,3]).Borders.set_LineStyle(XlLineStyle.xlContinuous);
oSheet.get_Range(oSheet.Cells[4,1], oSheet.Cells[i-1,3]).Font.set_Size(10);
string desFileName="abc"+System.DateTime.Now.ToString("yyMMddHHmmssff")+".xls";
string desPathFileName=Server.MapPath("../ReportDocs/")+desFileName;
//輸出整理後的文件
oSheet.Export(desPathFileName, Microsoft.Office.Interop.Owc11.SheetExportActionEnum.ssExportActionNone, Microsoft.Office.Interop.Owc11.SheetExportFormat.ssExportXMLSpreadsheet);
string path = desPathFileName;
System.IO.FileInfo file = new System.IO.FileInfo(path); //以下載的方式顯示文件
Response.Clear();
// Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.UTF8;
// 指定默認文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 指定文件大小
Response.AddHeader("Content-Length", file.Length.ToString());
// 下載方式
Response.ContentType = "application/ms-excel";
// 把文件流傳送到Client端
Response.WriteFile(file.FullName);
file = null;
Response.End();
转载:http://www.cnblogs.com/cai/archive/2006/04/12/372878.html
XmlDocument xmlDoc = new XmlDocument( );
xmlDoc.Load(Server.MapPath("./Reports/")+"abc.xml");
string strXml =xmlDoc.DocumentElement.OuterXml;
oSheet.XMLData = strXml;
oSheet.Cells[2,12]=DateTime.Now.ToString("yyyyMMdd");//制表日期
int i=4;
if (Session["datatable"] != null)
oSheet.get_Range(oSheet.Cells[4,1], oSheet.Cells[i-1,3]).Borders.set_LineStyle(XlLineStyle.xlContinuous);
oSheet.get_Range(oSheet.Cells[4,1], oSheet.Cells[i-1,3]).Font.set_Size(10);
string desFileName="abc"+System.DateTime.Now.ToString("yyMMddHHmmssff")+".xls";
string desPathFileName=Server.MapPath("../ReportDocs/")+desFileName;
//輸出整理後的文件
oSheet.Export(desPathFileName, Microsoft.Office.Interop.Owc11.SheetExportActionEnum.ssExportActionNone, Microsoft.Office.Interop.Owc11.SheetExportFormat.ssExportXMLSpreadsheet);
string path = desPathFileName;
System.IO.FileInfo file = new System.IO.FileInfo(path); //以下載的方式顯示文件
Response.Clear();
// Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.UTF8;
// 指定默認文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 指定文件大小
Response.AddHeader("Content-Length", file.Length.ToString());
// 下載方式
Response.ContentType = "application/ms-excel";
// 把文件流傳送到Client端
Response.WriteFile(file.FullName);
file = null;
Response.End();
转载:http://www.cnblogs.com/cai/archive/2006/04/12/372878.html
相关文章推荐
- ASP.NET中利用OWC组件生成EXCEL表(转)
- asp.net中利用OWC组件生成EXCEL表
- C#利用OWC组件生成数据报表
- asp.net中利用OWC组件生成EXCEL表
- ASP.NET中利用OWC组件生成EXCEL表
- C#利用OWC组件生成数据报表
- C#利用ZedDemo组件生成数据报表
- ASP 中利用OWC 服务器端组件动态生成图表
- C#利用ZedDemo组件生成数据报表
- C# 利用QRCode生成二维码图片
- asp.net(C#)利用QRCode生成二维码(续)-在二维码图片中心加Logo或图像 .
- [转]利用C#自带组件强壮程序日志
- C# 利用自带xsd.exe工具操作XML-如通过XML生成xsd文件
- asp.net(C#)利用QRCode生成二维码
- Aps.net—(利用C#来生成静态页面)
- C#利用QrCode.Net生成二维码(Qr码)
- 利用C#自带组件强壮程序日志
- C#利用zxing.net生成二维码和条形码并实现打印的功能
- c# 利用AForge.NET组件操作摄像头
- 利用C#自带组件强壮程序日志