经典 ASP XLS 输出,单元格中带有回车符
我有一个经典的 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 行),而其余的全部显示在一行上。我正在尝试在一个单元格中实现两行文本。是否有任何其他代码可以用来插入换行符但将数据保留在一个单元格中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中标记的显示和回车符的输出之间是否存在一些混淆。
提供回车符外观
标记显示为前三个 td
以及第四、第六和第七个 td 在 html 源代码中包含回车
编辑 asp 每个评论和提供的屏幕截图
将以下样式添加到您的页面您可以看到第一个单元格的行为符合预期。
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
and the fourth, sixth and seventh td's contain carriage returns in the html source
EDIT asp per comment and screenshot supplied
Add the following style to your page and you can see the first cell behaving as desired.