【问题标题】:Formatting HTML Tables for Excel为 Excel 格式化 HTML 表格
【发布时间】:2016-11-09 17:56:59
【问题描述】:

我在 asp 中有一个创建 xls 表的页面,但是当打开表时,所有行都填充到我想要设置的默认列宽中。

我的桌子看起来像这样:

<table>
<thead>
'A for loop makes a series of th 
</thead>
'another loop pulls db values
<tr><td>value1</td><td>value2</td> 'etc </tr>
</table>

我尝试了以下设置空间

  • width="3.29in"
  • &nsp;垃圾邮件(野蛮但有时有效)
  • width="400px"
  • style="width:300px"

上述方法似乎都不起作用。

另外这里是我的标题 asp 以防它的相关

Response.Clear()
Response.Buffer = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=blah.xls"

由于某种原因,当我印有美元价值时,也附注

<td>$<%=dbvalue%></td>

由于某种原因,这会产生 '$dollar 价值,我不确定如何取消单引号。

【问题讨论】:

  • 如果您不使用“th”系列并将它们保留为“td”会发生什么?您可以将 td 的样式添加为 font-weight

标签: excel asp-classic formatting html-table


【解决方案1】:

你需要thead标签吗?像这样的东西应该可以工作:

<html>
<body>
<h1>Report Title</h1>
<table >
<tr>
 <th style="width : 300px">header1</th>
 <th style="width : 100px">header2</th>
 <th style="width : 200px">header..</th>
 <th style="width : 300px">....</th>
</tr>
<tr class="row1">
 <td >value1</td>
 <td >value2</td>
 <td >value..</td>
 <td >....</td>
</tr>
....

您可以选择将带有 th 标签的表格行放在 标签内

【讨论】:

  • 对最终的 xls 没有影响 或其他方式,
  • 以上代码在 Excel 2007 中适用于我。如果不是 excel 版本问题,则可能是您的表格前的某些东西造成了破坏,或者您的 for 循环中有问题。尝试使用文本编辑器打开实际创建的 xls,查看实际创建的 html 类型并先修复它。

猜你喜欢
相关资源
最近更新 更多
热门标签