Format <cfspreadsheet> as table

前提是你 提交于 2020-01-16 03:43:04

问题


I'm using <cfspreadsheet> to output a database query to an Excel spreadsheet. When these spreadsheets are created manually it is possible to highlight all the cells and 'Format as table'. This means when the table header is clicked, the user can sort the table ascending and descending.

Is it possible to specify this formatting in the ColdFusion code when generating the Excel file?


回答1:


If you are on Coldfusion 9, you can use SpreadSheetNew, then SpreadSheetAddRow, SpreadSheetFormat functions to style an excel spreadsheet from a data set

 <cfset sObj = spreadsheetNew("myreport","yes")>
 <cfset SpreadsheetAddRow(sObj, "Column_1, ... , Column27")>

 <cfset SpreadsheetFormatRow(sObj, {bold=TRUE, alignment="center"}, 1)>

 <cfset spreadsheetAddRows(sObj, qMyQuery)>
    <cfheader name="content-disposition" value="attachment; filename=report_#Dateformat(NOW(),"MMDDYYYY")#.xlsx">

BE WARNED however, this can be extremely taxing to the JVM, I had a query i was creating an xls with, applying only two styles (bold, text-center) to the header row, and any query over 700 rows would shut down the entire server via JVM memory loss...here is my SO question about it, with related code/answer SpreadsheetAddRows failing on moderate size query

It has been documented with adobe as being a bug



来源:https://stackoverflow.com/questions/16237648/format-cfspreadsheet-as-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!