We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Export Gridview to Word

Hi,

I’m new to this forum. Before going forward with Aspose I wanted to do 3 tests to see if this soft is what we want. Adding text and image to a word document is ok so far but what about a gridview ?

I’m far from understanding all the subtilities of Aspose.Word and did not succeed to export a gridview like something I used to do :

Dim oStringWriter As New System.IO.StringWriter()
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.GridView1.RenderControl(oHtmlTextWriter)
HttpContext.Current.Response.Output.Write(oStringWriter.ToString())

Coul you please show me an exemple with Aspose.word ?

Something similar to that should work I guess but at the moment I’m just having the gridview html code reproduced in the word document :

Dim doc As Document = New Document(“Document.doc”)
doc.MailMerge.Execute(New String() {“toto”}, New Object() {oStringWriter.ToString()})
doc.Save(“Report Out.doc”, SaveFormat.Doc, SaveType.OpenInBrowser, Response)

Thank you

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. In this case oStringWriter.ToString() returns HTML string. So you should use InsertHtml method for inserting this HTML into the document. For example see the following code:

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

GridView1.RenderControl(oHtmlTextWriter);

string gridViewHtml = oStringWriter.ToString();

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(gridViewHtml);

doc.Save("out.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);

You should use MergeField event handler if you need to insert HTML during mail merge. See the following link for more information.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mergefieldeventhandler.html

Hope this helps.

Best regards.

Thank you for your fast answer.

Works perfect, this tool is amusing ;p

this link offers no help i would like to see this example can you provide since the doc does not seem to have one

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mergefieldeventhandler.html<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request and my apologizes for inconvenience. The link was broken after refactoring our documentation some time ago. Here is correct link to this article:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.reporting.mergefieldeventhandler.html

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards.