如何设置工作表名称为一个C#生成Excel的小号preadsheet? [英] How to set the sheet name for a C# generated Excel spreadsheet?

查看:147
本文介绍了如何设置工作表名称为一个C#生成Excel的小号preadsheet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们产生写了一个HTML表来响应一个Excel US preadsheet在我们的C#.net网站。这个伟大的工程,但表名称被设置为相同的文件名。

有没有去设置这个?我们需要一定的工作表名称导入时。

code:

 字符串文件名=的String.Format({0} -CopyDataBack_ {1}的.xls,Master.EventID.ToString(),DateTime.Now.ToString(DD-MM -yy_HHmm));

Response.Clear();
将Response.Buffer =真;
Response.ContentType =应用程序/ vnd.ms-EXCEL;
Response.AddHeader(内容处置,附件;文件名=+文件名);
Response.Charset的=;
this.EnableViewState = FALSE;

System.Text.StringBuilder tableOut =新System.Text.StringBuilder();
// ...在一个StringBuilder创建一个HTML表...
回复于(tableOut);
到Response.End();
 

解决方案

通过创建一个表,并设置内容类型到Excel不能定义一个工作表名称,也不是为了创造更多的工作表。

您可以通过使用<一个生成的完整的Excel工作簿href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AD0B72FB-4A1D-4C52-BDB5-7DD7E816D046&displaylang=en"相对=nofollow> OpenXML的SDK ,但你的客户会需要使用<一个处理Office 2007文件格式href="http://www.microsoft.com/downloads/details.aspx?FamilyID=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en"相对=nofollow> Microsoft Office兼容包的Word,Excel和PowerPoint 2007文件格式。

We generate an Excel spreadsheet in our C# .net website by writing out an HTML table to Response. This works great, but the sheet name gets set to the same as the file name.

Is there away to set this? We require a certain sheet name when importing.

Code:

string filename = String.Format( "{0}-CopyDataBack_{1}.xls", Master.EventID.ToString(), DateTime.Now.ToString( "dd-MM-yy_HHmm" ) );

Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=" + filename );
Response.Charset = "";
this.EnableViewState = false;

System.Text.StringBuilder tableOut = new System.Text.StringBuilder();
// ... Create an HTML table in a StringBuilder ...
Response.Write( tableOut );
Response.End();

解决方案

By creating a table and setting content-type to Excel you can't define a worksheet name, nor to create more worksheets.

You can to generate your complete Excel workbook by using OpenXML SDK, but your client will need to handle Office 2007 file formats by using Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats.

这篇关于如何设置工作表名称为一个C#生成Excel的小号preadsheet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆