经典 ASP XLS 输出,单元格中带有回车符

发布于 2025-01-02 17:51:44 字数 1444 浏览 1 评论 0原文

我有一个经典的 ASP 脚本,它将 HTML 表输出为 XLS 文件,但没有运气让回车符/换行符在单个单元格中工作。

为了进行测试,我使用基于 Kristof 对 How 的响应的代码从经典 ASP 输出 Excel *.xls 文件

我已经尝试了我所知道的所有插入回车/换行的方法。我的示例代码如下:

<%@ Language=VBScript %>
<%  Option Explicit
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
%>
<table border="1">
    <tr>
        <td>Line1<br />Line2</td>
        <td><p>Line1</p>Line2</td>
        <td><div>Line1</div>Line2</td>
        <td>Line1<%=chr(10)%>Line2</td>
        <td>Line1<%=vbCR%>Line2</td>
        <td>Line1<%=vbLF%>Line2</td>
        <td>Line1<%=vbCRLF%>Line2</td>
        <td>Line1\rLine2</td>
        <td>Line1\nLine2</td>
    </tr>
</table>

我正在 Excel 2010 中打开 XLS。使用 HTML 标记的前 3 个示例显示回车符,但将数据拆分为 2 行。其余示例将数据显示在一行上。有没有办法使用带有回车符的经典 ASP 填充 Excel 字段,而不会将其拆分为多行?

编辑:

为了澄清,我试图复制在 Excel 的单元格中键入 alt-enter 的行为。在下面的屏幕截图中,您可以看到前 3 个示例将数据拆分为两个单元格(第 1 行和第 2 行),而其余的全部显示在一行上。我正在尝试在一个单元格中实现两行文本。是否有任何其他代码可以用来插入换行符但将数据保留在一个单元格中?

Excel 屏幕截图

I have a Classic ASP script that outputs an HTML table as an XLS file but have had no luck getting a carriage return/line feed to work within a single cell.

For testing I am using code based on Kristof's response to How to output an Excel *.xls file from classic ASP

I've tried every method I know of for inserting a carriage return/line feed. My sample code is as follows:

<%@ Language=VBScript %>
<%  Option Explicit
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
%>
<table border="1">
    <tr>
        <td>Line1<br />Line2</td>
        <td><p>Line1</p>Line2</td>
        <td><div>Line1</div>Line2</td>
        <td>Line1<%=chr(10)%>Line2</td>
        <td>Line1<%=vbCR%>Line2</td>
        <td>Line1<%=vbLF%>Line2</td>
        <td>Line1<%=vbCRLF%>Line2</td>
        <td>Line1\rLine2</td>
        <td>Line1\nLine2</td>
    </tr>
</table>

I am opening the XLS in Excel 2010. The first 3 examples using HTML tags show the carriage return but split the data across 2 rows. The rest of the examples show the data on one line. Is there any way to populate an Excel field using Classic ASP with a carriage return without it splitting into multiple rows?

EDIT:

To clarify, I am trying to replicate the behavior of typing alt-enter within a cell in Excel. In the screenshot below you can see that the first 3 examples are splitting the data into two cells (rows 1 & 2) while the rest all appear on one line. I am trying to achieve two lines of text in one cell. Is there any other code I can use to insert a line break but keep the data in one cell?

Excel Screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2025-01-09 17:51:44

您的代码中标记的显示和回车符的输出之间是否存在一些混淆。

提供回车符外观

标记显示为前三个 td 在此处输入图像描述

以及第四、第六和第七个 td 在 html 源代码中包含回车

在此处输入图像描述

编辑 asp 每个评论和提供的屏幕截图

将以下样式添加到您的页面您可以看到第一个单元格的行为符合预期。

<style>
<!--table
br {mso-data-placement:same-cell;}
tr {vertical-align:top;}
-->
</style>

Is there is some confusion between the display of mark-up and output of carriage returns in your code.

The markup display gives the appearance of carriage returns for the first three td's

enter image description here

and the fourth, sixth and seventh td's contain carriage returns in the html source

enter image description here

EDIT asp per comment and screenshot supplied

Add the following style to your page and you can see the first cell behaving as desired.

<style>
<!--table
br {mso-data-placement:same-cell;}
tr {vertical-align:top;}
-->
</style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文