经典ASP XLS输出,单元格中有回车符 [英] Classic ASP XLS output with carriage return in cell

查看:129
本文介绍了经典ASP XLS输出,单元格中有回车符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

为了进行测试,我使用的是基于Kristof对

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>

我正在Excel 2010中打开XLS.使用HTML标记的前三个示例显示了回车符,但将数据分为两行.其余示例将数据显示在一行上.有没有什么方法可以使用Classic ASP填充Excel字段,并使用回车符而不将其拆分为多行?

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?

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

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屏幕截图

推荐答案

标记的显示与代码中回车输出之间是否有些混淆.

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

标记显示给出了前三个td的回车符的外观

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

以及html源中的第四,第六和第七个td包含回车符

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

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

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>

这篇关于经典ASP XLS输出,单元格中有回车符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆