Word导出ASP.NET MVC初学者

时间:2017-04-05 11:28:07

标签: c# asp.net-mvc

我是ASP.NET MVC的新手,并尝试生成从Formdata到word文件的导出。这非常有效,文档中的所有书签都使用以下代码正确填充:

string savePath = (@"U:\Coding ASP.MVC\WebForm Export into WordFile\Gutachten.docx");
string templatePath = (@"U:\Coding ASP.MVC\WebForm Export into WordFile\wordTemplate.docx");
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
doc = app.Documents.Open(templatePath);
doc.Activate();

if (doc.Bookmarks.Exists("FileNoSIS"))
{
    doc.Bookmarks["FileNoSIS"].Range.Text = FileNoSIS;
}

if (doc.Bookmarks.Exists("NameOfAction"))
{
    doc.Bookmarks["NameOfAction"].Range.Text = NameOfAction;
}

doc.SaveAs2(savePath);
app.Application.Quit();
Response.Write("Success");

但是现在我想通过流编辑文档并提供新填充的文档作为下载。在这里有人可以给我一些建议或任何提示如何到达那里吗?

THX

0 个答案:

没有答案