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
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.
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
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
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/

Hi

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:
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
Hope this helps. Please let me know if you need more assistance, I will be glad to help you.
Best regards.