473,416 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

HTML table in Excel with line feed in cell

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.
Nov 26 '06 #1
6 24511

"McKirahan" <Ne**@McKirahan.comwrote in message
news:3I******************************@comcast.com. ..
>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
Nov 27 '06 #2
"Mike Brind" <so*****@microsoft.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
>
"McKirahan" <Ne**@McKirahan.comwrote in message
news:3I******************************@comcast.com. ..
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).
Nov 27 '06 #3

"McKirahan" <Ne**@McKirahan.comwrote in message
news:At******************************@comcast.com. ..
"Mike Brind" <so*****@microsoft.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
>>
"McKirahan" <Ne**@McKirahan.comwrote in message
news:3I******************************@comcast.com ...
>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
Nov 27 '06 #4
"Mike Brind" <so*****@microsoft.comwrote in message
news:#9**************@TK2MSFTNGP04.phx.gbl...
>
"McKirahan" <Ne**@McKirahan.comwrote in message
news:At******************************@comcast.com. ..
"Mike Brind" <so*****@microsoft.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...
>
"McKirahan" <Ne**@McKirahan.comwrote in message
news:3I******************************@comcast.com. ..
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.
Dec 2 '06 #5

"McKirahan" <Ne**@McKirahan.comwrote in message
news:P6******************************@comcast.com. ..
"Mike Brind" <so*****@microsoft.comwrote in message
news:#9**************@TK2MSFTNGP04.phx.gbl...
>>
"McKirahan" <Ne**@McKirahan.comwrote in message
news:At******************************@comcast.com ...
"Mike Brind" <so*****@microsoft.comwrote in message
news:ee**************@TK2MSFTNGP06.phx.gbl...

"McKirahan" <Ne**@McKirahan.comwrote in message
news:3I******************************@comcast.com ...
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 <brto 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:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office: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
Dec 3 '06 #6
"Mike Brind" <pa*******@hotmail.comwrote in message
news:#B**************@TK2MSFTNGP06.phx.gbl...
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 <brto be parsed as chr(10).

The following gets you what you want:

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office: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!
Dec 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: A P | last post by:
Is this possible? I am planning to export data from SQL that generates HTML table. Instead of selecting the table and then copy then paste to word, I need a script(JS or VB) that will...
4
by: Q. John Chen | last post by:
All, I have an intial page that consist several images arranged nicely in an html table. I can center the table but not vertially so it looks really bad when it is showing in the maximized...
3
by: Spacy | last post by:
Am creating a HTML Report in asp.net. To save this report to excel on client-side, i write this code: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition",...
1
by: anonieko | last post by:
This example applies to javascript, table, cells, rows > > How do you access rows and columns of a HTML table? > > > <script language="javascript"> alert('start');
2
by: Jim Heavey | last post by:
I have an HTML table which has all kinds of special formatting and coloring and I am looking for how I should get this output to excel. I have an example working which is using the...
5
by: =?Utf-8?B?c2NobWlkdGU=?= | last post by:
Hi How can I Export an HTML Table to excel? My goal is a button, and when the user clicks this button a popup appears asking the user to 'open' or 'save' the generated Excel file. Actually...
4
by: =?Utf-8?B?Q2FybGl0b3M=?= | last post by:
Hi there, I have a asp.net page that dynamically constructs a table based on data retrieved from a database. This is an excerpt of the code used: ' Create a row Dim row As HtmlTableRow = New...
8
by: James Kimble | last post by:
Yeah I'm sure this is a stupid question. I've got a javascript source file with functions (creates a bar graph) I want to call from inside an html table cell so that the graph appears in the...
2
by: wannasee | last post by:
Hello everybody, I am new at javascript and I would like to write a script that resizes the input fieds of an html table depending on the entered text. The input fields are placed in table cells...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.