【发布时间】:2011-11-30 04:12:22
【问题描述】:
我想在网页顶部添加一个按钮,单击该按钮应将整个网页复制到 MS Word 文档中。 这必须在 ASP 中完成。
【问题讨论】:
标签: asp-classic ms-word
我想在网页顶部添加一个按钮,单击该按钮应将整个网页复制到 MS Word 文档中。 这必须在 ASP 中完成。
【问题讨论】:
标签: asp-classic ms-word
1) 首先在服务器上创建一个 .doc 文件。然后创建一个文件系统对象并使用它来打开 .doc 文件并写入:
Set file = CreateObject("Scripting.FileSystemObject")
Set wordFile = file.CreateTextFile(pathToYourDocFile, true)
wordFile.WriteLine(htmlOutput)
wordFile.close
"htmlOutput" 必须包含您要导出为 word 的页面。
2) 另一种选择是直接使用 Word 实例作为mentioned on MSDN:
Set wordApp = GetObject(, "Word.Application")
wordApp.Visible = False
wordApp.Documents.Open pathToYourDocFile
Set wordApp = Nothing
您需要挖掘through the Word API 才能将内容写入文档。
3) 更改页面的内容类型将自动在 Word 中打开它(如果安装在客户端上):
Response.ContentType = "application/msword"
【讨论】: