我的 aspx 页面中有两个文本框和一个按钮。当我单击该按钮时,应打开 Word 文档,并且文本框值应存储在 Word 文档中。
问问题
941 次
1 回答
1
听起来您必须下载 Open Xml SDK。比您将能够从您的 asp 页面创建一个 word 文档。
一些教程:http: //msdn.microsoft.com/en-us/library/office/dd440953%28v=office.12%29.aspx
像这样的东西:
using (WordprocessingDocument package = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
{
// Add a new main document part.
package.AddMainDocumentPart();
// Create the Document DOM.
package.MainDocumentPart.Document =
new Document(
new Body(
new Paragraph(
new Run(
new Text("Hello World!")))));
// Save changes to the main document part.
package.MainDocumentPart.Document.Save();
}
然后您必须将 word 文档写入响应流。像这样的东西:
FileInfo file = new FileInfo(PathToExcelFile);
if (file.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Type", "application/Excel");
Response.ContentType = "application/vnd.xls";
Response.AddHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("This file does not exist.");
}
于 2013-07-13T18:21:56.587 回答