我想将我的html表导出到在一张页面上适合所有列的excel工作表中,这是我的代码,但是它不起作用,请帮忙!非常感谢!
emplate += '<style><!--table {mso-displayed-decimal-separator:"\.";mso-displayed-thousand-separator:"\,";} @page {mso-header-data:"&"; mso-footer-data:"&P/&N";' +
' margin:.31in 0in .31in 0in; mso-header-margin:0in; mso-footer-margin:0in; mso-page-orientation:landscape; mso-page-scale: .1 .0} --></style>';
template += '<xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Sheet1</x:Name>';
template += '<x:WorksheetOptions><x:FitColumns/><x:Selected/><x:FreezePanes/><x:FrozenNoSplit/><x:SplitHorizontal>' + freezeTopRowNumber + '</x:SplitHorizontal><x:TopRowBottomPane>' + freezeTopRowNumber + '</x:TopRowBottomPane>';
template += '<x:Print><x:ValidPrinterInfo/><x:PaperSizeIndex>9</x:PaperSizeIndex><x:HorizontalResolution>600</x:HorizontalResolution><x:VerticalResolution>600</x:VerticalResolution></x:Print>';
template += '<x:ActivePane>2</x:ActivePane><x:Panes><x:Pane><x:Number>3</x:Number></x:Pane><x:Pane><x:Number>2</x:Number></x:Pane></x:Panes>';
template += '<x:ProtectContents>False</x:ProtectContents><x:ProtectObjects>False</x:ProtectObjects><x:ProtectScenarios>False</x:ProtectScenarios>';
template += '<x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>';
template += '<x:ExcelName><x:Name>Print_Titles</x:Name><x:SheetIndex>1</x:SheetIndex><x:Formula>=Sheet1!$6:$6</x:Formula></x:ExcelName></xml><![endif]--></head>';
template += '<body style="text-align:center"><center>{table}</center></body></html>';
答案 0 :(得分:0)
我已经在excel中成功mso-fit-text-to-shape:true
使用了以下标记,这会将打印结果缩小到一页。
此处有些参考:Export to Excel Page Orientation和mso-fit-shape-to-text