locked
How to Generate word document from a SECTION OR PART of .aspx page? RRS feed

  • Question

  • User524898530 posted

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link href="file:///C:%5CDOCUME%7E1%5Cchijikwm%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->Hello people ,

    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?.

    Please help

     

    			HttpContext.Current.Response.ContentType = "application/vnd.doc";
    			HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=DDBCertificate.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();
    			sPage.RenderControl(htmlWrite);
    			HttpContext.Current.Response.Write(stringWrite.ToString());
      
    Friday, December 19, 2008 11:31 AM

Answers

  • User-1136466523 posted

    Hi,

    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.

     

    1    Word.ApplicationClass wordApp = new Word.ApplicationClass();
    2    
    3    wordApp.Visible = true;
    4    
    5    object filename = selectedFile;
    6    
    7    Word.Document aDoc = new Document() ;
    8    
    9    object readOnly = false;
    10   
    11   object isVisible = true;
    12   
    13   object missing = System.Reflection.Missing.Value;
    14   
    15   try
    16   
    17   {
    18   
    19   
    20   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);
    21   
    22   aDoc.Activate();
    23   
    24   }
    25   
    26   catch (Exception ex)
    27   
    28   {
    29   
    30   MessageBox.Show(ex.Message);
    31   
    32   }
    33   
    34   
    

     

    Of course ,that's only a single sample, if you want to add other contents into the document, you may write your own logic.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 25, 2008 2:11 AM

All replies

  • User-1136466523 posted

    Hi,

    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.

    Thanks.

    Monday, December 22, 2008 9:57 PM
  • User524898530 posted

     may you give an example  or url where I can fins example

    Wednesday, December 24, 2008 8:01 AM
  • User-1136466523 posted

    Hi,

    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.

     

    1    Word.ApplicationClass wordApp = new Word.ApplicationClass();
    2    
    3    wordApp.Visible = true;
    4    
    5    object filename = selectedFile;
    6    
    7    Word.Document aDoc = new Document() ;
    8    
    9    object readOnly = false;
    10   
    11   object isVisible = true;
    12   
    13   object missing = System.Reflection.Missing.Value;
    14   
    15   try
    16   
    17   {
    18   
    19   
    20   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);
    21   
    22   aDoc.Activate();
    23   
    24   }
    25   
    26   catch (Exception ex)
    27   
    28   {
    29   
    30   MessageBox.Show(ex.Message);
    31   
    32   }
    33   
    34   
    

     

    Of course ,that's only a single sample, if you want to add other contents into the document, you may write your own logic.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 25, 2008 2:11 AM