Column width issues when exporting to Excel using ASP.NET

Discussion in 'ASP .Net Web Controls' started by Chase Kang #52, Jan 4, 2007.

  1. So I'm using the typical export code to render the contents on my web
    form to HTML and into an Excel spreadsheet. My web form consists of
    about 5 tables of varying dimensions (from approx. 3x4 to 6x8).
    Ideally, I would like my spreadsheet to look exactly like how my web
    form is laid out. My main problem is that the cell widths of each
    table are not independent of each other on the spreadsheet, and causes
    my spreadsheet to look warped and distorted. For example, the width of
    column A on the spreadsheet becomes equal to the size of the widest
    first column from all the tables. Has anyone had to tacke a similar
    problem as mine, and if so, what'd you do to alleviate it?

    Here's what my web form is set up (and how I'd like my spreadsheet to
    look):
    ------------------------------------------------------
    | [Table 1] [Table 3] |
    | |
    | [Table 2] [Table 4] |
    | |
    | [Table 5] |
    ------------------------------------------------------
    Here's the code I'm using:
    ' Clear response content before adding to web form.
    Response.Clear()
    Response.Buffer = True

    ' Set the content type to Excel.
    Response.ContentType = "application/vnd.ms-excel"
    ' Remove the charset from the Content-Type header.
    Response.Charset = ""
    ' Turn off the view state.
    Me.EnableViewState = False

    Dim tw As New System.IO.StringWriter
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)

    ' Get the HTML for all controls on the page.
    Me.RenderControl(hw)

    ' Write the HTML back to the browser.
    Response.Write(tw.ToString())

    ' End the response.
    Response.End()

    I really don't want to resort to using XML to generate my spreadsheet
    since that'd take me a good while to figure out, and I can't purchase
    any COTS products to do all this for me since I don't want to do a
    server-side install of Office. Any suggestions appreciated. Thanks.
    Chase Kang #52, Jan 4, 2007
    #1
    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. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,359
    Carl Prothman [MVP]
    Jan 12, 2005
  2. =?Utf-8?B?T3Bh?=

    Exporting to Excel and Column Order

    =?Utf-8?B?T3Bh?=, Sep 11, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    459
    =?Utf-8?B?T3Bh?=
    Sep 11, 2006
  3. Doogie
    Replies:
    1
    Views:
    435
    sloan
    Nov 19, 2008
  4. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    247
    Eliyahu Goldin
    Oct 24, 2004
  5. John Walker

    Column Formatting When Exporting to Excel

    John Walker, Nov 16, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    159
    John Walker
    Nov 16, 2008
Loading...

Share This Page