Last post Sep 25, 2009 06:30 AM by dinudany
Sep 25, 2009 12:06 AM|abinashpatra|LINK
First of all am sorry for putting this question here.
Currently we have a requirement where in we are exporting the content of a grid into excel sheet. The requirement says we need to stick to the format of the gird. For this we are using XML Spread Sheet approach.
We are facing problem with Auto Fit Columns in the excel. Currently we have a limitation in XML Spreadsheet stating that this feature works on columns having numbers and dates . But in Excel , text columns greatly need this feature . Please refer to the
Upon reverse engineering it is found that when a column in excel sheet is applied AutoFit formatting, then a Width property is added to that column with a hardcode value( in XML Spreadsheet format). The next time sheet is opened and that particular column
text is changed to greater width , then auto fit again needs to be applied . Please refer to the below piece of code, which is generated when I save the excel as XML Spread Sheet.
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="7" x:FullColumns="1" x:FullRows="1">
<Column ss:Width="132.75" />
- <Row ss:Index="7">
Sep 25, 2009 06:30 AM|dinudany|LINK
use this to export the grid as it is fron the grid to excel
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=" & ddlDocNumbers.SelectedItem.Text.Replace(" / ", "_").ToString & ".xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter()
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)