Re: Export Gridview to Word

can i do something similiar using a datatable or dataview into aspose.cells?

when i use the old stringwriter method my html tags are used to format however when i do the importdatatable in aspose.cells i get just the raw text without the pretty format.

below is my aspose

Dim workbook As New Workbook()

'Adding a new worksheet to the Workbook object

workbook.Worksheets.Add()

'Obtaining the reference of the newly added worksheet by passing its sheet index

Dim worksheet As Worksheet = workbook.Worksheets(0)

worksheet.Cells.ImportDataTable(dt, True, "B9")

'Saving the Excel file

workbook.Save("testinggrid.xlsx", Aspose.Cells.FileFormatType.Excel2007Xlsx, Aspose.Cells.SaveType.OpenInExcel, response)

response.End()

==================

the old method that worked previously

response.ContentType = "application/vnd.ms-excel"

'create a string writer

Dim stringWrite As New System.IO.StringWriter

'create an htmltextwriter which uses the stringwriter

Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

'instantiate a datagrid

Dim dg As New DataGrid

'set the datagrid datasource to the dataset passed in

dg.DataSource = dv

'bind the datagrid

dg.DataBind()

'tell the datagrid to render itself to our htmltextwriter

dg.RenderControl(htmlWrite)

'all that's left is to output the html

response.Write(stringWrite.ToString)

response.End()

attached are the outputs old and new...i would like to have similiar results with aspose.cells (i have a license)

Hi Chuck,

Thanks for your inquiry.

This is the support forum for Aspose.Words. It appears you are using Aspose.Cells so I will move your thread to their forum so someone from their team can help you better.

Thanks,

Hi,

I think you may use:

Cells.ImportGridView for your need.

Thank you.

thanks for the quick response.

I think my intent was lost in my attempt to piggyback....

I basically want to keep the html formating that i created for the datatable

so i am asking is can i easily import a datatable and keep the html formating with aspose.cellls (i can do it with response.rendercontrol however i then wont be able to use aspose for what i purchased it for...to embed images ulitimately)

1. i do not have a gridview

2. i have a datagrid,dataview, datatable or dataset (those are the objects i have to work with)

3. i simply want cells to render html since i have so much coding involved in that and it works the old way (see testingworkingOLDMETHOD.xls compare to testinggrid.xslx from aspose.cells -attached previously) i would like the headers to be displayed which i believe only datatable provides

this is a dynamic report...i would like to not have custom code for every datagrid, datatable etc i export

basically i want the results from aspose.cells that this produces:

Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

'instantiate a datagrid

Dim dg As New DataGrid

'set the datagrid datasource to the dataset passed in

dg.DataSource = 'datatable dataset dataview etc'

'bind the datagrid

dg.DataBind()

'tell the datagrid to render itself to our htmltextwriter

this is what creates a nice report see my excel doc that i attached previously.

dg.RenderControl(htmlWrite)

--------------

Hi,

Well, we do have Cells.ImportDataGrid() method but, I am afraid, it simply extract pure data and not the formattings as it can do in the case with Cells.ImportGridView(). I have logged an issue for the enhancement of ImportDataGrid() method with an id: CELLSNET-18041. We will soon look into it.

By the way, we also have Cell.HtmlString attribute which can parse html tags with formatting, so you may try it.

Thanks for your understanding!

ok so if i convert to a gridview would i be able to format (i.e. render my html) in aspose.cells? i just want to make it look like the OLD excel doc i attached.

also i am looking at using word as well (same issue) i notice there is a refrence

You can insert HTML into Word document using Aspose.Words. You can use DocuemntBuilder.insertHtml method to achieve this. Here you can find example how to insert HTML during mail merge:

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

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

however the link doesnt go to the explanation of how to use this mergefieldeventhandler...cant find any doc on that...can you provide an example as well ??? or do i need to post in the word section

Hi,

Yes, you may try to use Cells.ImportGridView, it would extract the formatted data to the worksheets.

Regarding your query about Aspose.Words, please do post a query in the Aspose.Words forum, they would help you soon.

Thank you.

i tried import gridview as well and it simply dumps raw data only without any header. what am i doing wrong or is this even possible with aspose?

my code is below:

Private Sub TestExcel()

'Create a datatable and add three columns to it

Dim dataTable As New DataTable("Products")

dataTable.Columns.Add("Product ID", GetType(Int32))

dataTable.Columns.Add("Product Name", GetType(String))

dataTable.Columns.Add("Units In Stock", GetType(Int32))

'Add the first record to it

Dim dr As DataRow = dataTable.NewRow()

dr(0) = 1

dr(1) = "Aniseed Syrup"

dr(2) = 15

dataTable.Rows.Add(dr)

'Add the second record to it

dr = dataTable.NewRow()

dr(0) = 2

' make this blue and bold...done dynamically with many columns and rows but for this example lets see if can get one column to obey the html commands. i do not want to have to 'custom code within aspose i just want to render from the datatable or gridview or whatever is that possible?????

dr(1) = "esx1.csps.com" '"Boston Crab Meat"

dr(2) = 123456

dataTable.Rows.Add(dr)

'set its datasource

Dim GridView1 As New GridView

GridView1.DataSource = dataTable

'bind data

GridView1.DataBind()

'Instantiate a new workbook

Dim workbook As New Aspose.Cells.Workbook()

'Get the first worksheet in the workbook

Dim worksheet As Aspose.Cells.Worksheet = workbook.Worksheets(0)

'Import data from GridView control to fill the worksheet

worksheet.Cells.ImportGridView(GridView1, 0, 0, False, True, False)

''workbook.Save("e:\test\importeddata.xls")

workbook.Save("testinggrid.xlsx", Aspose.Cells.FileFormatType.Excel2007Xlsx, Aspose.Cells.SaveType.OpenInExcel, Response)

End Sub

i just wnat the html rendered so that column 1 is blue and bold (in this simple instance)

here is what i get:

1 Aniseed Syrup 15
2 <FONT COLOR="BLUE"><B>esx1.csps.com</FONT></B> 123456

Hi,

Well, ImportGridView method will not work in your case as you can see GridView control does not format data for display if you specify html tags with data directly. I think for your case, you can just loop through your data rows formatted with html tags in your datatable and use Cell.HtmlString attribute ( we provide) to parse htmls to be placed in each cell in the worksheet for your need.

e.g

worksheet.Cells[“B3”].HtmlString = “<FONT COLOR=“BLUE”>esx1.csps.com”;


Thank you.