开发者

Export webpage to Word in ASP

I would like to add a button on top of a webpage, which when clicked should cop开发者_运维百科y the entire webpage to an MS Word document. This has to be done in ASP.


1) First create a .doc file on the server. Then create a file system object and use it to open the .doc file and write into it:

Set file = CreateObject("Scripting.FileSystemObject")
Set wordFile = file.CreateTextFile(pathToYourDocFile, true)
wordFile.WriteLine(htmlOutput)
wordFile.close

"htmlOutput" must contain the page you want to export to word.

2) Another option is to directly work with an instance of Word as mentioned on MSDN:

Set wordApp = GetObject(, "Word.Application")
wordApp.Visible = False
wordApp.Documents.Open pathToYourDocFile
Set wordApp = Nothing

You will need to dig through the Word API in order to write content to the document.

3) Change the content tye of your page will automatically opens it in Word (if installed on the client):

Response.ContentType = "application/msword"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜