我正在尝试使用Spire.Doc生成一个Word文档并下载它。我可以下载这份文件,但它是空的。有谁知道这是为什么,也能帮我吗?这是我的密码:
Document doc = new Document();
Paragraph paragraph = doc.AddSection().AddParagraph();
paragraph.AppendText("Hello World!");
doc.SaveToFile("Example.doc", FileFormat.Doc);
//Saves the Word document to MemoryStream
MemoryStream stream = new MemoryStream();
stream.Position = 0;
//Download Word document in the browser
return File(stream, "application/msword", "Example.doc");发布于 2022-01-11 10:39:18
下面是一个使用.NET Core3.1和FreeSpire.Doc v9.9.7的工作示例
[HttpGet]
public IActionResult DownloadWordDoc()
{
//Create the document object;
Document doc = new Document();
//Create a paragraph and add some text
var paragraph = doc.AddSection().AddParagraph();
paragraph.AppendText("Hello World!");
//Create and save the document to a memory stream
var ms = new MemoryStream();
doc.SaveToStream(ms, FileFormat.Docx);
ms.Seek(0, SeekOrigin.Begin);
//You may want to make this MIME type string into a constant
var fsr = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
fsr.FileDownloadName = "Example.docx";
return fsr;
}您可能还需要以下使用语句,但我假设您已经有了它们。
using System.IO;
using Spire.Doc;https://stackoverflow.com/questions/70664213
复制相似问题