2012-01-04 46 views
1

我从ColdFusion 9导出到Excel,我想设置页面方向和缩放比例,以便导出的Excel文档适合页面和打印景观。如何做到这一点?从ColdFusion导出到Excel,如何修改页面设置?

编辑方案:
感谢您的协助。页面方向设置与广告一样工作。
我用下面的hack来使它适合页面宽度。

此页面包含了可能的各种设置文档:
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> 
+0

你能否提供一个代码示例,显示你到目前为止? – Micah 2012-01-04 21:16:40

回答

1

您可以使用记录此页上一招:

How to format an Excel workbook while streaming MIME content

基本上,数据你输出一个标准的HTML表格,你会像打开Excel电子表格一样。您还必须为Excel指定mime类型,为了更好的衡量,我还想指定content-disposition标头以提示更好的下载文件名。

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

关键看你的特定格式的问题,那么,也是在上面的链接找到。您需要在<style>块中包含MS Office特定的CSS规则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和更新版本会在打开此文件时警告用户有关不同内容类型的信息。这只是一个烦恼(可以通过注册表更新来禁用);一切仍然会按需要运作和运作。

0

我看不出有任何属性的cfspreadsheet标签来做到这一点。从Adobe网站:

<cfspreadsheet 
    action="write" 
    filename = "filepath" 
    format = "csv" 
    name = "text" 
    overwrite = "true | false" 
    password = "password" 
    query = "queryname" 
    sheetname = "text" 
> 

您可能有使用打印范围或类似的东西在Excel导出后做。

让CF管理导出正确的数据,让Excel处理格式化/打印。

3

IIRC没有什么可烤的。但你可以挖掘底层的工作簿并使用一点魔法。 (请注意,这些打印设置每张应用)

<!--- get the underlying poi sheet ---> 
<cfset poiSheet = cfSheetObject.getWorkBook().getSheet("TheSheetName")> 
<cfset ps = poiSheet.getPrintSetup()> 
<cfset ps.setLandscape(true)> 
<!--- fit to one page ---> 
<cfset ps.setFitHeight(1)> 
<cfset ps.setFitWidth(1)> 
+0

没关系;)我从你的更新中看到你实际上正在生成一个人造的excel文件(即html)。所以这种方法是行不通的。 – Leigh 2012-01-05 16:15:37

相关问题