Creating an Excel file from ASP and setting a LineFeed

  • Thread starter Michael G. Schneider
  • Start date
M

Michael G. Schneider

From ASP I create response, which is to be shown as an Excel worksheet in
the user's browser (by setting the ContentType and creating a table). This
works fine.

Does anybody know what to do, if one of the cells should contain a multiline
text? I already tried by inserting a <br> inside the <td>. But this won't
work.
 
B

Bob Barrows [MVP]

Michael said:
From ASP I create response, which is to be shown as an Excel
worksheet in the user's browser (by setting the ContentType and
creating a table). This works fine.

Does anybody know what to do, if one of the cells should contain a
multiline text? I already tried by inserting a <br> inside the <td>.
But this won't work.

Reverse engineer it. Create a spreadsheet in excel that contains multiline
data, save it as html and look at the source to see what you need to
generate in asp.

Bob Barrows
 
M

Michael G. Schneider

Reverse engineer it. Create a spreadsheet in excel that contains multiline
data, save it as html and look at the source to see what you need to
generate in asp.

Thank's a lot for the answer.

Currently, I only set the ContentType corretly, then generate a simple HTML
table with nothing more than some tr's and td's. That is enough for making
Excel show the worksheet.

Reverse engineering the Excel HTML output meant that a lot of "noise" would
have to be generated. There is much more in a HTML file generated by Excel
than the HTML table.

I hoped that there would be some simple mechansim, such as inserted a <br>
or a vbCr or a vbLF or a vbCrLF or something else, which does the trick.
 
B

Bob Barrows [MVP]

Michael said:
Thank's a lot for the answer.

Currently, I only set the ContentType corretly, then generate a
simple HTML table with nothing more than some tr's and td's. That is
enough for making Excel show the worksheet.

Reverse engineering the Excel HTML output meant that a lot of "noise"
would have to be generated. There is much more in a HTML file
generated by Excel than the HTML table.

I'm not telling you to use the entire html from the test file ... just find
the part where the line break is accomplished and incorporate that into your
asp code.

I suspect it has something to do with setting the column width (perhaps
using <col> tags). The only way to know for sure is to look at the html that
Excel generates to accomplish the same formatting.

Bob Barrows
 
M

McKirahan

Michael G. Schneider said:
Thank's a lot for the answer.

Currently, I only set the ContentType corretly, then generate a simple HTML
table with nothing more than some tr's and td's. That is enough for making
Excel show the worksheet.

Reverse engineering the Excel HTML output meant that a lot of "noise" would
have to be generated. There is much more in a HTML file generated by Excel
than the HTML table.

I hoped that there would be some simple mechansim, such as inserted a <br>
or a vbCr or a vbLF or a vbCrLF or something else, which does the trick.

[snip]

Bob's suggestion of reverse engineering meant to find the small difference
generated to support multiline data by looking at the HTML output.

My efforts identified this style: { white-space:normal }

What happens when you try this: <td style="white-space:normal">
 
M

Michael G. Schneider

Bob's suggestion of reverse engineering meant to find the small difference
generated to support multiline data by looking at the HTML output.

My efforts identified this style: { white-space:normal }

What happens when you try this: <td style="white-space:normal">

Thank's a lot for the answer. I can confirm that it has something to do with
this style. However, it is not this style alone. For example, if the
following is opened by MS Excel...

<table>
<tr>
<td style="white-space:normal;">1<br>2<br>3<br>4</td>
</tr>
</table>

....four rows will be filled with the numbers.

I think it is best, if I switch over to generating a file that contains all
those Excel specific style information. Then it will work. Finding exactly
which minimum combination of CSS is necessary is probably not worth the
effort.

Thank's again.
 
L

Larry Bud

Michael said:
Thank's a lot for the answer. I can confirm that it has something to do with
this style. However, it is not this style alone. For example, if the
following is opened by MS Excel...

<table>
<tr>
<td style="white-space:normal;">1<br>2<br>3<br>4</td>
</tr>
</table>

...four rows will be filled with the numbers.

I think it is best, if I switch over to generating a file that contains all
those Excel specific style information. Then it will work. Finding exactly
which minimum combination of CSS is necessary is probably not worth the
effort.

Here's the style I use for wrapping text with possible <BR> breaks.

..text {mso-number-format:General; text-align:general;white-space:
normal;mso-spacerun: yes }
 
M

Michael G. Schneider

Here's the style I use for wrapping text with possible <BR> breaks.

.text {mso-number-format:General; text-align:general;white-space:
normal;mso-spacerun: yes }

Thank's a lot for the answer. This does work.

Does anybody know, whether these style are documented somewhere? Is there a
list, which attributes / values are allowed? Or does anybody know a way for
autosizing the column width?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top