SpreadsheetFormatRow abruptly stops working

筅森魡賤 提交于 2019-12-20 02:15:16

问题


I've seen this post, but there does look to be a resolution. Anyway, I'm using ColdFusion 10 to generate an Excel spreadsheet. However, when I use SpreadsheetFormatRow() and pass in the rows to be formatted, it only does about 3 and then abruptly stops. Here is an example...

ColdFusion Code

<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)#">

and here is a screenshot of the resulting Excel sheet

Why is the formatting stopping after X number of rows and cells? If I switch to using XML format with

excelSheet = SpreadsheetNew("ReportName",true);

it works properly. However I'm using a custom palette for my colors so I don't think switching to XLSX format is going to work for me. When I try and then call

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

I get an error stating that getCustomPalette() method is undefined.

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

Can anyone help me figure this out? Thank you!!!

Or even better since it works with the XML format, can anyone show example of how to use a custom palette with the XLSX (xml format)


回答1:


This is an issue I have seen often when dealing with xls files from CF; they seem to stop applying styles after a certain number of cells. I've been able to work around it by outputting to xlsx instead. (I was able to replicate and "fix" your issue by doing so.)

excelSheet = SpreadsheetNew("ReportName",true); 

...

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



回答2:


Since you are applying the exact same format to all rows, only do it once, not on each row. Using SpreadsheetFormatCellRange after the loop should resolve the issue:

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

I suspect the problem somehow relates back to Excel's maximum style limits. Since CF is a black box, it is difficult to know how many styles it actually creates or exactly how they are applied. However, in my experience it is very easy to exceed the style limits without even knowing it. Especially when using the older .xls file format, whose limits are much lower. That is why I suggested using the newer .xlsx format instead.

getCustomPalette() method is undefined.

Correct. It does not exist in XSSF. Is there some reason you need a custom palette instead of just defining your own colors, as mentioned in your other thread?



来源:https://stackoverflow.com/questions/37817997/spreadsheetformatrow-abruptly-stops-working

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