【问题标题】:Export ListView to Word将 ListView 导出到 Word
【发布时间】:2010-12-31 04:59:17
【问题描述】:

要将gridview 导出到Excel,可以将响应内容类型更改为“application/vnd.xls”,然后使用gridName.RenderControl 进行渲染。是否有任何理由不能/不应该采用这种相同的方法来将列表视图呈现为单词?

还有另一种将列表视图导出到 word 的首选方法吗?

更新:我已经验证这适用于 Word;但是,当打开文件时,Word 会显示列表视图中的 html 标记(连同内容)。下面是代码。

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=test.doc");
Response.Charset = "";
Response.ContentType = "application/msword";

var stringWriter = new StringWriter();
var htmlWriter = new HtmlTextWriter(stringWriter);   
listView.RenderControl(htmlWriter);
Response.Write(stringWriter.ToString());
Response.End();

【问题讨论】:

  • 我唯一的想法是 html 无效。
  • 看来不是这样。我简化了列表视图,因此 itemtemplate(和 layouttemplate)中唯一的东西是一个 div 标签,其内容中包含“test”。

标签: c# asp.net listview


【解决方案1】:

同样的技术也适用于 Microsoft Word。之所以如此,是因为这两个应用程序都将打开并读取 HTML 作为源文档格式。文件名和内容类型由网站设置,以便浏览器知道打开文件所需的应用程序。

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 2012-01-04
    相关资源
    最近更新 更多