How to populate a word file from within ASP.NET and stream it out to the client?

D

Daniel Walzenbach

Hi,

I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user.
Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible).

Does anybody know how this can be done? Which way would be preferable? Create the file on the server and streaming it out to the user or using automation to populate a file on the client's computer?
I know that it's possible to sent html to excel (via automation) which is then nicely rendered (like in the following example).

<script language="vbscript">
Sub Button1_onclick()
Dim sHTML
sHTML = window.Form1.children("DataGrid1").outerhtml
Dim oXL, oBook
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
end sub
</script>

Is there something similar possible with word? If


Thank you a lot for your help!

Daniel Walzenbach
 
S

Steve C. Orr [MVP, MCSD]

This article demonstrates a number of techniques for generating Excel and Word documents.
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

Here's a good 3rd party product you could use if you need to get really fancy:
http://www.aspose.com/Products/Aspose.Word/
And here's another:
www.officewriter.com

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Hi,

I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user.
Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible).

Does anybody know how this can be done? Which way would be preferable? Create the file on the server and streaming it out to the user or using automation to populate a file on the client's computer?
I know that it's possible to sent html to excel (via automation) which is then nicely rendered (like in the following example).

<script language="vbscript">
Sub Button1_onclick()
Dim sHTML
sHTML = window.Form1.children("DataGrid1").outerhtml
Dim oXL, oBook
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
end sub
</script>

Is there something similar possible with word? If


Thank you a lot for your help!

Daniel Walzenbach
 
D

Daniel Walzenbach

Steve,



Thank you for your immediate answer. Could you please tell me what I would have to do if I wanted to use automation and be able to access some fields within a template? How would I have to declare those fields and how could they be accessed?



Thank you!

Daniel

This article demonstrates a number of techniques for generating Excel and Word documents.
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

Here's a good 3rd party product you could use if you need to get really fancy:
http://www.aspose.com/Products/Aspose.Word/
And here's another:
www.officewriter.com

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Hi,

I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user.
Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible).

Does anybody know how this can be done? Which way would be preferable? Create the file on the server and streaming it out to the user or using automation to populate a file on the client's computer?
I know that it's possible to sent html to excel (via automation) which is then nicely rendered (like in the following example).

<script language="vbscript">
Sub Button1_onclick()
Dim sHTML
sHTML = window.Form1.children("DataGrid1").outerhtml
Dim oXL, oBook
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
end sub
</script>

Is there something similar possible with word? If


Thank you a lot for your help!

Daniel Walzenbach
 
S

Steven Cheng[MSFT]

Hi Daniel,

There are some tech articles discussing on using Automation to process Word
document in .net:

#HOW TO: Automate Word from Visual C# .NET to Create a New Document
http://support.microsoft.com/default.aspx?id=316384

#Microsoft Word Documents from ASP.NET
http://www.codeproject.com/aspnet/wordapplication.asp

However, in ASP.NET Web application, since web application is serverside
application and the Automation is strongly not recommended. And it'll cause
many unexpected issues which may occur randomly. Here is the kb article
mentioned the concerns:

#INFO: Considerations for Server-Side Automation of Office
http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757

In addition, I still recommend that you consider some other means to
generate word document such as transfer XML document or other components if
you feel appropriate. And here is another kb article discussing use XSL
TRANSFORM to generate word document;

#HOW TO: Use ASP.NET or Visual Basic.NET to Transform XML To Rich Text
Format (RTF) For Microsoft Word 2002
http://support.microsoft.com/default.aspx?scid=kb;en-us;311461

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steve C. Orr [MVP, MCSD]

For that kind of functionality in a web application I'd have to recommend one of the 3rd party products I mentioned. They both support your requirements.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Steve,



Thank you for your immediate answer. Could you please tell me what I would have to do if I wanted to use automation and be able to access some fields within a template? How would I have to declare those fields and how could they be accessed?



Thank you!

Daniel

This article demonstrates a number of techniques for generating Excel and Word documents.
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

Here's a good 3rd party product you could use if you need to get really fancy:
http://www.aspose.com/Products/Aspose.Word/
And here's another:
www.officewriter.com

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Hi,

I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user.
Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible).

Does anybody know how this can be done? Which way would be preferable? Create the file on the server and streaming it out to the user or using automation to populate a file on the client's computer?
I know that it's possible to sent html to excel (via automation) which is then nicely rendered (like in the following example).

<script language="vbscript">
Sub Button1_onclick()
Dim sHTML
sHTML = window.Form1.children("DataGrid1").outerhtml
Dim oXL, oBook
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
end sub
</script>

Is there something similar possible with word? If


Thank you a lot for your help!

Daniel Walzenbach
 
D

Daniel Walzenbach

All right,

Thank you Steve!
For that kind of functionality in a web application I'd have to recommend one of the 3rd party products I mentioned. They both support your requirements.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Steve,



Thank you for your immediate answer. Could you please tell me what I would have to do if I wanted to use automation and be able to access some fields within a template? How would I have to declare those fields and how could they be accessed?



Thank you!

Daniel

This article demonstrates a number of techniques for generating Excel and Word documents.
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp

Here's a good 3rd party product you could use if you need to get really fancy:
http://www.aspose.com/Products/Aspose.Word/
And here's another:
www.officewriter.com

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Hi,

I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed).
The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user.
Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible).

Does anybody know how this can be done? Which way would be preferable? Create the file on the server and streaming it out to the user or using automation to populate a file on the client's computer?
I know that it's possible to sent html to excel (via automation) which is then nicely rendered (like in the following example).

<script language="vbscript">
Sub Button1_onclick()
Dim sHTML
sHTML = window.Form1.children("DataGrid1").outerhtml
Dim oXL, oBook
Set oXL = CreateObject("Excel.Application")
Set oBook = oXL.Workbooks.Add
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML
oBook.HTMLProject.RefreshDocument
oXL.Visible = true
oXL.UserControl = true
end sub
</script>

Is there something similar possible with word? If


Thank you a lot for your help!

Daniel Walzenbach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top