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

  2. j.t.w

    Bwig Zomberi Guest

    j.t.w wrote:
    > 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



    Haven't checked this but it may work:

    <td style="width: 200px; ">



    --
    Bwig Zomberi
     
    Bwig Zomberi, Jul 21, 2010
    #2
    1. Advertising

  3. j.t.w

    Dan Guest

    "j.t.w" <> wrote in message
    news:...
    > 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


    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
     
    Dan, Jul 21, 2010
    #3
  4. j.t.w

    Bob Barrows Guest

    j.t.w wrote:
    > 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


    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. 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:
    840
    Bruce Barker
    Oct 10, 2005
  2. Charleees
    Replies:
    2
    Views:
    8,278
    Eliyahu Goldin
    Jun 20, 2006
  3. ssk
    Replies:
    5
    Views:
    5,680
    Jukka K. Korpela
    Oct 30, 2006
  4. Carl Howarth

    DG Column Width vs Table Column Width

    Carl Howarth, Oct 22, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    289
    Eliyahu Goldin
    Oct 24, 2004
  5. Chase Kang #52

    Column width issues when exporting to Excel using ASP.NET

    Chase Kang #52, Jan 4, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    486
    Chase Kang #52
    Jan 4, 2007
Loading...

Share This Page