Change column width during Excel export

Discussion in 'ASP .Net' started by Lester Mosley, Mar 25, 2008.

  1. 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
    Lester Mosley, Mar 25, 2008
    #1
    1. Advertising

  2. Lester  Mosley

    Masudur Guest

    On Mar 26, 12:25 am, Lester Mosley <> wrote:
    > 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


    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_Spreadsheet

    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
    Masudur, Mar 25, 2008
    #2
    1. Advertising

  3. Lester  Mosley

    bruce barker Guest

    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:eek:ffice: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)


    "Lester Mosley" wrote:

    > 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
    >
    bruce barker, Mar 25, 2008
    #3
  4. Lester  Mosley

    rote Guest

    Bruce i'm just curious i would you tell excel to use this xml when
    exporting?
    Thanks in advance

    "bruce barker" <> wrote in message
    news:...
    > 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:eek:ffice: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)
    >
    >
    > "Lester Mosley" wrote:
    >
    >> 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
    >>
    rote, Mar 26, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    738
    Bruce Barker
    Oct 10, 2005
  2. ssk
    Replies:
    5
    Views:
    5,454
    Jukka K. Korpela
    Oct 30, 2006
  3. David Basford
    Replies:
    3
    Views:
    2,386
    BootNic
    Sep 30, 2007
  4. Replies:
    0
    Views:
    910
  5. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    252
    Eliyahu Goldin
    Oct 24, 2004
Loading...

Share This Page