Last post Dec 25, 2008 02:11 AM by Nai-Dong Jin - MSFT
Dec 19, 2008 11:31 AM|Mobzam|LINK
I am developing a web application using csharp in visual studio 2003.
I would like to be printing
or generating a word document and the information on this document should come from a section
of a page. Initially I wanted to be converting the page (aspx )
into a document, but it not coming out the I want. Now I would
like just part from the page to be printed. The section to be printed is on table on the web page with following measurement 90% in width.
I have the csharp code that was posted by
suthish nair that I am using to print the whole page. But, how can I modify it so that can be printing just information in that table or JUST SECTION?.
HttpContext.Current.Response.ContentType = "application/vnd.doc";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.Page sPage = new System.Web.UI.Page();
Dec 22, 2008 09:57 PM|Nai-Dong Jin - MSFT|LINK
Based on my konwledge, you can add a iframe to your page, and display the contents which you want to exported to Word inside that iframe. And in this way, you can export the specific page in iframe.
Another practice is that you can take advantage of Word.Application object. I'm not sure what kind of content would you like to export? A table, a gridview or something like that? if so, you can create tables in word by using the APIs provided by Word.Application.
So in this way, you can render the content to the word document manually.
Dec 24, 2008 08:01 AM|Mobzam|LINK
may you give an example or url where I can fins example
Dec 25, 2008 02:11 AM|Nai-Dong Jin - MSFT|LINK
For the first practice, there isn't any samples or links at all. What you need is just to add a iframe into your web page, make the iframe link to the page which you want to export to word.
For the second practice, you can try the Word.ApplicationClass. And here's the simple code snippet for you to refer.
Word.ApplicationClass wordApp = new Word.ApplicationClass();
wordApp.Visible = true;
object filename = selectedFile;
Word.Document aDoc = new Document() ;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
aDoc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
catch (Exception ex)
Of course ,that's only a single sample, if you want to add other contents into the document, you may write your own logic.