473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24577

"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*****@micros oft.comwrote in message
news:ee******** ******@TK2MSFTN GP06.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*****@micros oft.comwrote in message
news:ee******** ******@TK2MSFTN GP06.phx.gbl...
>>
"McKirahan" <Ne**@McKirahan .comwrote in message
news:3I******* *************** ********@comcas t.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*****@micros oft.comwrote in message
news:#9******** ******@TK2MSFTN GP04.phx.gbl...
>
"McKirahan" <Ne**@McKirahan .comwrote in message
news:At******** *************** *******@comcast .com...
"Mike Brind" <so*****@micros oft.comwrote in message
news:ee******** ******@TK2MSFTN GP06.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*****@micros oft.comwrote in message
news:#9******** ******@TK2MSFTN GP04.phx.gbl...
>>
"McKirahan" <Ne**@McKirahan .comwrote in message
news:At******* *************** ********@comcas t.com...
"Mike Brind" <so*****@micros oft.comwrote in message
news:ee******** ******@TK2MSFTN GP06.phx.gbl...

"McKirahan" <Ne**@McKirahan .comwrote in message
news:3I******* *************** ********@comcas t.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:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
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.S heet>
<meta name=Generator content="Micros oft 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:windowtex t;
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:lock ed 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:windowtex t;
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:lock ed 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;wi dth:48pt'>
<col width=64 style='width:48 pt'>
<tr height=51 style='height:3 8.25pt'>
<td height=51 class=xl24 width=64 style='height:3 8.25pt;width:48 pt'>1<br>
2<br>
3</td>
</tr>
</table>
</body>
</html>

--
Mike Brind
Dec 3 '06 #6
"Mike Brind" <pa*******@hotm ail.comwrote in message
news:#B******** ******@TK2MSFTN GP06.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:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
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.S heet>
<meta name=Generator content="Micros oft 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:windowtex t;
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:lock ed 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:windowtex t;
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:lock ed 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;wi dth:48pt'>
<col width=64 style='width:48 pt'>
<tr height=51 style='height:3 8.25pt'>
<td height=51 class=xl24 width=64
style='height:3 8.25pt;width:48 pt'>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
5771
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 automatically export or open the Query to word.
4
7476
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 brower. Any suggestion? TIA. John
3
3855
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", "attachment; filename=Report.xls") But once the report is saved in excel, on click of hyperlink for second html report, i dont get the second report. the same old first html report is displayed. Please can anyone help me. Am frustrated with...
1
57524
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
1767
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 response.write and a Datagrid.RenderControl method to stream the output to excel. I am guessing that this method merely writes the out put to my datastream rather then outputing the result to my web page, but the output would look just exactly like it is...
5
4176
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 I'm exporting by rendering my table to an htmlwriter and sending this to excel. This is working nearly perfect. There's a problem with Excel's auto-formatting of cells. Excel is changing the content of my cells. '1.23' is getting 'Jan 23',
4
1761
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 HtmlTableRow ' Create a column and add it to the row Dim cell As HtmlTableCell = New HtmlTableCell cell.InnerText = sValue
8
2143
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 cell. I've tried a bunch of different things but I'm not getting it. I'm a newbee to both html and javascript so be kind. Any example would be appreciated.
2
3718
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 (using <tr> and <td>) arranged like an Excel sheet. Requirements to my script are the following: 1- When an entered text is longer than the length of the input field (there is overflow), then the script should automatically insert a linebreak...
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.