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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.