diff --git a/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java index 871311f114..75fd4a5e35 100644 --- a/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java @@ -17,6 +17,7 @@ package org.apache.poi.stress; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.FileInputStream; @@ -27,11 +28,13 @@ import java.io.PrintStream; import java.util.HashSet; import java.util.Set; -import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.dev.BiffViewer; +import org.apache.poi.hssf.usermodel.HSSFOptimiser; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.util.RecordFormatException; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.junit.Test; public class HSSFFileHandler extends SpreadsheetHandler { @@ -40,7 +43,7 @@ public class HSSFFileHandler extends SpreadsheetHandler { public void handleFile(InputStream stream, String path) throws Exception { HSSFWorkbook wb = new HSSFWorkbook(stream); handleWorkbook(wb); - + // TODO: some documents fail currently... // Note - as of Bugzilla 48036 (svn r828244, r828247) POI is capable of evaluating // IntersectionPtg. However it is still not capable of parsing it. @@ -52,6 +55,15 @@ public class HSSFFileHandler extends SpreadsheetHandler { // also try to see if some of the Records behave incorrectly // TODO: still fails on some records... RecordsStresser.handleWorkbook(wb); + + HSSFOptimiser.optimiseCellStyles(wb); + for(Sheet sheet : wb) { + for (Row row : sheet) { + for (Cell cell : row) { + assertNotNull(cell.getCellStyle()); + } + } + } } private static final Set EXPECTED_ADDITIONAL_FAILURES = new HashSet<>(); @@ -86,14 +98,6 @@ public class HSSFFileHandler extends SpreadsheetHandler { EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())); } catch (OldExcelFormatException e) { // old excel formats are not supported here - } catch (EncryptedDocumentException e) { - if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) { - throw e; - } - } catch (RecordFormatException e) { - if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) { - throw e; - } } catch (RuntimeException e) { if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) { throw e; @@ -107,12 +111,9 @@ public class HSSFFileHandler extends SpreadsheetHandler { @Test public void test() throws Exception { File file = new File("test-data/spreadsheet/49219.xls"); - - InputStream stream = new FileInputStream(file); - try { + + try (InputStream stream = new FileInputStream(file)) { handleFile(stream, file.getPath()); - } finally { - stream.close(); } } diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index 650b4de270..83e1d37907 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -1680,4 +1680,12 @@ public final class InternalSheet { public int getColumnOutlineLevel(int columnIndex) { return _columnInfos.getOutlineLevel(columnIndex); } + + public int getMinColumnIndex() { + return _columnInfos.getMinColumnIndex(); + } + + public int getMaxColumnIndex() { + return _columnInfos.getMaxColumnIndex(); + } } diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java index 5b9e7c57ae..d16eec62ee 100644 --- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java +++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java @@ -936,6 +936,27 @@ public final class InternalWorkbook { return null; } + /** + * Update the StyleRecord to point to the new + * given index. + * + * @param oldXf the extended format index that was previously associated with this StyleRecord + * @param newXf the extended format index that is now associated with this StyleRecord + */ + public void updateStyleRecord(int oldXf, int newXf) { + // Style records always follow after + // the ExtendedFormat records + for(int i=records.getXfpos(); iColumnInfoRecord which contains the specified columnIndex * @param columnIndex index of the column (not the index of the ColumnInfoRecord) @@ -504,6 +505,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate implements } return null; } + public int getMaxOutlineLevel() { int result = 0; int count=records.size(); @@ -513,6 +515,7 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate implements } return result; } + public int getOutlineLevel(int columnIndex) { ColumnInfoRecord ci = findColumnInfo(columnIndex); if (ci != null) { @@ -521,4 +524,34 @@ public final class ColumnInfoRecordsAggregate extends RecordAggregate implements return 0; } } + + public int getMinColumnIndex() { + if(records.isEmpty()) { + return 0; + } + + int minIndex = Integer.MAX_VALUE; + int nInfos = records.size(); + for(int i=0; i< nInfos; i++) { + ColumnInfoRecord ci = getColInfo(i); + minIndex = Math.min(minIndex, ci.getFirstColumn()); + } + + return minIndex; + } + + public int getMaxColumnIndex() { + if(records.isEmpty()) { + return 0; + } + + int maxIndex = 0; + int nInfos = records.size(); + for(int i=0; i< nInfos; i++) { + ColumnInfoRecord ci = getColInfo(i); + maxIndex = Math.max(maxIndex, ci.getLastColumn()); + } + + return maxIndex; + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java b/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java index c38fd375b2..f4287ce4b5 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFOptimiser.java @@ -20,6 +20,7 @@ import java.util.HashSet; import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.FontRecord; +import org.apache.poi.hssf.record.StyleRecord; import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -185,50 +186,81 @@ public class HSSFOptimiser { // Get each style record, so we can do deletes // without getting confused - ExtendedFormatRecord[] xfrs = new ExtendedFormatRecord[newPos.length]; + ExtendedFormatRecord[] xfrs = new ExtendedFormatRecord[newPos.length]; for(int i=0; i= newPos.length) { + continue; + } + HSSFCellStyle newStyle = workbook.getCellStyleAt(newPos[oldXf]); + cell.setCellStyle(newStyle); + } - HSSFCellStyle newStyle = workbook.getCellStyleAt( - newPos[oldXf] - ); - cell.setCellStyle(newStyle); - } - } - } + // adjust row column style + short oldXf = ((HSSFRow) row).getRowRecord().getXFIndex(); + // some documents contain invalid values here + if(oldXf >= newPos.length) { + continue; + } + HSSFCellStyle newStyle = workbook.getCellStyleAt(newPos[oldXf]); + row.setRowStyle(newStyle); + } + + // adjust cell column style + for (int col = s.getSheet().getMinColumnIndex(); col <= s.getSheet().getMaxColumnIndex(); col++) { + short oldXf = s.getSheet().getXFIndexForColAt((short) col); + // some documents contain invalid values here + if(oldXf >= newPos.length) { + continue; + } + HSSFCellStyle newStyle = workbook.getCellStyleAt(newPos[oldXf]); + s.setDefaultColumnStyle(col, newStyle); + } + } } + + private static boolean isUserDefined(HSSFWorkbook workbook, int index) { + StyleRecord styleRecord = workbook.getWorkbook().getStyleRecord(index); + return styleRecord != null && + !styleRecord.isBuiltin() && + styleRecord.getName() != null; + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java index c407778179..daf18ae6dc 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java @@ -16,12 +16,16 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel; -import org.apache.poi.ss.usermodel.BorderStyle; -import org.apache.poi.ss.usermodel.HorizontalAlignment; +import java.io.IOException; -import junit.framework.TestCase; +import org.apache.poi.ss.usermodel.*; +import org.junit.Test; -public final class TestHSSFOptimiser extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public final class TestHSSFOptimiser { + @Test public void testDoesNoHarmIfNothingToDo() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -60,6 +64,7 @@ public final class TestHSSFOptimiser extends TestCase { assertEquals(f, s.getFont(wb)); } + @Test public void testOptimiseFonts() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -158,6 +163,7 @@ public final class TestHSSFOptimiser extends TestCase { assertEquals(8, r.getCell(1).getRichStringCellValue().getFontAtIndex(7)); } + @Test public void testOptimiseStyles() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -274,6 +280,7 @@ public final class TestHSSFOptimiser extends TestCase { assertEquals(21, r.getCell(8).getCellValueRecord().getXFIndex()); } + @Test public void testOptimiseStylesCheckActualStyles() { HSSFWorkbook wb = new HSSFWorkbook(); @@ -313,4 +320,383 @@ public final class TestHSSFOptimiser extends TestCase { assertEquals(BorderStyle.DASH_DOT, r.getCell(1).getCellStyle().getBorderBottom()); assertEquals(BorderStyle.THICK, r.getCell(2).getCellStyle().getBorderBottom()); } + + @Test + public void testColumnAndRowStyles() { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + Row row = sheet.createRow(0); + row.createCell(0); + row.createCell(1); + row.setRowStyle(createColorStyle(wb, IndexedColors.RED)); + + row = sheet.createRow(1); + row.createCell(0); + row.createCell(1); + row.setRowStyle(createColorStyle(wb, IndexedColors.RED)); + + sheet.setDefaultColumnStyle(0, createColorStyle(wb, IndexedColors.RED)); + sheet.setDefaultColumnStyle(1, createColorStyle(wb, IndexedColors.RED)); + + // now the color should be equal for those two columns and rows + checkColumnStyles(sheet, 0, 1, false); + checkRowStyles(sheet, 0, 1, false); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + + // We should have the same style-objects for these two columns and rows + checkColumnStyles(sheet, 0, 1, true); + checkRowStyles(sheet, 0, 1, true); + } + + @Test + public void testUnusedStyle() { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + Row row = sheet.createRow(0); + row.createCell(0); + row.createCell(1).setCellStyle( + createColorStyle(wb, IndexedColors.GREEN)); + + + row = sheet.createRow(1); + row.createCell(0); + row.createCell(1).setCellStyle( + createColorStyle(wb, IndexedColors.RED)); + + + // Create style. But don't use it. + for (int i = 0; i < 3; i++) { + // Set Cell Color : AQUA + createColorStyle(wb, IndexedColors.AQUA); + } + + assertEquals(21 + 2 + 3, wb.getNumCellStyles()); + assertEquals(IndexedColors.GREEN.getIndex(), sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.RED.getIndex(), sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColor()); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + + assertEquals(21 + 2, wb.getNumCellStyles()); + assertEquals(IndexedColors.GREEN.getIndex(), sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.RED.getIndex(), sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColor()); + } + + @Test + public void testUnusedStyleOneUsed() { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + Row row = sheet.createRow(0); + row.createCell(0); + row.createCell(1).setCellStyle( + createColorStyle(wb, IndexedColors.GREEN)); + + // Create style. But don't use it. + for (int i = 0; i < 3; i++) { + // Set Cell Color : AQUA + createColorStyle(wb, IndexedColors.AQUA); + } + + row = sheet.createRow(1); + row.createCell(0).setCellStyle(createColorStyle(wb, IndexedColors.AQUA)); + row.createCell(1).setCellStyle( + createColorStyle(wb, IndexedColors.RED)); + + assertEquals(21 + 3 + 3, wb.getNumCellStyles()); + assertEquals(IndexedColors.GREEN.getIndex(), sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.AQUA.getIndex(), sheet.getRow(1).getCell(0).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.RED.getIndex(), sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColor()); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + + assertEquals(21 + 3, wb.getNumCellStyles()); + assertEquals(IndexedColors.GREEN.getIndex(), sheet.getRow(0).getCell(1).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.AQUA.getIndex(), sheet.getRow(1).getCell(0).getCellStyle().getFillForegroundColor()); + assertEquals(IndexedColors.RED.getIndex(), sheet.getRow(1).getCell(1).getCellStyle().getFillForegroundColor()); + } + + @Test + public void testDefaultColumnStyleWitoutCell() throws IOException { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + //Set CellStyle and RowStyle and ColumnStyle + for (int i = 0; i < 2; i++) { + sheet.createRow(i); + } + + // Create a test font and style, and use them + int obj_cnt = wb.getNumCellStyles(); + int cnt = wb.getNumCellStyles(); + + // Set Column Color : Red + sheet.setDefaultColumnStyle(3, + createColorStyle(wb, IndexedColors.RED)); + obj_cnt++; + + // Set Column Color : Red + sheet.setDefaultColumnStyle(4, + createColorStyle(wb, IndexedColors.RED)); + obj_cnt++; + + assertEquals(obj_cnt, wb.getNumCellStyles()); + + // now the color should be equal for those two columns and rows + checkColumnStyles(sheet, 3, 4, false); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + + // We should have the same style-objects for these two columns and rows + checkColumnStyles(sheet, 3, 4, true); + + // (GREEN + RED + BLUE + CORAL) + YELLOW(2*2) + assertEquals(cnt + 1, wb.getNumCellStyles()); + } + + @Test + public void testUserDefinedStylesAreNeverOptimizedAway() throws IOException { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + //Set CellStyle and RowStyle and ColumnStyle + for (int i = 0; i < 2; i++) { + sheet.createRow(i); + } + + // Create a test font and style, and use them + int obj_cnt = wb.getNumCellStyles(); + int cnt = wb.getNumCellStyles(); + for (int i = 0; i < 3; i++) { + HSSFCellStyle s = null; + if (i == 0) { + // Set cell color : +2(user style + proxy of it) + s = (HSSFCellStyle) createColorStyle(wb, + IndexedColors.YELLOW); + s.setUserStyleName("user define"); + obj_cnt += 2; + } + + HSSFRow row = sheet.getRow(1); + row.createCell(i).setCellStyle(s); + } + + // Create style. But don't use it. + for (int i = 3; i < 6; i++) { + // Set Cell Color : AQUA + createColorStyle(wb, IndexedColors.AQUA); + obj_cnt++; + } + + // Set cell color : +2(user style + proxy of it) + HSSFCellStyle s = (HSSFCellStyle) createColorStyle(wb,IndexedColors.YELLOW); + s.setUserStyleName("user define2"); + obj_cnt += 2; + + sheet.createRow(10).createCell(0).setCellStyle(s); + + assertEquals(obj_cnt, wb.getNumCellStyles()); + + // Confirm user style name + checkUserStyles(sheet); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + + // Confirm user style name + checkUserStyles(sheet); + + // (GREEN + RED + BLUE + CORAL) + YELLOW(2*2) + assertEquals(cnt + 2 * 2, wb.getNumCellStyles()); + } + + @Test + public void testBug57517() throws IOException { + HSSFWorkbook wb = new HSSFWorkbook(); + assertEquals("Usually we have 21 pre-defined styles in a newly created Workbook, see InternalWorkbook.createWorkbook()", + 21, wb.getNumCellStyles()); + + HSSFSheet sheet = wb.createSheet(); + + //Set CellStyle and RowStyle and ColumnStyle + for (int i = 0; i < 2; i++) { + sheet.createRow(i); + } + + // Create a test font and style, and use them + int obj_cnt = wb.getNumCellStyles(); + int cnt = wb.getNumCellStyles(); + for (int i = 0; i < 3; i++) { + // Set Cell Color : GREEN + HSSFRow row = sheet.getRow(0); + row.createCell(i).setCellStyle( + createColorStyle(wb, IndexedColors.GREEN)); + obj_cnt++; + + // Set Column Color : Red + sheet.setDefaultColumnStyle(i + 3, + createColorStyle(wb, IndexedColors.RED)); + obj_cnt++; + + // Set Row Color : Blue + row = sheet.createRow(i + 3); + row.setRowStyle(createColorStyle(wb, IndexedColors.BLUE)); + obj_cnt++; + + HSSFCellStyle s = null; + if (i == 0) { + // Set cell color : +2(user style + proxy of it) + s = (HSSFCellStyle) createColorStyle(wb, + IndexedColors.YELLOW); + s.setUserStyleName("user define"); + obj_cnt += 2; + } + + row = sheet.getRow(1); + row.createCell(i).setCellStyle(s); + + } + + // Create style. But don't use it. + for (int i = 3; i < 6; i++) { + // Set Cell Color : AQUA + createColorStyle(wb, IndexedColors.AQUA); + obj_cnt++; + } + + // Set CellStyle and RowStyle and ColumnStyle + for (int i = 9; i < 11; i++) { + sheet.createRow(i); + } + + //Set 0 or 255 index of ColumnStyle. + HSSFCellStyle s = (HSSFCellStyle) createColorStyle(wb, IndexedColors.CORAL); + obj_cnt++; + sheet.setDefaultColumnStyle(0, s); + sheet.setDefaultColumnStyle(255, s); + + // Create a test font and style, and use them + for (int i = 3; i < 6; i++) { + // Set Cell Color : GREEN + HSSFRow row = sheet.getRow(0 + 9); + row.createCell(i - 3).setCellStyle( + createColorStyle(wb, IndexedColors.GREEN)); + obj_cnt++; + + // Set Column Color : Red + sheet.setDefaultColumnStyle(i + 3, + createColorStyle(wb, IndexedColors.RED)); + obj_cnt++; + + // Set Row Color : Blue + row = sheet.createRow(i + 3); + row.setRowStyle(createColorStyle(wb, IndexedColors.BLUE)); + obj_cnt++; + + if (i == 3) { + // Set cell color : +2(user style + proxy of it) + s = (HSSFCellStyle) createColorStyle(wb, + IndexedColors.YELLOW); + s.setUserStyleName("user define2"); + obj_cnt += 2; + } + + row = sheet.getRow(1 + 9); + row.createCell(i - 3).setCellStyle(s); + } + + assertEquals(obj_cnt, wb.getNumCellStyles()); + + // now the color should be equal for those two columns and rows + checkColumnStyles(sheet, 3, 4, false); + checkRowStyles(sheet, 3, 4, false); + + // Confirm user style name + checkUserStyles(sheet); + +// out = new FileOutputStream(new File(tmpDirName, "out.xls")); +// wb.write(out); +// out.close(); + + // Optimise styles + HSSFOptimiser.optimiseCellStyles(wb); + +// out = new FileOutputStream(new File(tmpDirName, "out_optimised.xls")); +// wb.write(out); +// out.close(); + + // We should have the same style-objects for these two columns and rows + checkColumnStyles(sheet, 3, 4, true); + checkRowStyles(sheet, 3, 4, true); + + // Confirm user style name + checkUserStyles(sheet); + + // (GREEN + RED + BLUE + CORAL) + YELLOW(2*2) + assertEquals(cnt + 4 + 2 * 2, wb.getNumCellStyles()); + } + + private void checkUserStyles(HSSFSheet sheet) { + HSSFCellStyle parentStyle1 = sheet.getRow(1).getCell(0).getCellStyle().getParentStyle(); + assertNotNull(parentStyle1); + assertEquals(parentStyle1.getUserStyleName(), "user define"); + + HSSFCellStyle parentStyle10 = sheet.getRow(10).getCell(0).getCellStyle().getParentStyle(); + assertNotNull(parentStyle10); + assertEquals(parentStyle10.getUserStyleName(), "user define2"); + } + + private void checkColumnStyles(HSSFSheet sheet, int col1, int col2, boolean checkEquals) { + // we should have the same color for the column styles + HSSFCellStyle columnStyle1 = sheet.getColumnStyle(col1); + assertNotNull(columnStyle1); + HSSFCellStyle columnStyle2 = sheet.getColumnStyle(col2); + assertNotNull(columnStyle2); + assertEquals(columnStyle1.getFillForegroundColor(), columnStyle2.getFillForegroundColor()); + if(checkEquals) { + assertEquals(columnStyle1.getIndex(), columnStyle2.getIndex()); + assertEquals(columnStyle1, columnStyle2); + } + } + + private void checkRowStyles(HSSFSheet sheet, int row1, int row2, boolean checkEquals) { + // we should have the same color for the row styles + HSSFCellStyle rowStyle1 = sheet.getRow(row1).getRowStyle(); + assertNotNull(rowStyle1); + HSSFCellStyle rowStyle2 = sheet.getRow(row2).getRowStyle(); + assertNotNull(rowStyle2); + assertEquals(rowStyle1.getFillForegroundColor(), rowStyle2.getFillForegroundColor()); + if(checkEquals) { + assertEquals(rowStyle1.getIndex(), rowStyle2.getIndex()); + assertEquals(rowStyle1, rowStyle2); + } + } + + private CellStyle createColorStyle(Workbook wb, IndexedColors c) { + CellStyle cs = wb.createCellStyle(); + cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); + cs.setFillForegroundColor(c.getIndex()); + return cs; + } }