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

查看:25
本文介绍了经典 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 对 如何从经典 ASP 输出 Excel *.xls 文件

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
Line2</td>
        <td>Line1
Line2</td>
    </tr>
</table>

我在 Excel 2010 中打开 XLS.前 3 个使用 HTML 标记的示例显示回车,但将数据拆分为 2 行.其余示例将数据显示在一行上.有什么办法来填充使用经典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

和第四,第六和第七TD的包含在HTML源回车

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天全站免登陆