HTML table in Excel with line feed in cell

Discussion in 'ASP General' started by McKirahan, Nov 26, 2006.

  1. McKirahan

    McKirahan Guest

    I an using ASP to read a database table and generate an HTML table
    which is save via FSO with a file extension of .xls which opens up
    in MS-Excel. I am inserting several lines of text into a cell and would
    like to force a line break between them.

    I recorded an MS-Excel macro so see how Alt-Enter was captured
    which turned out to be Chr(10) which is the same as vbLf (right?)

    I tried inserting that in character in the text but it didn't show up as
    a line break in MS-Excel.. Can anyone assist? Thanks in advance.
     
    McKirahan, Nov 26, 2006
    #1
    1. Advertising

  2. McKirahan

    Mike Brind Guest

    "McKirahan" <> wrote in message
    news:...
    >I an using ASP to read a database table and generate an HTML table
    > which is save via FSO with a file extension of .xls which opens up
    > in MS-Excel. I am inserting several lines of text into a cell and would
    > like to force a line break between them.
    >
    > I recorded an MS-Excel macro so see how Alt-Enter was captured
    > which turned out to be Chr(10) which is the same as vbLf (right?)
    >
    > I tried inserting that in character in the text but it didn't show up as
    > a line break in MS-Excel.. Can anyone assist? Thanks in advance.
    >


    Try vbCrLf

    --
    Mike Brind
     
    Mike Brind, Nov 27, 2006
    #2
    1. Advertising

  3. McKirahan

    McKirahan Guest

    "Mike Brind" <> wrote in message
    news:...
    >
    > "McKirahan" <> wrote in message
    > news:...
    > >I an using ASP to read a database table and generate an HTML table
    > > which is save via FSO with a file extension of .xls which opens up
    > > in MS-Excel. I am inserting several lines of text into a cell and would
    > > like to force a line break between them.
    > >
    > > I recorded an MS-Excel macro so see how Alt-Enter was captured
    > > which turned out to be Chr(10) which is the same as vbLf (right?)
    > >
    > > I tried inserting that in character in the text but it didn't show up as
    > > a line break in MS-Excel.. Can anyone assist? Thanks in advance.
    > >

    >
    > Try vbCrLf


    I did, it didn't (work).
     
    McKirahan, Nov 27, 2006
    #3
  4. McKirahan

    Mike Brind Guest

    "McKirahan" <> wrote in message
    news:...
    > "Mike Brind" <> wrote in message
    > news:...
    >>
    >> "McKirahan" <> wrote in message
    >> news:...
    >> >I an using ASP to read a database table and generate an HTML table
    >> > which is save via FSO with a file extension of .xls which opens up
    >> > in MS-Excel. I am inserting several lines of text into a cell and
    >> > would
    >> > like to force a line break between them.
    >> >
    >> > I recorded an MS-Excel macro so see how Alt-Enter was captured
    >> > which turned out to be Chr(10) which is the same as vbLf (right?)
    >> >
    >> > I tried inserting that in character in the text but it didn't show up
    >> > as
    >> > a line break in MS-Excel.. Can anyone assist? Thanks in advance.
    >> >

    >>
    >> Try vbCrLf

    >
    > I did, it didn't (work).


    <br /> then, since you are writing html.

    --
    Mike Brind
     
    Mike Brind, Nov 27, 2006
    #4
  5. McKirahan

    McKirahan Guest

    "Mike Brind" <> wrote in message
    news:#...
    >
    > "McKirahan" <> wrote in message
    > news:...
    > > "Mike Brind" <> wrote in message
    > > news:...
    > >>
    > >> "McKirahan" <> wrote in message
    > >> news:...
    > >> >I an using ASP to read a database table and generate an HTML table
    > >> > which is save via FSO with a file extension of .xls which opens up
    > >> > in MS-Excel. I am inserting several lines of text into a cell and
    > >> > would
    > >> > like to force a line break between them.
    > >> >
    > >> > I recorded an MS-Excel macro so see how Alt-Enter was captured
    > >> > which turned out to be Chr(10) which is the same as vbLf (right?)
    > >> >
    > >> > I tried inserting that in character in the text but it didn't show up
    > >> > as
    > >> > a line break in MS-Excel.. Can anyone assist? Thanks in advance.
    > >> >
    > >>
    > >> Try vbCrLf

    > >
    > > I did, it didn't (work).

    >
    > <br /> then, since you are writing html.


    Mike, thanks for trying.

    <br /> (or <br>) does cause a line break; however, it creates a new row.

    I'm trying to simulate Excel's Alt+Enter to force word-wrap within a cell.


    Here's an example of the generated HTML table:

    <table border="1" width="100%">
    <tr height="60" valign="bottom">
    <td width="120">One<br />Two<br />Three</td>
    </tr>
    </table>

    If you open it up in Excel you see that it's on three rows ont one.
     
    McKirahan, Dec 2, 2006
    #5
  6. McKirahan

    Mike Brind Guest

    "McKirahan" <> wrote in message
    news:p...
    > "Mike Brind" <> wrote in message
    > news:#...
    >>
    >> "McKirahan" <> wrote in message
    >> news:...
    >> > "Mike Brind" <> wrote in message
    >> > news:...
    >> >>
    >> >> "McKirahan" <> wrote in message
    >> >> news:...
    >> >> >I an using ASP to read a database table and generate an HTML table
    >> >> > which is save via FSO with a file extension of .xls which opens up
    >> >> > in MS-Excel. I am inserting several lines of text into a cell and
    >> >> > would
    >> >> > like to force a line break between them.
    >> >> >
    >> >> > I recorded an MS-Excel macro so see how Alt-Enter was captured
    >> >> > which turned out to be Chr(10) which is the same as vbLf (right?)
    >> >> >
    >> >> > I tried inserting that in character in the text but it didn't show
    >> >> > up
    >> >> > as
    >> >> > a line break in MS-Excel.. Can anyone assist? Thanks in advance.
    >> >> >
    >> >>
    >> >> Try vbCrLf
    >> >
    >> > I did, it didn't (work).

    >>
    >> <br /> then, since you are writing html.

    >
    > Mike, thanks for trying.
    >
    > <br /> (or <br>) does cause a line break; however, it creates a new row.
    >
    > I'm trying to simulate Excel's Alt+Enter to force word-wrap within a cell.
    >
    >


    Then you need to simulate Excel. Create a file in the way that you want it,
    save it as html then open the result in Notepad. You'll see it has it's own
    CSS declarations. I'm no expert on CSS, but clearly one of the rules
    (nowrap, perhaps?) forces <br> to be parsed as chr(10).

    > Here's an example of the generated HTML table:
    >
    > <table border="1" width="100%">
    > <tr height="60" valign="bottom">
    > <td width="120">One<br />Two<br />Three</td>
    > </tr>
    > </table>
    >
    > If you open it up in Excel you see that it's on three rows ont one.


    The following gets you what you want:

    <html xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
    xmlns:x="urn:schemas-microsoft-com:eek:ffice:excel"
    xmlns="http://www.w3.org/TR/REC-html40">

    <head>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 11">
    <style>
    <!--table
    {mso-displayed-decimal-separator:"\.";
    mso-displayed-thousand-separator:"\,";}
    @page
    {margin:1.0in .75in 1.0in .75in;
    mso-header-margin:.5in;
    mso-footer-margin:.5in;}
    tr
    {mso-height-source:auto;}
    col
    {mso-width-source:auto;}
    br
    {mso-data-placement:same-cell;}
    ..style0
    {mso-number-format:General;
    text-align:general;
    vertical-align:bottom;
    white-space:nowrap;
    mso-rotate:0;
    mso-background-source:auto;
    mso-pattern:auto;
    color:windowtext;
    font-size:10.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:Arial;
    mso-generic-font-family:auto;
    mso-font-charset:0;
    border:none;
    mso-protection:locked visible;
    mso-style-name:Normal;
    mso-style-id:0;}
    td
    {mso-style-parent:style0;
    padding-top:1px;
    padding-right:1px;
    padding-left:1px;
    mso-ignore:padding;
    color:windowtext;
    font-size:10.0pt;
    font-weight:400;
    font-style:normal;
    text-decoration:none;
    font-family:Arial;
    mso-generic-font-family:auto;
    mso-font-charset:0;
    mso-number-format:General;
    text-align:general;
    vertical-align:bottom;
    border:none;
    mso-background-source:auto;
    mso-pattern:auto;
    mso-protection:locked visible;
    white-space:nowrap;
    mso-rotate:0;}
    ..xl24
    {mso-style-parent:style0;
    white-space:normal;}
    -->
    </style>
    </head>

    <body>

    <table x:str border=0 cellpadding=0 cellspacing=0 width=64
    style='border-collapse:
    collapse;table-layout:fixed;width:48pt'>
    <col width=64 style='width:48pt'>
    <tr height=51 style='height:38.25pt'>
    <td height=51 class=xl24 width=64 style='height:38.25pt;width:48pt'>1<br>
    2<br>
    3</td>
    </tr>
    </table>
    </body>
    </html>

    --
    Mike Brind
     
    Mike Brind, Dec 3, 2006
    #6
  7. McKirahan

    McKirahan Guest

    "Mike Brind" <> wrote in message
    news:#...
    > Then you need to simulate Excel. Create a file in the way that you want

    it,
    > save it as html then open the result in Notepad. You'll see it has it's

    own
    > CSS declarations. I'm no expert on CSS, but clearly one of the rules
    > (nowrap, perhaps?) forces <br> to be parsed as chr(10).
    >
    > The following gets you what you want:
    >
    > <html xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
    > xmlns:x="urn:schemas-microsoft-com:eek:ffice:excel"
    > xmlns="http://www.w3.org/TR/REC-html40">
    >
    > <head>
    > <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    > <meta name=ProgId content=Excel.Sheet>
    > <meta name=Generator content="Microsoft Excel 11">
    > <style>
    > <!--table
    > {mso-displayed-decimal-separator:"\.";
    > mso-displayed-thousand-separator:"\,";}
    > @page
    > {margin:1.0in .75in 1.0in .75in;
    > mso-header-margin:.5in;
    > mso-footer-margin:.5in;}
    > tr
    > {mso-height-source:auto;}
    > col
    > {mso-width-source:auto;}
    > br
    > {mso-data-placement:same-cell;}
    > .style0
    > {mso-number-format:General;
    > text-align:general;
    > vertical-align:bottom;
    > white-space:nowrap;
    > mso-rotate:0;
    > mso-background-source:auto;
    > mso-pattern:auto;
    > color:windowtext;
    > font-size:10.0pt;
    > font-weight:400;
    > font-style:normal;
    > text-decoration:none;
    > font-family:Arial;
    > mso-generic-font-family:auto;
    > mso-font-charset:0;
    > border:none;
    > mso-protection:locked visible;
    > mso-style-name:Normal;
    > mso-style-id:0;}
    > td
    > {mso-style-parent:style0;
    > padding-top:1px;
    > padding-right:1px;
    > padding-left:1px;
    > mso-ignore:padding;
    > color:windowtext;
    > font-size:10.0pt;
    > font-weight:400;
    > font-style:normal;
    > text-decoration:none;
    > font-family:Arial;
    > mso-generic-font-family:auto;
    > mso-font-charset:0;
    > mso-number-format:General;
    > text-align:general;
    > vertical-align:bottom;
    > border:none;
    > mso-background-source:auto;
    > mso-pattern:auto;
    > mso-protection:locked visible;
    > white-space:nowrap;
    > mso-rotate:0;}
    > .xl24
    > {mso-style-parent:style0;
    > white-space:normal;}
    > -->
    > </style>
    > </head>
    >
    > <body>
    >
    > <table x:str border=0 cellpadding=0 cellspacing=0 width=64
    > style='border-collapse:
    > collapse;table-layout:fixed;width:48pt'>
    > <col width=64 style='width:48pt'>
    > <tr height=51 style='height:38.25pt'>
    > <td height=51 class=xl24 width=64

    style='height:38.25pt;width:48pt'>1<br>
    > 2<br>
    > 3</td>
    > </tr>
    > </table>
    > </body>
    > </html>


    Thank you!

    I took your advice -- I created a simple Excel file and saved it as HTML.

    The key piece seems to be:

    <style>
    br { mso-data-placement:same-cell; }
    </style>

    as this gives me what I want:

    <html>
    <head>
    <style>
    br { mso-data-placement:same-cell; }
    </style>
    </head>
    <body>
    <table border=1 cellpadding=0 cellspacing=0 width=64>
    <tr valign="top">
    <td>1<br>2<br>3</td>
    <td>4</td>
    </tr>
    </table>
    </body>
    </html>

    A Google found this to confirm it:

    CodeSnip:Export DataTable to Excel
    http://aspalliance.com/518

    Many thanks!
     
    McKirahan, Dec 4, 2006
    #7
    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. Dave Tichenor
    Replies:
    3
    Views:
    32,206
    Steven Cheng[MSFT]
    Feb 17, 2004
  2. Multi-line cell in Excel

    , Oct 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,289
  3. Replies:
    0
    Views:
    344
  4. Phillip Roncoroni
    Replies:
    14
    Views:
    1,123
    Toby A Inkster
    Apr 5, 2004
  5. Replies:
    1
    Views:
    453
    Tim Williams
    Mar 28, 2007
Loading...

Share This Page