导出到Excel并使用ColdFusion 10格式化单元格



我有一个查询,我想在Excel中的电子表格中输出。我希望一些单元格列以某种方式格式化,这是数千分组和数字格式,以便总和,添加等可以在该行上完成,而无需任何进一步的更改。

我已经通读了文档,但它让我对如何首先输出到Excel有点困惑。

我以一个评论开始,但它会更容易阅读作为一个答案。

你试过什么?你读过CFSpreadsheet文档了吗?应该是很直接的。CFSpreadsheet标签的参数之一是"query"。为什么不从这个开始,看看默认情况下它是如何为你格式化列的,看看需要调整什么。

下面是一个直接取自参考文档页面的例子:

<cfquery name="courses" datasource="cfdocexamples"> 
    SELECT CORNUMBER, DEPT_ID, COURSE_ID, CORNAME 
    FROM COURSELIST 
</cfquery> 
<cfscript> 
    //Use an absolute path for the files. ---> 
    theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
    theFile=theDir & "courses.xls"; 
    //Create an empty ColdFusion spreadsheet object. ---> 
    theSheet = SpreadsheetNew("CourseData"); 
    //Populate the object with a query. ---> 
    SpreadsheetAddRows(theSheet,courses); 
</cfscript>
<!--- Write the sheet to a file ---> 
<cfspreadsheet action="write" filename="#theFile#" name="theSheet" sheetname="courses" overwrite=true> 

请参阅SpreadsheetFormatColumn, SpreadsheetFormatColumns, SpreadsheetFormatRow和SpreadsheetFormatRows的文档,以阅读有关格式化特定单元格的信息。

您只需要使用cfspreadsheet标记来创建文件,并且可以使用spreadsheetFormat*函数格式化单元格。您可以在Ray Camden的网站上找到如何做到这一点的示例。

最新更新