例如在 HTTP Header 中利用 Content-disposition 讓使用者下載指定的檔案:
Content-Disposition: inline; filename=data.xls不過有人會以為在 <td> 中加入 <br/> 會讓資料在 Excel 的儲存格中換行. 結果實際並不是這樣.
例如以下的 HTML, 會在 Excel 中形成下圖的結果 (加入 <br> 造成分成兩列的結果).
<table align="center" border="1" cellpadding="3"
cellspacing="1" bgcolor="#336699" class="e12" width="98%">
<tr bgcolor="#CCDDEE">
<td><p align="center">No.</p></td>
<td><p align="center">Content</p></td>
</tr>
<tr bgcolor="#FFFEEE">
<td align="center">1</td>
<td align="center">
Hello<br />World
</td>
</tr>
</table>
br
{mso-data-placement:same-cell;}
接下來就試著把 <br> 加上這個 style 的設定看看: <table align="center" border="1" cellpadding="3"
cellspacing="1" bgcolor="#336699" class="e12" width="98%">
<tr bgcolor="#CCDDEE">
<td><p align="center">No.</p></td>
<td><p align="center">Content</p></td>
</tr>
<tr bgcolor="#FFFEEE">
<td align="center">1</td>
<td align="center">
Hello<br style="mso-data-placement:same-cell;">World
</td>
</tr>
</table>
最後就會產生我們希望的斷行結果, 如下圖: 結論: 請記得在 <br> 中加上 style="mso-data-placement:same-cell;", 才能正確地在儲存格中斷行.
我現在都改用xml了
回覆刪除http://msdn.microsoft.com/en-us/library/bb226687%28v=office.11%29.aspx
table匯出的格線實在是好醜啊><
為了快點改掉舊程式的bug, 只好先將就用. 要等有空才能好好處理這部分.
回覆刪除哇~ 原來Yilin 大師已搬家到這裏了!
回覆刪除先膜拜一下。
作者已經移除這則留言。
回覆刪除