【发布时间】:2012-12-14 03:34:50
【问题描述】:
我正在尝试在 ASP.NET MVC 4 上执行此操作:
MemoryStream mem = new MemoryStream();
using (WordprocessingDocument wordDoc =
WordprocessingDocument.Create(mem, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
{
// instantiate the members of the hierarchy
Document doc = new Document();
Body body = new Body();
Paragraph para = new Paragraph();
Run run = new Run();
Text text = new Text() { Text = "The OpenXML SDK rocks!" };
// put the hierarchy together
run.Append(text);
para.Append(run);
body.Append(para);
doc.Append(body);
//wordDoc.Close();
///wordDoc.Save();
}
return File(mem.ToArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ABC.docx");
但是 ABC.docx 以损坏的形式打开,即使修复后也无法打开。
有什么想法吗?
链接问题:
Streaming In Memory Word Document using OpenXML SDK w/ASP.NET results in "corrupt" document
【问题讨论】:
标签: asp.net-mvc ms-word openxml-sdk