Setting Excel Column Width in ASP

Discussion in 'ASP General' started by j.t.w, Jul 21, 2010.

  1. j.t.w

    j.t.w Guest

    Hi,

    How do you set the column width of a <td>? I'm using
    "Response.ContentType = "application/vnd.ms-excel" at the top of my
    page to change the web page to an excel spreadsheet.

    I've tried Response.Write("<td width=200>" & rst("Address") & "</td>")
    but, it doesn't seem to change the column width.

    Thanks if advance for any and all help.

    j.t.w
     
    j.t.w, Jul 21, 2010
    #1
    1. Advertisements

  2. j.t.w

    Bwig Zomberi Guest


    Haven't checked this but it may work:

    <td style="width: 200px; ">
     
    Bwig Zomberi, Jul 21, 2010
    #2
    1. Advertisements

  3. j.t.w

    Dan Guest

    You're not actually creating an Excel spreadsheet - you're using a trick of
    the MIME type to get the browser to load the resulting page in Excel, but
    the actual output is HTML and it's relying on the Excel HTML parser to
    convert it to an Excel spreadsheet format. So you need to figure out what
    Excel will parse, and what it will ignore, when processing HTML, and use
    that to figure out what attributes can be used. It might well be as simple
    as simply needing to enclose the width in quotes, eg.

    Response.Write("<td width=""200"">" & rst("Address") & "</td>")

    (when you want to include a double quote within a string, simply double it
    up so it's not treated as a string terminator).
     
    Dan, Jul 21, 2010
    #3
  4. j.t.w

    Bob Barrows Guest

    Create a spreadsheet in Excel whose columns are set to the widths you want
    and then save it to html. View the source to see the markup that Excel needs
    to properly format the column widths.
     
    Bob Barrows, Jul 21, 2010
    #4
  5. j.t.w

    j.t.w Guest

    Thank you all for your help and suggestions. I finally got it working
    properly.

    My problem was there were more than one Response.Write("<table>") in
    my code. Once I removed all but the outermost <table>, the width
    property started working.

    Thanks again.
    j.t.w
     
    j.t.w, Jul 21, 2010
    #5
    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.