代码之家  ›  专栏  ›  技术社区  ›  Rich

如何为C生成的Excel电子表格设置工作表名称?

  •  0
  • Rich  · 技术社区  · 16 年前

    我们通过编写一个HTML表来响应,从而在我们的C.NET网站中生成一个Excel电子表格。这很好,但是工作表名称被设置为与文件名相同。

    有没有地方放这个?导入时需要特定的工作表名称。

    代码:

    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();
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Rubens Farias    16 年前

    通过创建表并将内容类型设置为Excel,既不能定义工作表名称,也不能创建更多工作表。

    您可以使用 OpenXML SDK ,但您的客户端需要使用 Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats .

    推荐文章