HTML导出到Excel中,mso-data-placement:same-cell失去换行符

我正在生成一个HTML文档,然后将其作为Excel电子表格。 一切正常,除了首先,Excel正在阅读
换行成新的单元格。 我find了一个解决方法,那就是添加<style>br { mso-data-placement:same-cell; }</style> <style>br { mso-data-placement:same-cell; }</style>这足够保证所有的数据在同一个单元格中,但是我完全丢失了换行符,并且它保持在同一行。

有没有其他人有这个问题?

我无法弄清楚为什么会发生这种事。 这是我的完整代码:

 <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html;charset=windows-1252"> <meta name=ProgId content=Excel.Sheet/> <meta name=Generator content="Microsoft Excel 11"> <!--[if gte mso 9]><xml> <x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetOptions><x:Panes> </x:Panes></x:WorksheetOptions> </x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook> </xml> <![endif]--> <style> br {mso-data-placement:same-cell;} </style> <body> <table> <tr> <td colspan="2" style="font-size:14pt;font-weight:bold;"><?= $user['company_name'] ?> File System Listing</th> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td colspan="2">1. To Enter or Sort</td> </tr> <tr> <td width="45">&nbsp;</td> <td width="300">To Enter</td> </tr> <tr> <td>&nbsp;</td> <td>To Pay</td> </tr> <tr> <td>&nbsp;</td> <td>To Do</td> </tr> <tr> <td>&nbsp;</td> <td>To File- Completed</td> </tr> <tr> <td>&nbsp;</td> <td><?= $user['business_bank'] ?><br>Deposit Slips</td> </tr> <tr> <td>&nbsp;</td> <td>Receipt Sorting <?= $user['business_bank'] ?><br><?= $user['account1_name'] ?> Card x<?= $user['account1_debit'] ?><br><?= $user['account1_name'] ?> x<?= $user['account1_num'] ?></td> </tr> </table> </body> </html> 

你没有closures的“头”标签。 如果仍然不起作用,请尝试将内联样式放置。 例如:

 <br style="mso-data-placement:same-cell;" /> 

而不是在风格标签。 Excel应该评估你的头部风格,但是让我们来检查一下是否有问题。