从ColdFusion导出到Excel,如何修改页面设置? [英] Exporting from ColdFusion to Excel, how to modify Page Setup?

查看:155
本文介绍了从ColdFusion导出到Excel,如何修改页面设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从ColdFusion 9导出到Excel,我想设置页面方向和缩放,使导出的Excel文档适合页面和打印景观。如何完成此操作?



使用解决方案进行编辑:

感谢您的帮助。页面方向设置的工作方式与广告一样。

我使用以下hack来使其适合页面宽度。



此页面包含有关可能的各种设置:

http://msdn.microsoft.com/en-us/library/Aa155477%28office.10%29.aspx

 < cfheader name =Content-dispositionvalue =attachment; filename = export.xls> 
< cfcontent type =application / application / vnd.ms-excel>

<!---
mso-page-orientation:landscape导出导出的excel电子表格打印格局。
设置Scale = 45使打印输出适合我的页面宽度。
根据文档,我应该能够设置
< x:Print>< x:FitWidth> 1< / x:FitWidth>< x:FitHeight> 32767< / x:FitHeight> < x:ValidPrinterInfo />< / x:Print>
,但它不想工作。
宽度和高度在页面设置对话框中正确显示,但调整为缩放大小
单选按钮保持选中,而不是适合一页宽乘32767高单选按钮。
--->

< HTML xmlns:x =urn:schemas-microsoft-com:office:excel>
< HEAD>
< STYLE>
<! - table
@page {mso-page-orientation:landscape;}
- >
< / STYLE>
<! - [if gte mso 9]>< xml>
< x:ExcelWorkbook>
< x:ExcelWorksheets>
< x:ExcelWorksheet>
< x:WorksheetOptions>
< x:Print>
< x:ValidPrinterInfo />
< x:Scale> 45< / x:Scale>
< / x:Print>
< / x:WorksheetOptions>
< / x:ExcelWorksheet>
< / x:ExcelWorksheets>
< / x:ExcelWorkbook>
< / xml><![endif] - >
< / HEAD>
< BODY>

< cfoutput>
< cfloop from =1to =#arrayLen(reportItems)#index =i>
< table cellpadding =1cellspacing =1bgcolor =dcdcdcwidth =100%border =1>
... table contents ...
< / table>
< / cfloop>
< / cfoutput>

< / BODY>
< / HTML>


解决方案

/ p>

如何在传输MIME内容时格式化Excel工作簿



基本上,您输出一个标准HTML数据表,您希望将其打开为Excel电子表格。您还必须为Excel指定MIME类型,并且为了良好的度量,我还喜欢指定content-disposition标题以提示更好的下载文件名。

 < cfcontent type =application / msexcel/> 
< cfheader name =content-dispositionvalue =attachment; filename = myFile.xls>

然后,在上面的链接中找到您的特定格式问题的关键。您需要在MS Office特定的CSS规则中包含< style> mso-page-orientation:landscape; 。从该链接:

 < style> 
<! - table
@page
{mso-header-data:& CMultiplication Table\000ADate\:& D\000APage& P;
mso-page-orientation:landscape;}
br
{mso-data-placement:same-cell;}

- >
< / style>

这应该处理页面方向问题。需要注意的一点是,Office 2007及更高版本会在打开此文件时向用户发出有关不同内容类型的警告。这只是一个烦恼(可以禁用注册表更新);一切仍然可以工作,并根据需要运行。


I'm exporting from ColdFusion 9 to Excel and I want to set the page orientation and scaling so the exported excel document fits to page and prints landscape. How to accomplish this?

Edit with solution:
Thanks for the assistance. The page-orientation setting worked as advertised.
I used the following hack to get it to fit to page width.

This page contains documentation on the various settings that are possible:
http://msdn.microsoft.com/en-us/library/Aa155477%28office.10%29.aspx

<cfheader name="Content-disposition" value="attachment;filename=export.xls">
<cfcontent type="application/application/vnd.ms-excel">

<!--- 
mso-page-orientation:landscape causes the exported excel spreadsheet to be printed landscape.
Setting Scale=45 causes the printout to fit to page width for me.
Per the documentation, I should be able to set
<x:Print><x:FitWidth>1</x:FitWidth><x:FitHeight>32767</x:FitHeight><x:ValidPrinterInfo/></x:Print>
but it doesn't want to work.
The width and height appear correctly in the Page Setup dialog, but the 'Adjust to' scale size
radio button remains selected instead of the 'Fit to' one page wide by 32767 tall radio button.
--->

<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
<HEAD>
<STYLE>
  <!--table
  @page {mso-page-orientation:landscape;}
  -->
</STYLE>
  <!--[if gte mso 9]><xml>
   <x:ExcelWorkbook>
    <x:ExcelWorksheets>
     <x:ExcelWorksheet>
      <x:WorksheetOptions>
       <x:Print>
        <x:ValidPrinterInfo/>
        <x:Scale>45</x:Scale>
       </x:Print>
      </x:WorksheetOptions>
     </x:ExcelWorksheet>
    </x:ExcelWorksheets>
   </x:ExcelWorkbook>
  </xml><![endif]--> 
</HEAD>
<BODY>

<cfoutput>
  <cfloop from = "1" to = "#arrayLen(reportItems)#" index = "i">
    <table cellpadding="1" cellspacing="1" bgcolor="dcdcdc" width="100%" border="1">
      ... table contents ...
    </table>
  </cfloop>
</cfoutput>

</BODY>
</HTML>

解决方案

You can use a trick documented on this page:

How to format an Excel workbook while streaming MIME content

Basically, you output a standard HTML table of data that you would like opened as an Excel spreadsheet. You also have to specify the mime-type for Excel, and for good measure I also like to specify the content-disposition header to prompt for a better download file name.

<cfcontent type="application/msexcel"/> 
<cfheader name="content-disposition" value="attachment; filename=myFile.xls">

The key to your specific formatting question, then, is also found in that above link. You need to include a <style> block with the MS Office-specific CSS rule mso-page-orientation:landscape;. From that link:

<style>
  <!--table
  @page
     {mso-header-data:"&CMultiplication Table\000ADate\: &D\000APage &P";
    mso-page-orientation:landscape;}
     br
     {mso-data-placement:same-cell;}

  -->
</style>

This should handle the page orientation question. One thing to note - Office 2007 and newer will warn users about differing content types when opening this file. It's simply an annoyance (that can be disabled with a registry update); everything will still work and function as needed.

这篇关于从ColdFusion导出到Excel,如何修改页面设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆