【发布时间】:2016-09-26 06:45:45
【问题描述】:
我刚刚开始探索 OpenXml,我正在尝试创建一个新的简单 word 文档,然后下载该文件
这是我的代码
[HttpPost]
public ActionResult WordExport()
{
var stream = new MemoryStream();
WordprocessingDocument doc = WordprocessingDocument.Create(stream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true);
MainDocumentPart mainPart = doc.AddMainDocumentPart();
new Document(new Body()).Save(mainPart);
Body body = mainPart.Document.Body;
body.Append(new Paragraph(
new Run(
new Text("Hello World!"))));
mainPart.Document.Save();
return File(stream, "application/msword", "test.doc");
}
我原以为它会包含“Hello World!” 但是当我下载文件时,文件是空的
我错过了什么? 提示
【问题讨论】:
标签: c# asp.net-mvc openxml