4

I need to resize range of conditional formatting.

Read an Excel file (.xlsm, .xlsx), modify ranges for conditional formatting, and save it as new file.

SheetConditionalFormatting sheetFormatting = sheet.getSheetConditionalFormatting();
for( int i = 0; i < sheetFormatting.getNumConditionalFormattings() ; i++ )
    for( CellRangeAddress region : 
            sheetFormatting.getConditionalFormattingAt(i).getFormattingRanges() )
        if( region.getFirstRow() == 1 )
            region.setLastRow( 1+data.length );

So I just get all conditional formatting objects, get range objects for them, and modify ranges by calling CellRangeAddress.setLastRow().

The problem is that this modification is not present in result file. In fact, there are no changes in sheet.getSheetConditionalFormatting() just after the operation.

Need I 'commit' somehow changes to ConditionalFormatting?

4

1 回答 1

3

是的,您应该在工作表格式中添加条件格式。

sheetFormatting.addConditionalFormatting(newRange,arrayOfRules);
于 2013-12-13T11:17:07.160 回答