I am having trouble adjusting the column width when exporting from an
ASP.net web page.
I don't really want to have a sotred formated excel page and prefer to
do it by code within the display page. (When user enters the data and
requests report to run, it brings back a new page, then the user can
clcik on a button to export to excel)
I have achieved in formatting the header to a different color, as well
as adding a header with what report they have run, or add dates if it
was a custom date range. using the lower code
Response.Write("<font size=4><center>" & "Report: " & lbl_title.Text &
" " & Now.Date & "</center></font>") ' Adds title to Excel Sheet
dg_Report.HeaderStyle.BackColor = Drawing.Color.LightSkyBlue ' Colors
header row in grid and not sheet.
dg_Report.ItemStyle.VerticalAlign = VerticalAlign.Top
However I am unable to make a column width wider at all.. is there any
suggestions?
I have tried the below code with out success: (and yes I know they are
commented out at the moment, I just copied direct from code..
'dg_Report.Columns(9).ItemStyle.Width.Pixel(450) ' -- Won't work
'dg_Report.HeaderStyle.Width.Equals(20) ' -- Won't Work
'dg_Report.Columns("Description").HeaderStyle.Width =
System.Web.UI.WebControls.Unit.Pixel(100) ' -- Won't Work
'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work
Masudur - 25 Mar 2008 20:13 GMT
> I am having trouble adjusting the column width when exporting from an
> ASP.net web page.
[quoted text clipped - 27 lines]
> 'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
> 'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work
Hi..
how about traverse the rows of datagrid and manually generate the
report using a html table...
http://aspalliance.com/725_CodeSnip_Export_a_DataGrid_to_a_Formatted_Excel_Sprea
dsheet
and set the html table's cell that is <TD> is width to a specific
width...
Not sure though cause i found a post that says its not going to
happen...
http://www.velocityreviews.com/forums/t112076-export-to-excel-from-aspnet.html
Thanks
Masudur
bruce barker - 25 Mar 2008 22:47 GMT
if you want to specify columns withds, multiple sheets, sheet name, etc. you
shoudl be producing an xml work book. the xml is easy, and you can specifiy
all the properties. a simple wookbook:
<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Worksheet ss:Name="MySheet">
<ss:Table>
<ss:Column ss:Width="80"/>
<ss:Column ss:Width="80"/>
<ss:Row>
<ss:Cell>
<ss:Data ss:Type="String">Hello</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">World</ss:Data>
</ss:Cell>
</ss:Row>
</ss:Table>
</ss:Worksheet>
</ss:Workbook>
-- bruce (sqlwork.com)
> I am having trouble adjusting the column width when exporting from an
> ASP.net web page.
[quoted text clipped - 27 lines]
> 'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
> 'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work
rote - 26 Mar 2008 23:50 GMT
Bruce i'm just curious i would you tell excel to use this xml when
exporting?
Thanks in advance
> if you want to specify columns withds, multiple sheets, sheet name, etc.
> you
[quoted text clipped - 53 lines]
>> 'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
>> 'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work