【问题标题】:Generating Excel Sheet using HtmlWriter使用 HtmlWriter 生成 Excel 工作表
【发布时间】:2013-09-16 10:05:58
【问题描述】:

我正在使用字符串 writer 生成 Excel 报告。我生成了 Excel 工作表,但它只生成一张工作表。但我需要根据我的情况创建工作表。 我的代码是:

   string filename = "DownloadMobileNoExcel.xls";
   System.IO.StringWriter tw = new System.IO.StringWriter();
    tw.Write("<table>");
    tw.Write("<tr><td>data1</td><td>data2</td><td>data3</td><td>data4</td><td>data5</td><td>data6</td></tr>");
    tw.Write("<tr><td>data1</td><td>data2</td><td>data3</td><td>data4</td><td>data5</td><td>data6</td></tr>");
    tw.Write("<tr><td>data1</td><td>data2</td><td>data3</td><td>data4</td><td>data5</td><td>data6</td></tr>");
    tw.Write("</table>");
    Response.ContentType = "application/vnd.ms-excel";
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
    this.EnableViewState = false;
    Response.Write(tw.ToString());
    Response.End();

上面的代码生成单个工作表,但我想根据我的条件创建,我如何创建工作表,我想要添加 Html 的相同方法,提前谢谢

【问题讨论】:

    标签: c# excel c#-4.0 c#-3.0 c#-5.0


    【解决方案1】:

    可以使用框架来完成:您必须为 Excel 工作表中的每个选项卡创建一个 .html 文件。

    要了解它是如何工作的, - 创建一个包含 2 张工作表的 Excel 文件 - 另存为... .html - 查看编写的 html(+ 生成的包含工作表的子文件夹

    如果您创建类似的结构(使用上述测试中的文件作为模板),Excel 将能够打开它。

    另一种方法是使用 OpenXml 创建 Excel 文件,如下所述: How to write data on new sheet of EXCEL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-16
      • 1970-01-01
      • 2011-06-07
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      相关资源
      最近更新 更多