SpreadsheetFormatRow突然停止工作

时间:2016-06-14 16:55:15

标签: coldfusion spreadsheet coldfusion-10 cfspreadsheet

我看过this帖子,但看起来确实是一个解决方案。无论如何,我正在使用ColdFusion 10来生成Excel电子表格。但是,当我使用SpreadsheetFormatRow()并传入要格式化的行时,它只执行大约3然后突然停止。这是一个例子......

ColdFusion代码

<cfscript>

    rowCount = 1;
    headingRows = 4;

    // Create instance of new Spreadsheet
    excelSheet = SpreadsheetNew("ReportName",false); 

    // HEADING (IMAGE) ROW FORMAT
    formatHeadingRow = StructNew();
    formatHeadingRow.fgcolor="blue";        

    // Add rows to fill the header area (must add as many as we are spanning with the above image)
    for (x=0;x<headingRows;x++) {
        SpreadsheetAddRow(excelSheet,"TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST,TEST");
        SpreadsheetFormatRow(excelSheet,formatHeadingRow,rowCount);
        rowCount++;
    }

</cfscript>

<!--- stream it to the browser --->
<cfheader name="Content-Disposition" value="inline; filename=reportName.xls">
<cfcontent type="application/vnd.ms-excel" variable="#SpreadSheetReadBinary(excelSheet)#">

以下是生成的Excel表格的屏幕截图

enter image description here

为什么X行和单元格后格式化停止? 如果我切换到使用XML格式

excelSheet = SpreadsheetNew("ReportName",true);

它运作正常。但是我正在为我的颜色使用自定义调色板,所以我不认为切换到XLSX格式对我有用。当我尝试然后打电话

palette = excelSheet.getWorkbook().getCustomPalette();

我收到一条错误,指出getCustomPalette()方法未定义。

coldfusion.runtime.java.MethodSelectionException: The getcustompalette method was not found

任何人都可以帮我解决这个问题吗?谢谢!!!

甚至更好,因为它适用于XML格式,任何人都可以展示如何使用XLSX(xml格式)的自定义调色板

2 个答案:

答案 0 :(得分:3)

这是我在处理来自CF的xls文件时经常看到的问题;他们似乎在一定数量的细胞后停止使用样式。我已经能够通过输出到xlsx来解决它。 (通过这样做,我能够复制并“修复”你的问题。)

excelSheet = SpreadsheetNew("ReportName",true); 

...

<cfheader name="Content-Disposition" value="inline; filename=reportName.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        variable="#SpreadSheetReadBinary(excelSheet)#">

答案 1 :(得分:3)

由于您要对所有行应用完全相同的格式,因此只需一次,而不是每行。在循环之后使用SpreadsheetFormatCellRange可以解决问题:

SpreadsheetFormatCellRange(excelSheet
                             , formatHeadingRow
                              , startRow
                              , startCol
                              , endRow
                              , endCol ); 

怀疑问题以某种方式与Excel's maximum style limits有关。由于CF是一个黑盒子,很难知道它实际创建了多少样式或者确切地说它们的应用方式。但是,根据我的经验,很容易超出样式限制而不知道它。特别是在使用较旧的.xls文件格式时,其限制要低得多。这就是为什么我建议using the newer .xlsx format instead

  

getCustomPalette()方法未定义。

正确。它在XSSF中不存在。是否有某些原因需要自定义调色板而不仅仅是defining your own colors,如您的其他线程中所述?