From: Tim Allison Date: Fri, 14 Jul 2017 14:19:21 +0000 (+0000) Subject: clean up whitespace and indents X-Git-Tag: REL_3_17_FINAL~54 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c674c92d382ec019273a9e1d09dad44f6eb99ca;p=poi.git clean up whitespace and indents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1801969 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index b6b7019411..adc07bd952 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -93,9 +93,9 @@ import org.junit.Test; /** * Testcases for bugs entered in bugzilla * the Test name contains the bugzilla bug id - * + *

* YK: If a bug can be tested in terms of common ss interfaces, - * define the test in the base class {@link BaseTestBugzillaIssues} + * define the test in the base class {@link BaseTestBugzillaIssues} */ public final class TestBugs extends BaseTestBugzillaIssues { // to not affect other tests running in the same JVM @@ -116,8 +116,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { return HSSFITestDataProvider.instance.writeOutAndReadBack(original); } - /** Test reading AND writing a complicated workbook - *Test opening resulting sheet in excel*/ + /** + * Test reading AND writing a complicated workbook + * Test opening resulting sheet in excel + */ @Test public void bug15228() throws Exception { HSSFWorkbook wb = openSample("15228.xls"); @@ -140,7 +142,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } - /** test reading of a formula with a name and a cell ref in one + /** + * test reading of a formula with a name and a cell ref in one **/ @Test public void bug14460() throws Exception { @@ -164,8 +167,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { cell.setCellValue(new HSSFRichTextString(text)); } - /** test rewriting a file with large number of unique strings - *open resulting file in Excel to check results!*/ + /** + * test rewriting a file with large number of unique strings + * open resulting file in Excel to check results! + */ @Test public void bug15375() throws Exception { HSSFWorkbook wb = openSample("15375.xls"); @@ -191,6 +196,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { writeOutAndReadBack(wb).close(); wb.close(); } + /** * test writing a file with large number of unique strings, * open resulting file in Excel to check results! @@ -200,55 +206,71 @@ public final class TestBugs extends BaseTestBugzillaIssues { bug15375(6000); } - /**Double byte strings*/ + /** + * Double byte strings + */ @Test public void bug15556() throws Exception { HSSFWorkbook wb = openSample("15556.xls"); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(45); - assertNotNull("Read row fine!" , row); + assertNotNull("Read row fine!", row); wb.close(); } - /**Double byte strings */ + /** + * Double byte strings + */ @Test public void bug22742() { openSample("22742.xls"); } - /**Double byte strings */ + /** + * Double byte strings + */ @Test public void bug12561_1() { openSample("12561-1.xls"); } - /** Double byte strings */ + /** + * Double byte strings + */ @Test public void bug12561_2() { openSample("12561-2.xls"); } - /** Double byte strings - File supplied by jubeson*/ + /** + * Double byte strings + * File supplied by jubeson + */ @Test public void bug12843_1() { openSample("12843-1.xls"); } - /** Double byte strings - File supplied by Paul Chung*/ + /** + * Double byte strings + * File supplied by Paul Chung + */ @Test public void bug12843_2() { openSample("12843-2.xls"); } - /** Reference to Name*/ + /** + * Reference to Name + */ @Test public void bug13224() { openSample("13224.xls"); } - /** Illegal argument exception - cannot store duplicate value in Map*/ + /** + * Illegal argument exception - cannot store duplicate value in Map + */ @Test public void bug19599() { openSample("19599-1.xls"); @@ -259,7 +281,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug24215() throws Exception { HSSFWorkbook wb = openSample("24215.xls"); - for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets();sheetIndex++) { + for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) { HSSFSheet sheet = wb.getSheetAt(sheetIndex); int rows = sheet.getLastRowNum(); @@ -275,7 +297,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } - /**Tests read and write of Unicode strings in formula results + /** + * Tests read and write of Unicode strings in formula results * bug and testcase submitted by Sompop Kumnoonsate * The file contains THAI unicode characters. */ @@ -334,7 +357,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { confirmSameCellText(b1, rb2); confirmSameCellText(c1, rc2); confirmSameCellText(d1, rd2); - + rw.close(); } @@ -352,30 +375,36 @@ public final class TestBugs extends BaseTestBugzillaIssues { return sb.toString(); }*/ - /** Error in opening wb*/ + /** + * Error in opening wb + */ @Test public void bug32822() { openSample("32822.xls"); } - /**fail to read wb with chart */ + /** + * fail to read wb with chart + */ @Test public void bug15573() { openSample("15573.xls"); } - /**names and macros */ + /** + * names and macros + */ @Test public void bug27852() throws Exception { HSSFWorkbook wb = openSample("27852.xls"); - for(int i = 0 ; i < wb.getNumberOfNames(); i++){ - HSSFName name = wb.getNameAt(i); - name.getNameName(); - if (name.isFunctionName()) { - continue; - } - name.getRefersToFormula(); + for (int i = 0; i < wb.getNumberOfNames(); i++) { + HSSFName name = wb.getNameAt(i); + name.getNameName(); + if (name.isFunctionName()) { + continue; + } + name.getRefersToFormula(); } wb.close(); } @@ -394,7 +423,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { } } - /** Error when reading then writing ArrayValues in NameRecord's*/ + /** + * Error when reading then writing ArrayValues in NameRecord's + */ @Test public void bug37630() throws Exception { HSSFWorkbook wb = openSample("37630.xls"); @@ -440,9 +471,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { //the first check with blank workbook HSSFWorkbook wb = openSample("Simple.xls"); HSSFSheet sheet = wb.createSheet(); - for(int i = 1; i < 400; i++) { + for (int i = 1; i < 400; i++) { HSSFRow row = sheet.getRow(i); - if(row != null) { + if (row != null) { row.getCell(0); } } @@ -469,9 +500,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFSheet sheet = wb.getSheetAt(0); int count = 0; for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) { - HSSFRow row = sheet.getRow(i); + HSSFRow row = sheet.getRow(i); if (row != null) { - HSSFCell cell = row .getCell(0); + HSSFCell cell = row.getCell(0); assertEquals(CellType.STRING, cell.getCellTypeEnum()); count++; } @@ -484,7 +515,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 29982: Unable to read spreadsheet when dropdown list cell is selected - - * Unable to construct record instance + * Unable to construct record instance */ @Test public void bug29982() throws Exception { @@ -503,7 +534,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFSheet s = wb.getSheetAt(0); s.setRowBreak(1); writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -529,18 +560,18 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 35564: HSSFCell.java: NullPtrExc in isGridsPrinted() and getProtect() - * when HSSFWorkbook is created from file + * when HSSFWorkbook is created from file */ @Test public void bug35564() throws Exception { HSSFWorkbook wb = openSample("35564.xls"); - HSSFSheet sheet = wb.getSheetAt( 0 ); + HSSFSheet sheet = wb.getSheetAt(0); assertEquals(false, sheet.isGridsPrinted()); assertEquals(false, sheet.getProtect()); writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -551,10 +582,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug35565() throws Exception { HSSFWorkbook wb = openSample("35565.xls"); - HSSFSheet sheet = wb.getSheetAt( 0 ); + HSSFSheet sheet = wb.getSheetAt(0); assertNotNull(sheet); writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -575,7 +606,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug40285() throws Exception { HSSFWorkbook wb = openSample("40285.xls"); - HSSFSheet sheet = wb.getSheetAt( 0 ); + HSSFSheet sheet = wb.getSheetAt(0); int rownum = 0; for (Iterator it = sheet.rowIterator(); it.hasNext(); rownum++) { Row row = it.next(); @@ -591,7 +622,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Test bug 38266: NPE when adding a row break - * + *

* User's diagnosis: * 1. Manually (i.e., not using POI) create an Excel Workbook, making sure it * contains a sheet that doesn't have any row breaks @@ -605,13 +636,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { for (String file : files) { HSSFWorkbook wb = openSample(file); - HSSFSheet sheet = wb.getSheetAt( 0 ); + HSSFSheet sheet = wb.getSheetAt(0); int[] breaks = sheet.getRowBreaks(); assertEquals(0, breaks.length); //add 3 row breaks for (int j = 1; j <= 3; j++) { - sheet.setRowBreak(j*20); + sheet.setRowBreak(j * 20); } wb.close(); } @@ -670,7 +701,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 41546: Constructing HSSFWorkbook is failed, - * Unknown Ptg in Formula: 0x1a (26) + * Unknown Ptg in Formula: 0x1a (26) */ @Test public void bug41546() throws Exception { @@ -684,7 +715,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 42564: Some files from Access were giving a RecordFormatException - * when reading the BOFRecord + * when reading the BOFRecord */ @Test public void bug42564() throws Exception { @@ -695,8 +726,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 42564: Some files from Access also have issues - * with the NameRecord, once you get past the BOFRecord - * issue. + * with the NameRecord, once you get past the BOFRecord + * issue. */ @Test public void bug42564Alt() throws Exception { @@ -707,7 +738,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 42618: RecordFormatException reading a file containing - * =CHOOSE(2,A2,A3,A4) + * =CHOOSE(2,A2,A3,A4) */ @Test public void bug42618() throws Exception { @@ -725,13 +756,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Formula Value HSSFRow r2 = s.getRow(1); HSSFCell c2 = r2.getCell(1); - assertEquals(25, (int)c2.getNumericCellValue()); + assertEquals(25, (int) c2.getNumericCellValue()); try { assertEquals("CHOOSE(2,A2,A3,A4)", c2.getCellFormula()); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Too few arguments") - && e.getMessage().indexOf("ConcatPtg") > 0) { + && e.getMessage().indexOf("ConcatPtg") > 0) { fail("identified bug 44306"); } } @@ -752,7 +783,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Crystal reports generates files with short - * StyleRecords, which is against the spec + * StyleRecords, which is against the spec */ @Test public void bug44471() throws Exception { @@ -765,7 +796,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Files with "read only recommended" were giving - * grief on the FileSharingRecord + * grief on the FileSharingRecord */ @Test public void bug44536() throws Exception { @@ -786,7 +817,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Some files were having problems with the DVRecord, - * probably due to dropdowns + * probably due to dropdowns */ @Test public void bug44593() throws Exception { @@ -801,7 +832,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Used to give problems due to trying to read a zero - * length string, but that's now properly handled + * length string, but that's now properly handled */ @Test public void bug44643() throws Exception { @@ -813,7 +844,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * User reported the wrong number of rows from the - * iterator, but we can't replicate that + * iterator, but we can't replicate that */ @Test public void bug44693() throws Exception { @@ -827,7 +858,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Now check the iterator int rowsSeen = 0; - for(Iterator i = s.rowIterator(); i.hasNext(); ) { + for (Iterator i = s.rowIterator(); i.hasNext(); ) { Row r = i.next(); assertNotNull(r); rowsSeen++; @@ -850,7 +881,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Had a problem apparently, not sure what as it - * works just fine... + * works just fine... */ @Test public void bug44891() throws Exception { @@ -863,7 +894,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Bug 44235: Ms Excel can't open save as excel file - * + *

* Works fine with poi-3.1-beta1. */ @Test @@ -895,9 +926,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Problems with extracting check boxes from - * HSSFObjectData + * HSSFObjectData */ - @Test(expected=FileNotFoundException.class) + @Test(expected = FileNotFoundException.class) public void bug44840() throws Exception { HSSFWorkbook wb = openSample("WithCheckBoxes.xls"); @@ -932,8 +963,8 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Test that we can delete sheets without - * breaking the build in named ranges - * used for printing stuff. + * breaking the build in named ranges + * used for printing stuff. */ @Test public void bug30978() throws Exception { @@ -967,7 +998,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { } private void assertNames(HSSFWorkbook wb1, InternalWorkbook w) { - for(int i=0; i it = ns.getSheet().getCellValueIterator(); it.hasNext(); i++) { CellValueRecordInterface cvr = it.next(); - if(cvr instanceof FormulaRecordAggregate) { - FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr; + if (cvr instanceof FormulaRecordAggregate) { + FormulaRecordAggregate fr = (FormulaRecordAggregate) cvr; - if(i == 0) { + if (i == 0) { assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001); assertNull(fr.getStringRecord()); } else if (i == 1) { @@ -1161,6 +1192,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(CellType.NUMERIC, cell.getCachedFormulaResultTypeEnum()); assertEquals(expectedValue, cell.getNumericCellValue(), 0.0); } + private static void confirmCachedValue(String expectedValue, HSSFCell cell) { assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.STRING, cell.getCachedFormulaResultTypeEnum()); @@ -1169,14 +1201,14 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Problem with "Vector Rows", eg a whole - * column which is set to the result of - * {=sin(B1:B9)}(9,1), so that each cell is - * shown to have the contents - * {=sin(B1:B9){9,1)[rownum][0] + * column which is set to the result of + * {=sin(B1:B9)}(9,1), so that each cell is + * shown to have the contents + * {=sin(B1:B9){9,1)[rownum][0] * In this sample file, the vector column - * is C, and the data column is B. - * - * Expected ExpPtg to be converted from Shared to Non-Shared... + * is C, and the data column is B. + *

+ * Expected ExpPtg to be converted from Shared to Non-Shared... */ @Ignore("For now, blows up with an exception from ExtPtg") @Test @@ -1211,7 +1243,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * People are all getting confused about the last - * row and cell number + * row and cell number */ @Test public void bug30635() throws IOException { @@ -1257,7 +1289,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(0, r.getFirstCellNum()); assertEquals(5, r.getLastCellNum()); // last cell # + 1 assertEquals(3, r.getPhysicalNumberOfCells()); - + wb.close(); } @@ -1301,13 +1333,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug45322() throws Exception { HSSFWorkbook wb = openSample("44958.xls"); HSSFSheet sh = wb.getSheetAt(0); - for(short i=0; i < 30; i++) sh.autoSizeColumn(i); + for (short i = 0; i < 30; i++) sh.autoSizeColumn(i); wb.close(); - } + } /** * We used to add too many UncalcRecords to sheets - * with diagrams on. Don't any more + * with diagrams on. Don't any more */ @Test public void bug45414() throws Exception { @@ -1406,7 +1438,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // footer can be more than 256 bytes s.getFooter().setCenter(s250); // 256 bytes required s.getFooter().setCenter(s251); // 257 bytes required - + wb.close(); } @@ -1422,7 +1454,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } - /** + /** * Cell background colours */ @Test @@ -1485,7 +1517,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * In POI-2.5 user reported exception when parsing a name with a custom VBA function: - * =MY_VBA_FUNCTION("lskdjflsk") + * =MY_VBA_FUNCTION("lskdjflsk") */ @Test public void bug30070() throws Exception { @@ -1508,17 +1540,16 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * The link formulas which is referring to other books cannot be taken (the bug existed prior to POI-3.2) * Expected: - * + *

* [link_sub.xls]Sheet1!$A$1 * [link_sub.xls]Sheet1!$A$2 * [link_sub.xls]Sheet1!$A$3 - * + *

* POI-3.1 output: - * + *

* Sheet1!$A$1 * Sheet1!$A$2 * Sheet1!$A$3 - * */ @Test public void bug27364() throws Exception { @@ -1596,7 +1627,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFITestDataProvider.instance.openWorkbookStream("46904.xls")); new HSSFWorkbook(fs.getRoot(), false).close(); fail("Should catch exception here"); - } catch(OldExcelFormatException e) { + } catch (OldExcelFormatException e) { assertTrue(e.getMessage().startsWith( "The supplied spreadsheet seems to be Excel" )); @@ -1606,11 +1637,11 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFITestDataProvider.instance.openWorkbookStream("46904.xls")); try { new HSSFWorkbook(fs.getRoot(), false).close(); - fail("Should catch exception here"); + fail("Should catch exception here"); } finally { fs.close(); } - } catch(OldExcelFormatException e) { + } catch (OldExcelFormatException e) { assertTrue(e.getMessage().startsWith( "The supplied spreadsheet seems to be Excel" )); @@ -1619,7 +1650,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * java.lang.NegativeArraySizeException reading long - * non-unicode data for a name record + * non-unicode data for a name record */ @Test public void bug47034() throws Exception { @@ -1636,7 +1667,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void bug46368() throws Exception { HSSFWorkbook wb = openSample("46368.xls"); - HSSFSheet s = wb.getSheetAt(0); + HSSFSheet s = wb.getSheetAt(0); HSSFCell cell1 = s.getRow(0).getCell(0); assertEquals(32770, cell1.getStringCellValue().length()); @@ -1652,7 +1683,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug48180() throws Exception { HSSFWorkbook wb = openSample("48180.xls"); - HSSFSheet s = wb.getSheetAt(0); + HSSFSheet s = wb.getSheetAt(0); HSSFCell cell1 = s.getRow(0).getCell(0); assertEquals("test ", cell1.getStringCellValue()); @@ -1688,211 +1719,211 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug47847() throws Exception { - HSSFWorkbook wb1 = openSample("47847.xls"); - assertEquals(3, wb1.getNumberOfSheets()); + HSSFWorkbook wb1 = openSample("47847.xls"); + assertEquals(3, wb1.getNumberOfSheets()); - // Find the SST record - UnicodeString withExt = wb1.getWorkbook().getSSTString(0); - UnicodeString withoutExt = wb1.getWorkbook().getSSTString(31); + // Find the SST record + UnicodeString withExt = wb1.getWorkbook().getSSTString(0); + UnicodeString withoutExt = wb1.getWorkbook().getSSTString(31); - assertEquals("O:Alloc:Qty", withExt.getString()); - assertTrue((withExt.getOptionFlags() & 0x0004) == 0x0004); + assertEquals("O:Alloc:Qty", withExt.getString()); + assertTrue((withExt.getOptionFlags() & 0x0004) == 0x0004); - assertEquals("RT", withoutExt.getString()); - assertTrue((withoutExt.getOptionFlags() & 0x0004) == 0x0000); + assertEquals("RT", withoutExt.getString()); + assertTrue((withoutExt.getOptionFlags() & 0x0004) == 0x0000); - // Something about continues... + // Something about continues... - // Write out and re-read - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - assertEquals(3, wb2.getNumberOfSheets()); + // Write out and re-read + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + assertEquals(3, wb2.getNumberOfSheets()); - // Check it's the same now - withExt = wb2.getWorkbook().getSSTString(0); - withoutExt = wb2.getWorkbook().getSSTString(31); + // Check it's the same now + withExt = wb2.getWorkbook().getSSTString(0); + withoutExt = wb2.getWorkbook().getSSTString(31); - assertEquals("O:Alloc:Qty", withExt.getString()); - assertTrue((withExt.getOptionFlags() & 0x0004) == 0x0004); + assertEquals("O:Alloc:Qty", withExt.getString()); + assertTrue((withExt.getOptionFlags() & 0x0004) == 0x0004); - assertEquals("RT", withoutExt.getString()); - assertTrue((withoutExt.getOptionFlags() & 0x0004) == 0x0000); - wb2.close(); + assertEquals("RT", withoutExt.getString()); + assertTrue((withoutExt.getOptionFlags() & 0x0004) == 0x0000); + wb2.close(); } /** * Problem with cloning a sheet with a chart - * contained in it. + * contained in it. */ @Test public void bug49096() throws Exception { - HSSFWorkbook wb1 = openSample("49096.xls"); - assertEquals(1, wb1.getNumberOfSheets()); + HSSFWorkbook wb1 = openSample("49096.xls"); + assertEquals(1, wb1.getNumberOfSheets()); - assertNotNull(wb1.getSheetAt(0)); - wb1.cloneSheet(0); - assertEquals(2, wb1.getNumberOfSheets()); + assertNotNull(wb1.getSheetAt(0)); + wb1.cloneSheet(0); + assertEquals(2, wb1.getNumberOfSheets()); - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - assertEquals(2, wb2.getNumberOfSheets()); - wb2.close(); + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + assertEquals(2, wb2.getNumberOfSheets()); + wb2.close(); } /** * Newly created sheets need to get a - * proper TabID, otherwise print setup - * gets confused on them. + * proper TabID, otherwise print setup + * gets confused on them. * Also ensure that print setup refs are - * by reference not value + * by reference not value */ @Test public void bug46664() throws Exception { - HSSFWorkbook wb1 = new HSSFWorkbook(); - HSSFSheet sheet = wb1.createSheet("new_sheet"); - HSSFRow row = sheet.createRow((short)0); - row.createCell(0).setCellValue(new HSSFRichTextString("Column A")); - row.createCell(1).setCellValue(new HSSFRichTextString("Column B")); - row.createCell(2).setCellValue(new HSSFRichTextString("Column C")); - row.createCell(3).setCellValue(new HSSFRichTextString("Column D")); - row.createCell(4).setCellValue(new HSSFRichTextString("Column E")); - row.createCell(5).setCellValue(new HSSFRichTextString("Column F")); - - //set print area from column a to column c (on first row) - wb1.setPrintArea( - 0, //sheet index - 0, //start column - 2, //end column - 0, //start row - 0 //end row - ); - - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - - // Ensure the tab index - TabIdRecord tr = null; - for(Record r : wb2.getWorkbook().getRecords()) { - if(r instanceof TabIdRecord) { - tr = (TabIdRecord)r; - } - } - assertNotNull(tr); - assertEquals(1, tr._tabids.length); - assertEquals(0, tr._tabids[0]); - - // Ensure the print setup - assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0)); + HSSFWorkbook wb1 = new HSSFWorkbook(); + HSSFSheet sheet = wb1.createSheet("new_sheet"); + HSSFRow row = sheet.createRow((short) 0); + row.createCell(0).setCellValue(new HSSFRichTextString("Column A")); + row.createCell(1).setCellValue(new HSSFRichTextString("Column B")); + row.createCell(2).setCellValue(new HSSFRichTextString("Column C")); + row.createCell(3).setCellValue(new HSSFRichTextString("Column D")); + row.createCell(4).setCellValue(new HSSFRichTextString("Column E")); + row.createCell(5).setCellValue(new HSSFRichTextString("Column F")); + + //set print area from column a to column c (on first row) + wb1.setPrintArea( + 0, //sheet index + 0, //start column + 2, //end column + 0, //start row + 0 //end row + ); + + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + + // Ensure the tab index + TabIdRecord tr = null; + for (Record r : wb2.getWorkbook().getRecords()) { + if (r instanceof TabIdRecord) { + tr = (TabIdRecord) r; + } + } + assertNotNull(tr); + assertEquals(1, tr._tabids.length); + assertEquals(0, tr._tabids[0]); + + // Ensure the print setup + assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0)); HSSFName printArea = wb2.getName("Print_Area"); assertNotNull(printArea); assertEquals("new_sheet!$A$1:$C$1", printArea.getRefersToFormula()); - // Needs reference not value - NameRecord nr = wb2.getWorkbook().getNameRecord( - wb2.getNameIndex("Print_Area") - ); - assertEquals("Print_Area", nr.getNameText()); - assertEquals(1, nr.getNameDefinition().length); - assertEquals( - "new_sheet!$A$1:$C$1", - ((Area3DPtg)nr.getNameDefinition()[0]).toFormulaString(HSSFEvaluationWorkbook.create(wb2)) - ); - assertEquals('R', nr.getNameDefinition()[0].getRVAType()); - wb2.close(); + // Needs reference not value + NameRecord nr = wb2.getWorkbook().getNameRecord( + wb2.getNameIndex("Print_Area") + ); + assertEquals("Print_Area", nr.getNameText()); + assertEquals(1, nr.getNameDefinition().length); + assertEquals( + "new_sheet!$A$1:$C$1", + ((Area3DPtg) nr.getNameDefinition()[0]).toFormulaString(HSSFEvaluationWorkbook.create(wb2)) + ); + assertEquals('R', nr.getNameDefinition()[0].getRVAType()); + wb2.close(); } /** * Problems with formula references to - * sheets via URLs + * sheets via URLs */ @Test public void bug45970() throws Exception { - HSSFWorkbook wb1 = openSample("FormulaRefs.xls"); - assertEquals(3, wb1.getNumberOfSheets()); - - HSSFSheet s = wb1.getSheetAt(0); - HSSFRow row; - - row = s.getRow(0); - assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(1); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("B1", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(2); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(3); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(4); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - // Link our new workbook - Workbook externalWb1 = new HSSFWorkbook(); - externalWb1.createSheet("Sheet1"); - wb1.linkExternalWorkbook("$http://gagravarr.org/FormulaRefs2.xls", externalWb1); - - // Change 4 - row.getCell(1).setCellFormula("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2"); - row.getCell(1).setCellValue(123.0); - - // Link our new workbook - Workbook externalWb2 = new HSSFWorkbook(); - externalWb2.createSheet("Sheet1"); - wb1.linkExternalWorkbook("$http://example.com/FormulaRefs.xls", externalWb2); - - // Add 5 - row = s.createRow(5); - row.createCell(1, CellType.FORMULA); - row.getCell(1).setCellFormula("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1"); - row.getCell(1).setCellValue(234.0); - - // Re-test - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - s = wb2.getSheetAt(0); - - row = s.getRow(0); - assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(),0); - - row = s.getRow(1); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("B1", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(2); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(3); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); - assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(4); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula()); - assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0); - - row = s.getRow(5); - assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); - assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); - assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0); - - wb2.close(); + HSSFWorkbook wb1 = openSample("FormulaRefs.xls"); + assertEquals(3, wb1.getNumberOfSheets()); + + HSSFSheet s = wb1.getSheetAt(0); + HSSFRow row; + + row = s.getRow(0); + assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(1); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("B1", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(2); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(3); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(4); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("'[$http://gagravarr.org/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + // Link our new workbook + Workbook externalWb1 = new HSSFWorkbook(); + externalWb1.createSheet("Sheet1"); + wb1.linkExternalWorkbook("$http://gagravarr.org/FormulaRefs2.xls", externalWb1); + + // Change 4 + row.getCell(1).setCellFormula("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2"); + row.getCell(1).setCellValue(123.0); + + // Link our new workbook + Workbook externalWb2 = new HSSFWorkbook(); + externalWb2.createSheet("Sheet1"); + wb1.linkExternalWorkbook("$http://example.com/FormulaRefs.xls", externalWb2); + + // Add 5 + row = s.createRow(5); + row.createCell(1, CellType.FORMULA); + row.getCell(1).setCellFormula("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1"); + row.getCell(1).setCellValue(234.0); + + // Re-test + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + s = wb2.getSheetAt(0); + + row = s.getRow(0); + assertEquals(CellType.NUMERIC, row.getCell(1).getCellTypeEnum()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(1); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("B1", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(2); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("Sheet1!B1", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(3); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("[Formulas2.xls]Sheet1!B2", row.getCell(1).getCellFormula()); + assertEquals(112.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(4); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("'[$http://gagravarr.org/FormulaRefs2.xls]Sheet1'!B2", row.getCell(1).getCellFormula()); + assertEquals(123.0, row.getCell(1).getNumericCellValue(), 0); + + row = s.getRow(5); + assertEquals(CellType.FORMULA, row.getCell(1).getCellTypeEnum()); + assertEquals("'[$http://example.com/FormulaRefs.xls]Sheet1'!B1", row.getCell(1).getCellFormula()); + assertEquals(234.0, row.getCell(1).getNumericCellValue(), 0); + + wb2.close(); } /** @@ -1934,39 +1965,39 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug49524() throws Exception { - HSSFWorkbook wb1 = openSample("49524.xls"); - Sheet s = wb1.getSheetAt(0); - Row r = s.getRow(0); - Cell rotated = r.getCell(0); - Cell normal = r.getCell(1); - - // Check the current ones - assertEquals(0, normal.getCellStyle().getRotation()); - assertEquals(0xff, rotated.getCellStyle().getRotation()); - - // Add a new style, also rotated - CellStyle cs = wb1.createCellStyle(); - cs.setRotation((short)0xff); - Cell nc = r.createCell(2); - nc.setCellValue("New Rotated Text"); - nc.setCellStyle(cs); - assertEquals(0xff, nc.getCellStyle().getRotation()); - - // Write out and read back - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - - // Re-check - s = wb2.getSheetAt(0); - r = s.getRow(0); - rotated = r.getCell(0); - normal = r.getCell(1); - nc = r.getCell(2); - - assertEquals(0, normal.getCellStyle().getRotation()); - assertEquals(0xff, rotated.getCellStyle().getRotation()); - assertEquals(0xff, nc.getCellStyle().getRotation()); - wb2.close(); + HSSFWorkbook wb1 = openSample("49524.xls"); + Sheet s = wb1.getSheetAt(0); + Row r = s.getRow(0); + Cell rotated = r.getCell(0); + Cell normal = r.getCell(1); + + // Check the current ones + assertEquals(0, normal.getCellStyle().getRotation()); + assertEquals(0xff, rotated.getCellStyle().getRotation()); + + // Add a new style, also rotated + CellStyle cs = wb1.createCellStyle(); + cs.setRotation((short) 0xff); + Cell nc = r.createCell(2); + nc.setCellValue("New Rotated Text"); + nc.setCellStyle(cs); + assertEquals(0xff, nc.getCellStyle().getRotation()); + + // Write out and read back + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + + // Re-check + s = wb2.getSheetAt(0); + r = s.getRow(0); + rotated = r.getCell(0); + normal = r.getCell(1); + nc = r.getCell(2); + + assertEquals(0, normal.getCellStyle().getRotation()); + assertEquals(0xff, rotated.getCellStyle().getRotation()); + assertEquals(0xff, nc.getCellStyle().getRotation()); + wb2.close(); } /** @@ -1974,37 +2005,37 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug49689() throws Exception { - HSSFWorkbook wb1 = new HSSFWorkbook(); - HSSFSheet s = wb1.createSheet("Test"); - HSSFRow r = s.createRow(0); - HSSFCell c = r.createCell(0); + HSSFWorkbook wb1 = new HSSFWorkbook(); + HSSFSheet s = wb1.createSheet("Test"); + HSSFRow r = s.createRow(0); + HSSFCell c = r.createCell(0); - HSSFCellStyle cs1 = wb1.createCellStyle(); - HSSFCellStyle cs2 = wb1.createCellStyle(); - HSSFCellStyle cs3 = wb1.createCellStyle(); + HSSFCellStyle cs1 = wb1.createCellStyle(); + HSSFCellStyle cs2 = wb1.createCellStyle(); + HSSFCellStyle cs3 = wb1.createCellStyle(); - assertEquals(21, cs1.getIndex()); - cs1.setUserStyleName("Testing"); + assertEquals(21, cs1.getIndex()); + cs1.setUserStyleName("Testing"); - assertEquals(22, cs2.getIndex()); - cs2.setUserStyleName("Testing 2"); + assertEquals(22, cs2.getIndex()); + cs2.setUserStyleName("Testing 2"); - assertEquals(23, cs3.getIndex()); - cs3.setUserStyleName("Testing 3"); + assertEquals(23, cs3.getIndex()); + cs3.setUserStyleName("Testing 3"); - // Set one - c.setCellStyle(cs1); + // Set one + c.setCellStyle(cs1); - // Write out and read back - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); + // Write out and read back + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); - // Re-check - assertEquals("Testing", wb2.getCellStyleAt((short)21).getUserStyleName()); - assertEquals("Testing 2", wb2.getCellStyleAt((short)22).getUserStyleName()); - assertEquals("Testing 3", wb2.getCellStyleAt((short)23).getUserStyleName()); - - wb2.close(); + // Re-check + assertEquals("Testing", wb2.getCellStyleAt((short) 21).getUserStyleName()); + assertEquals("Testing 2", wb2.getCellStyleAt((short) 22).getUserStyleName()); + assertEquals("Testing 3", wb2.getCellStyleAt((short) 23).getUserStyleName()); + + wb2.close(); } @Test @@ -2037,10 +2068,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug49931() throws Exception { - HSSFWorkbook wb = openSample("49931.xls"); - assertEquals(1, wb.getNumberOfSheets()); - assertEquals("Foo", wb.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().toString()); - wb.close(); + HSSFWorkbook wb = openSample("49931.xls"); + assertEquals(1, wb.getNumberOfSheets()); + assertEquals("Foo", wb.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().toString()); + wb.close(); } /** @@ -2048,19 +2079,19 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug48325() throws Exception { - HSSFWorkbook wb = openSample("48325.xls"); - HSSFSheet sh = wb.getSheetAt(0); - HSSFFooter f = sh.getFooter(); + HSSFWorkbook wb = openSample("48325.xls"); + HSSFSheet sh = wb.getSheetAt(0); + HSSFFooter f = sh.getFooter(); - // Will show as the center, as that is what excel does - // with an invalid footer lacking left/right/center details - assertEquals("Left text should be empty", "", f.getLeft()); - assertEquals("Right text should be empty", "", f.getRight()); - assertEquals( - "Center text should contain the illegal value", - "BlahBlah blah blah ", f.getCenter() - ); - wb.close(); + // Will show as the center, as that is what excel does + // with an invalid footer lacking left/right/center details + assertEquals("Left text should be empty", "", f.getLeft()); + assertEquals("Right text should be empty", "", f.getRight()); + assertEquals( + "Center text should contain the illegal value", + "BlahBlah blah blah ", f.getCenter() + ); + wb.close(); } /** @@ -2068,16 +2099,16 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug50020() throws Exception { - HSSFWorkbook wb = openSample("50020.xls"); - writeOutAndReadBack(wb).close(); - wb.close(); + HSSFWorkbook wb = openSample("50020.xls"); + writeOutAndReadBack(wb).close(); + wb.close(); } @Test public void bug50426() throws Exception { - HSSFWorkbook wb = openSample("50426.xls"); - writeOutAndReadBack(wb).close(); - wb.close(); + HSSFWorkbook wb = openSample("50426.xls"); + writeOutAndReadBack(wb).close(); + wb.close(); } /** @@ -2085,129 +2116,129 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug50416LastRowNumber() throws IOException { - // Create the workbook with 1 sheet which contains 3 rows - HSSFWorkbook workbook = new HSSFWorkbook(); - Sheet sheet = workbook.createSheet("Bug50416"); - Row row1 = sheet.createRow(0); - Cell cellA_1 = row1.createCell(0,CellType.STRING); - cellA_1.setCellValue("Cell A,1"); - Row row2 = sheet.createRow(1); - Cell cellA_2 = row2.createCell(0,CellType.STRING); - cellA_2.setCellValue("Cell A,2"); - Row row3 = sheet.createRow(2); - Cell cellA_3 = row3.createCell(0,CellType.STRING); - cellA_3.setCellValue("Cell A,3"); - - // Test the last Row number it currently correct - assertEquals(2, sheet.getLastRowNum()); - - // Shift the first row to the end - sheet.shiftRows(0, 0, 3); - assertEquals(3, sheet.getLastRowNum()); - assertEquals(-1, sheet.getRow(0).getLastCellNum()); - assertEquals("Cell A,2", sheet.getRow(1).getCell(0).getStringCellValue()); - assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); - assertEquals("Cell A,1", sheet.getRow(3).getCell(0).getStringCellValue()); - - // Shift the 2nd row up to the first one - sheet.shiftRows(1, 1, -1); - assertEquals(3, sheet.getLastRowNum()); - assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); - assertEquals(-1, sheet.getRow(1).getLastCellNum()); - assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); - assertEquals("Cell A,1", sheet.getRow(3).getCell(0).getStringCellValue()); - - // Shift the 4th row up into the gap in the 3rd row - sheet.shiftRows(3, 3, -2); - assertEquals(2, sheet.getLastRowNum()); - assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); - assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue()); - assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); - assertEquals(-1, sheet.getRow(3).getLastCellNum()); - - // Now zap the empty 4th row - won't do anything - sheet.removeRow(sheet.getRow(3)); - - // Test again the last row number which should be 2 - assertEquals(2, sheet.getLastRowNum()); - assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); - assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue()); - assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); - - workbook.close(); + // Create the workbook with 1 sheet which contains 3 rows + HSSFWorkbook workbook = new HSSFWorkbook(); + Sheet sheet = workbook.createSheet("Bug50416"); + Row row1 = sheet.createRow(0); + Cell cellA_1 = row1.createCell(0, CellType.STRING); + cellA_1.setCellValue("Cell A,1"); + Row row2 = sheet.createRow(1); + Cell cellA_2 = row2.createCell(0, CellType.STRING); + cellA_2.setCellValue("Cell A,2"); + Row row3 = sheet.createRow(2); + Cell cellA_3 = row3.createCell(0, CellType.STRING); + cellA_3.setCellValue("Cell A,3"); + + // Test the last Row number it currently correct + assertEquals(2, sheet.getLastRowNum()); + + // Shift the first row to the end + sheet.shiftRows(0, 0, 3); + assertEquals(3, sheet.getLastRowNum()); + assertEquals(-1, sheet.getRow(0).getLastCellNum()); + assertEquals("Cell A,2", sheet.getRow(1).getCell(0).getStringCellValue()); + assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); + assertEquals("Cell A,1", sheet.getRow(3).getCell(0).getStringCellValue()); + + // Shift the 2nd row up to the first one + sheet.shiftRows(1, 1, -1); + assertEquals(3, sheet.getLastRowNum()); + assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); + assertEquals(-1, sheet.getRow(1).getLastCellNum()); + assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); + assertEquals("Cell A,1", sheet.getRow(3).getCell(0).getStringCellValue()); + + // Shift the 4th row up into the gap in the 3rd row + sheet.shiftRows(3, 3, -2); + assertEquals(2, sheet.getLastRowNum()); + assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); + assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue()); + assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); + assertEquals(-1, sheet.getRow(3).getLastCellNum()); + + // Now zap the empty 4th row - won't do anything + sheet.removeRow(sheet.getRow(3)); + + // Test again the last row number which should be 2 + assertEquals(2, sheet.getLastRowNum()); + assertEquals("Cell A,2", sheet.getRow(0).getCell(0).getStringCellValue()); + assertEquals("Cell A,1", sheet.getRow(1).getCell(0).getStringCellValue()); + assertEquals("Cell A,3", sheet.getRow(2).getCell(0).getStringCellValue()); + + workbook.close(); } /** * If you send a file between Excel and OpenOffice enough, something - * will turn the "General" format into "GENERAL" + * will turn the "General" format into "GENERAL" */ @Test public void bug50756() throws Exception { - HSSFWorkbook wb = openSample("50756.xls"); - HSSFSheet s = wb.getSheetAt(0); - HSSFRow r17 = s.getRow(16); - HSSFRow r18 = s.getRow(17); - HSSFDataFormatter df = new HSSFDataFormatter(); - - assertEquals(10.0, r17.getCell(1).getNumericCellValue(), 0); - assertEquals(20.0, r17.getCell(2).getNumericCellValue(), 0); - assertEquals(20.0, r17.getCell(3).getNumericCellValue(), 0); - assertEquals("GENERAL", r17.getCell(1).getCellStyle().getDataFormatString()); - assertEquals("GENERAL", r17.getCell(2).getCellStyle().getDataFormatString()); - assertEquals("GENERAL", r17.getCell(3).getCellStyle().getDataFormatString()); - assertEquals("10", df.formatCellValue(r17.getCell(1))); - assertEquals("20", df.formatCellValue(r17.getCell(2))); - assertEquals("20", df.formatCellValue(r17.getCell(3))); - - assertEquals(16.0, r18.getCell(1).getNumericCellValue(), 0); - assertEquals(35.0, r18.getCell(2).getNumericCellValue(), 0); - assertEquals(123.0, r18.getCell(3).getNumericCellValue(), 0); - assertEquals("GENERAL", r18.getCell(1).getCellStyle().getDataFormatString()); - assertEquals("GENERAL", r18.getCell(2).getCellStyle().getDataFormatString()); - assertEquals("GENERAL", r18.getCell(3).getCellStyle().getDataFormatString()); - assertEquals("16", df.formatCellValue(r18.getCell(1))); - assertEquals("35", df.formatCellValue(r18.getCell(2))); - assertEquals("123", df.formatCellValue(r18.getCell(3))); - wb.close(); + HSSFWorkbook wb = openSample("50756.xls"); + HSSFSheet s = wb.getSheetAt(0); + HSSFRow r17 = s.getRow(16); + HSSFRow r18 = s.getRow(17); + HSSFDataFormatter df = new HSSFDataFormatter(); + + assertEquals(10.0, r17.getCell(1).getNumericCellValue(), 0); + assertEquals(20.0, r17.getCell(2).getNumericCellValue(), 0); + assertEquals(20.0, r17.getCell(3).getNumericCellValue(), 0); + assertEquals("GENERAL", r17.getCell(1).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r17.getCell(2).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r17.getCell(3).getCellStyle().getDataFormatString()); + assertEquals("10", df.formatCellValue(r17.getCell(1))); + assertEquals("20", df.formatCellValue(r17.getCell(2))); + assertEquals("20", df.formatCellValue(r17.getCell(3))); + + assertEquals(16.0, r18.getCell(1).getNumericCellValue(), 0); + assertEquals(35.0, r18.getCell(2).getNumericCellValue(), 0); + assertEquals(123.0, r18.getCell(3).getNumericCellValue(), 0); + assertEquals("GENERAL", r18.getCell(1).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r18.getCell(2).getCellStyle().getDataFormatString()); + assertEquals("GENERAL", r18.getCell(3).getCellStyle().getDataFormatString()); + assertEquals("16", df.formatCellValue(r18.getCell(1))); + assertEquals("35", df.formatCellValue(r18.getCell(2))); + assertEquals("123", df.formatCellValue(r18.getCell(3))); + wb.close(); } /** * A protected sheet with comments, when written out by - * POI, ends up upsetting excel. + * POI, ends up upsetting excel. * TODO Identify the cause and add extra asserts for - * the bit excel cares about + * the bit excel cares about */ @Test public void bug50833() throws Exception { - Biff8EncryptionKey.setCurrentUserPassword(null); + Biff8EncryptionKey.setCurrentUserPassword(null); - HSSFWorkbook wb1 = openSample("50833.xls"); - HSSFSheet s = wb1.getSheetAt(0); - assertEquals("Sheet1", s.getSheetName()); - assertEquals(false, s.getProtect()); + HSSFWorkbook wb1 = openSample("50833.xls"); + HSSFSheet s = wb1.getSheetAt(0); + assertEquals("Sheet1", s.getSheetName()); + assertEquals(false, s.getProtect()); - HSSFCell c = s.getRow(0).getCell(0); - assertEquals("test cell value", c.getRichStringCellValue().getString()); + HSSFCell c = s.getRow(0).getCell(0); + assertEquals("test cell value", c.getRichStringCellValue().getString()); - HSSFComment cmt = c.getCellComment(); - assertNotNull(cmt); - assertEquals("Robert Lawrence", cmt.getAuthor()); - assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); + HSSFComment cmt = c.getCellComment(); + assertNotNull(cmt); + assertEquals("Robert Lawrence", cmt.getAuthor()); + assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); - // Reload - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - s = wb2.getSheetAt(0); - c = s.getRow(0).getCell(0); + // Reload + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + s = wb2.getSheetAt(0); + c = s.getRow(0).getCell(0); - // Re-check the comment - cmt = c.getCellComment(); - assertNotNull(cmt); - assertEquals("Robert Lawrence", cmt.getAuthor()); - assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); + // Re-check the comment + cmt = c.getCellComment(); + assertNotNull(cmt); + assertEquals("Robert Lawrence", cmt.getAuthor()); + assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); - // TODO Identify what excel doesn't like, and check for that - wb2.close(); + // TODO Identify what excel doesn't like, and check for that + wb2.close(); } @Test @@ -2223,21 +2254,21 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * The spec says that ChartEndObjectRecord has 6 reserved - * bytes on the end, but we sometimes find files without... + * bytes on the end, but we sometimes find files without... */ @Test public void bug50939() throws Exception { - HSSFWorkbook wb = openSample("50939.xls"); - assertEquals(2, wb.getNumberOfSheets()); - wb.close(); + HSSFWorkbook wb = openSample("50939.xls"); + assertEquals(2, wb.getNumberOfSheets()); + wb.close(); } @Test public void bug49219() throws Exception { - HSSFWorkbook wb = openSample("49219.xls"); - assertEquals(1, wb.getNumberOfSheets()); - assertEquals("DGATE", wb.getSheetAt(0).getRow(1).getCell(0).getStringCellValue()); - wb.close(); + HSSFWorkbook wb = openSample("49219.xls"); + assertEquals(1, wb.getNumberOfSheets()); + assertEquals("DGATE", wb.getSheetAt(0).getRow(1).getCell(0).getStringCellValue()); + wb.close(); } @Test @@ -2245,88 +2276,88 @@ public final class TestBugs extends BaseTestBugzillaIssues { TimeZone userTimeZone = LocaleUtil.getUserTimeZone(); LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET")); try { - HSSFWorkbook wb = openSample("48968.xls"); - assertEquals(1, wb.getNumberOfSheets()); - - DataFormatter fmt = new DataFormatter(); - - // Check the dates - HSSFSheet s = wb.getSheetAt(0); - Cell cell_d20110325 = s.getRow(0).getCell(0); - Cell cell_d19000102 = s.getRow(11).getCell(0); - Cell cell_d19000100 = s.getRow(21).getCell(0); - assertEquals(s.getRow(0).getCell(3).getStringCellValue(), fmt.formatCellValue(cell_d20110325)); - assertEquals(s.getRow(11).getCell(3).getStringCellValue(), fmt.formatCellValue(cell_d19000102)); - // There is no such thing as 00/01/1900... - assertEquals("00/01/1900 06:14:24", s.getRow(21).getCell(3).getStringCellValue()); - assertEquals("31/12/1899 06:14:24", fmt.formatCellValue(cell_d19000100)); - - // Check the cached values - assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); - assertEquals(11.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); - assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); - assertEquals(39.0, s.getRow(6).getCell(0).getNumericCellValue(), 0); - assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); - assertEquals(54.0, s.getRow(7).getCell(0).getNumericCellValue(), 0); - - // Re-evaluate and check - HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); - assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); - assertEquals(11.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); - assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); - assertEquals(39.0, s.getRow(6).getCell(0).getNumericCellValue(), 0); - assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); - assertEquals(54.0, s.getRow(7).getCell(0).getNumericCellValue(), 0); - - // Push the time forward a bit and check - double date = s.getRow(0).getCell(0).getNumericCellValue(); - s.getRow(0).getCell(0).setCellValue(date + 1.26); - - HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); - assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); - assertEquals(11.0+6.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); - assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); - assertEquals(39.0+14.0+1, s.getRow(6).getCell(0).getNumericCellValue(), 0); - assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); - assertEquals(54.0+24.0-60, s.getRow(7).getCell(0).getNumericCellValue(), 0); - - wb.close(); + HSSFWorkbook wb = openSample("48968.xls"); + assertEquals(1, wb.getNumberOfSheets()); + + DataFormatter fmt = new DataFormatter(); + + // Check the dates + HSSFSheet s = wb.getSheetAt(0); + Cell cell_d20110325 = s.getRow(0).getCell(0); + Cell cell_d19000102 = s.getRow(11).getCell(0); + Cell cell_d19000100 = s.getRow(21).getCell(0); + assertEquals(s.getRow(0).getCell(3).getStringCellValue(), fmt.formatCellValue(cell_d20110325)); + assertEquals(s.getRow(11).getCell(3).getStringCellValue(), fmt.formatCellValue(cell_d19000102)); + // There is no such thing as 00/01/1900... + assertEquals("00/01/1900 06:14:24", s.getRow(21).getCell(3).getStringCellValue()); + assertEquals("31/12/1899 06:14:24", fmt.formatCellValue(cell_d19000100)); + + // Check the cached values + assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); + assertEquals(11.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); + assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); + assertEquals(39.0, s.getRow(6).getCell(0).getNumericCellValue(), 0); + assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); + assertEquals(54.0, s.getRow(7).getCell(0).getNumericCellValue(), 0); + + // Re-evaluate and check + HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); + assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); + assertEquals(11.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); + assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); + assertEquals(39.0, s.getRow(6).getCell(0).getNumericCellValue(), 0); + assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); + assertEquals(54.0, s.getRow(7).getCell(0).getNumericCellValue(), 0); + + // Push the time forward a bit and check + double date = s.getRow(0).getCell(0).getNumericCellValue(); + s.getRow(0).getCell(0).setCellValue(date + 1.26); + + HSSFFormulaEvaluator.evaluateAllFormulaCells(wb); + assertEquals("HOUR(A1)", s.getRow(5).getCell(0).getCellFormula()); + assertEquals(11.0 + 6.0, s.getRow(5).getCell(0).getNumericCellValue(), 0); + assertEquals("MINUTE(A1)", s.getRow(6).getCell(0).getCellFormula()); + assertEquals(39.0 + 14.0 + 1, s.getRow(6).getCell(0).getNumericCellValue(), 0); + assertEquals("SECOND(A1)", s.getRow(7).getCell(0).getCellFormula()); + assertEquals(54.0 + 24.0 - 60, s.getRow(7).getCell(0).getNumericCellValue(), 0); + + wb.close(); } finally { LocaleUtil.setUserTimeZone(userTimeZone); } } - + /** * Mixture of Ascii and Unicode strings in a - * NameComment record + * NameComment record */ @Test public void bug51143() throws Exception { - HSSFWorkbook wb1 = openSample("51143.xls"); - assertEquals(1, wb1.getNumberOfSheets()); - HSSFWorkbook wb2 = writeOutAndReadBack(wb1); - wb1.close(); - assertEquals(1, wb2.getNumberOfSheets()); - wb2.close(); + HSSFWorkbook wb1 = openSample("51143.xls"); + assertEquals(1, wb1.getNumberOfSheets()); + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); + wb1.close(); + assertEquals(1, wb2.getNumberOfSheets()); + wb2.close(); } /** * File with exactly 256 data blocks (+header block) - * shouldn't break on POIFS loading + * shouldn't break on POIFS loading */ @SuppressWarnings("resource") @Test public void bug51461() throws Exception { - byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls"); + byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51461.xls"); - HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem( - new ByteArrayInputStream(data)).getRoot(), false); - HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem( - new ByteArrayInputStream(data)).getRoot(), false); + HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem( + new ByteArrayInputStream(data)).getRoot(), false); + HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem( + new ByteArrayInputStream(data)).getRoot(), false); - assertEquals(2, wbPOIFS.getNumberOfSheets()); - assertEquals(2, wbNPOIFS.getNumberOfSheets()); + assertEquals(2, wbPOIFS.getNumberOfSheets()); + assertEquals(2, wbNPOIFS.getNumberOfSheets()); } /** @@ -2335,32 +2366,32 @@ public final class TestBugs extends BaseTestBugzillaIssues { @SuppressWarnings("resource") @Test public void bug51535() throws Exception { - byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51535.xls"); - - HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem( - new ByteArrayInputStream(data)).getRoot(), false); - HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem( - new ByteArrayInputStream(data)).getRoot(), false); - - for(HSSFWorkbook wb : new HSSFWorkbook[] {wbPOIFS, wbNPOIFS}) { - assertEquals(3, wb.getNumberOfSheets()); - - // Check directly - HSSFSheet s = wb.getSheetAt(0); - assertEquals("Top Left Cell", s.getRow(0).getCell(0).getStringCellValue()); - assertEquals("Top Right Cell", s.getRow(0).getCell(255).getStringCellValue()); - assertEquals("Bottom Left Cell", s.getRow(65535).getCell(0).getStringCellValue()); - assertEquals("Bottom Right Cell", s.getRow(65535).getCell(255).getStringCellValue()); - - // Extract and check - ExcelExtractor ex = new ExcelExtractor(wb); - String text = ex.getText(); - assertContains(text, "Top Left Cell"); - assertContains(text, "Top Right Cell"); - assertContains(text, "Bottom Left Cell"); - assertContains(text, "Bottom Right Cell"); - ex.close(); - } + byte[] data = HSSFITestDataProvider.instance.getTestDataFileContent("51535.xls"); + + HSSFWorkbook wbPOIFS = new HSSFWorkbook(new POIFSFileSystem( + new ByteArrayInputStream(data)).getRoot(), false); + HSSFWorkbook wbNPOIFS = new HSSFWorkbook(new NPOIFSFileSystem( + new ByteArrayInputStream(data)).getRoot(), false); + + for (HSSFWorkbook wb : new HSSFWorkbook[]{wbPOIFS, wbNPOIFS}) { + assertEquals(3, wb.getNumberOfSheets()); + + // Check directly + HSSFSheet s = wb.getSheetAt(0); + assertEquals("Top Left Cell", s.getRow(0).getCell(0).getStringCellValue()); + assertEquals("Top Right Cell", s.getRow(0).getCell(255).getStringCellValue()); + assertEquals("Bottom Left Cell", s.getRow(65535).getCell(0).getStringCellValue()); + assertEquals("Bottom Right Cell", s.getRow(65535).getCell(255).getStringCellValue()); + + // Extract and check + ExcelExtractor ex = new ExcelExtractor(wb); + String text = ex.getText(); + assertContains(text, "Top Left Cell"); + assertContains(text, "Top Right Cell"); + assertContains(text, "Bottom Left Cell"); + assertContains(text, "Bottom Right Cell"); + ex.close(); + } } @Test @@ -2372,7 +2403,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Sum across multiple workbooks - * eg =SUM($Sheet2.A1:$Sheet3.A1) + * eg =SUM($Sheet2.A1:$Sheet3.A1) */ @Test public void test48703() throws Exception { @@ -2396,9 +2427,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Normally encrypted files have BOF then FILEPASS, but - * some may squeeze a WRITEPROTECT in the middle + * some may squeeze a WRITEPROTECT in the middle */ - @Test(expected=EncryptedDocumentException.class) + @Test(expected = EncryptedDocumentException.class) public void bug51832() { openSample("51832.xls"); } @@ -2406,13 +2437,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void bug49896() throws Exception { HSSFWorkbook wb = openSample("49896.xls"); - HSSFCell cell = wb.getSheetAt(0).getRow(1).getCell(1); + HSSFCell cell = wb.getSheetAt(0).getRow(1).getCell(1); String PATH_SEPARATOR = System.getProperty("file.separator"); - assertEquals("VLOOKUP(A2,'[C:Documents and Settings" + PATH_SEPARATOR+"Yegor"+PATH_SEPARATOR - +"My Documents"+PATH_SEPARATOR+"csco.xls]Sheet1'!$A$2:$B$3,2,FALSE)", + assertEquals("VLOOKUP(A2,'[C:Documents and Settings" + PATH_SEPARATOR + "Yegor" + PATH_SEPARATOR + + "My Documents" + PATH_SEPARATOR + "csco.xls]Sheet1'!$A$2:$B$3,2,FALSE)", cell.getCellFormula()); wb.close(); - } + } @Test public void bug49529() throws Exception { @@ -2425,7 +2456,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // make sure we are still readable writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -2468,13 +2499,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { list.add(r.getSid()); } }); - assertEquals(UnknownRecord.BITMAP_00E9, list.get(list.size()-1).intValue()); - assertEquals(UnknownRecord.HEADER_FOOTER_089C, list.get(list.size()-2).intValue()); + assertEquals(UnknownRecord.BITMAP_00E9, list.get(list.size() - 1).intValue()); + assertEquals(UnknownRecord.HEADER_FOOTER_089C, list.get(list.size() - 2).intValue()); wb.close(); } @Test - public void bug52272() throws IOException{ + public void bug52272() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.createSheet(); HSSFPatriarch p = sh.createDrawingPatriarch(); @@ -2484,14 +2515,14 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFSheet sh2 = wb.cloneSheet(0); assertNotNull(sh2.getDrawingPatriarch()); - + wb.close(); } @Test - public void bug53432() throws IOException{ + public void bug53432() throws IOException { Workbook wb1 = new HSSFWorkbook(); //or new HSSFWorkbook(); - wb1.addPicture(new byte[]{123,22}, Workbook.PICTURE_TYPE_JPEG); + wb1.addPicture(new byte[]{123, 22}, Workbook.PICTURE_TYPE_JPEG); assertEquals(wb1.getAllPictures().size(), 1); wb1.close(); @@ -2501,13 +2532,13 @@ public final class TestBugs extends BaseTestBugzillaIssues { Workbook wb2 = writeOutAndReadBack((HSSFWorkbook) wb1); wb1.close(); assertEquals(wb2.getAllPictures().size(), 0); - wb2.addPicture(new byte[]{123,22}, Workbook.PICTURE_TYPE_JPEG); + wb2.addPicture(new byte[]{123, 22}, Workbook.PICTURE_TYPE_JPEG); assertEquals(wb2.getAllPictures().size(), 1); Workbook wb3 = writeOutAndReadBack((HSSFWorkbook) wb2); wb2.close(); assertEquals(wb3.getAllPictures().size(), 1); - + wb3.close(); } @@ -2521,10 +2552,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFTextbox tb = (HSSFTextbox) patriarch.getChildren().get(2); tb.setString(new HSSFRichTextString("POI test")); - tb.setAnchor(new HSSFClientAnchor(0,0,0,0,(short)0,0,(short)10,10)); + tb.setAnchor(new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 10, 10)); writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -2534,7 +2565,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { Sheet sheet = wb.getSheet("test-sheet"); int rowCount = sheet.getLastRowNum() + 1; int newRows = 5; - Calendar cal = LocaleUtil.getLocaleCalendar(); + Calendar cal = LocaleUtil.getLocaleCalendar(); for (int r = rowCount; r < rowCount + newRows; r++) { Row row = sheet.createRow((short) r); row.createCell(0).setCellValue(1.03 * (r + 7)); @@ -2547,7 +2578,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { } writeOutAndReadBack(wb).close(); - + wb.close(); } @@ -2559,7 +2590,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } - /** Row style information is 12 not 16 bits */ + /** + * Row style information is 12 not 16 bits + */ @Test public void bug49237() throws Exception { Workbook wb = openSample("49237.xls"); @@ -2571,8 +2604,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } - /** POI doesn't currently support the RC4 CryptoAPI encryption header structure */ - @Test(expected=EncryptedDocumentException.class) + /** + * POI doesn't currently support the RC4 CryptoAPI encryption header structure + */ + @Test(expected = EncryptedDocumentException.class) public void bug35897() throws Exception { // password is abc try { @@ -2648,7 +2683,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFWorkbook wb3 = writeOutAndReadBack(wb2); wb2.close(); - + assertEquals(0, wb3.getNumberOfSheets()); wb3.close(); } @@ -2677,7 +2712,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Formulas which reference named ranges, either in other - * sheets, or workbook scoped but in other workbooks. + * sheets, or workbook scoped but in other workbooks. * Used to fail with * java.lang.RuntimeException: Unexpected eval class (org.apache.poi.ss.formula.eval.NameXEval) */ @@ -2711,7 +2746,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Try to evaluate them FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); assertEquals("Test A1", eval.evaluate(cRefSName).getStringValue()); - assertEquals(142, (int)eval.evaluate(cRefWName).getNumberValue()); + assertEquals(142, (int) eval.evaluate(cRefWName).getNumberValue()); // Try to evaluate everything eval.evaluateAll(); @@ -2724,7 +2759,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { */ @Test public void bug54443() throws Exception { - HSSFWorkbook workbook = new HSSFWorkbook( ); + HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCellStyle style = workbook.createCellStyle(); HSSFCellStyle newStyle = workbook.createCellStyle(); @@ -2754,17 +2789,16 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertFormula(wb, s.getRow(8).getCell(0), "Tabelle2!E:F Tabelle2!$A11:$IV12", null); wb.close(); } - + private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) { assertEquals(CellType.FORMULA, intF.getCellTypeEnum()); if (null == expectedResultOrNull) { assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum()); expectedResultOrNull = "#VALUE!"; - } - else { + } else { assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum()); } - + assertEquals(expectedFormula, intF.getCellFormula()); // Check we can evaluate it correctly @@ -2776,7 +2810,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { public void bug42016() throws Exception { Workbook wb = openSample("42016.xls"); Sheet s = wb.getSheetAt(0); - for(int row = 0;row < 7;row++) { + for (int row = 0; row < 7; row++) { assertEquals("A$1+B$1", s.getRow(row).getCell(2).getCellFormula()); } wb.close(); @@ -2797,9 +2831,9 @@ public final class TestBugs extends BaseTestBugzillaIssues { /** * Read, write, read for formulas point to cells in other files. * See {@link #bug46670()} for the main test, this just - * covers reading an existing file and checking it. + * covers reading an existing file and checking it. * TODO Fix this so that it works - formulas are ending up as - * #REF when being changed + * #REF when being changed */ @Test @Ignore @@ -2809,7 +2843,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Expected values String refLocal = "'[refs/airport.xls]Sheet1'!$A$2"; - String refHttp = "'[9http://www.principlesofeconometrics.com/excel/airline.xls]Sheet1'!$A$2"; + String refHttp = "'[9http://www.principlesofeconometrics.com/excel/airline.xls]Sheet1'!$A$2"; // Check we can read them correctly HSSFWorkbook wb1 = openSample("46670_local.xls"); @@ -2868,32 +2902,32 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void test53109() throws IOException { HSSFWorkbook wb1 = openSample("53109.xls"); - + HSSFWorkbook wb2 = writeOutAndReadBack(wb1); assertNotNull(wb2); wb2.close(); - + wb1.close(); } - + @Test public void test53109a() throws IOException { HSSFWorkbook wb1 = openSample("com.aida-tour.www_SPO_files_maldives%20august%20october.xls"); - + Workbook wb2 = writeOutAndReadBack(wb1); assertNotNull(wb2); wb2.close(); - + wb1.close(); } - + @Test public void test48043() throws IOException { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("56325a.xls"); - + wb.removeSheetAt(2); wb.removeSheetAt(1); - + //Sheet s = wb.createSheet("sheetname"); Sheet s = wb.getSheetAt(0); Row row = s.createRow(0); @@ -2901,11 +2935,11 @@ public final class TestBugs extends BaseTestBugzillaIssues { cell.setCellFormula( "IF(AND(ISBLANK(A10)," + - "ISBLANK(B10)),\"\"," + - "CONCATENATE(A10,\"-\",B10))"); - + "ISBLANK(B10)),\"\"," + + "CONCATENATE(A10,\"-\",B10))"); + FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator(); - + eval.evaluateAll(); /*OutputStream out = new FileOutputStream("C:\\temp\\48043.xls"); @@ -2914,32 +2948,32 @@ public final class TestBugs extends BaseTestBugzillaIssues { } finally { out.close(); }*/ - + Workbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb); assertNotNull(wbBack); wbBack.close(); wb.close(); } - + @Test public void test57925() throws IOException { Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57925.xls"); - + wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); - - for(int i = 0;i < wb.getNumberOfSheets();i++) { + + for (int i = 0; i < wb.getNumberOfSheets(); i++) { Sheet sheet = wb.getSheetAt(i); - for(Row row : sheet) { - for(Cell cell : row) { + for (Row row : sheet) { + for (Cell cell : row) { new DataFormatter().formatCellValue(cell); } } } - + wb.close(); } - + @Test public void test46515() throws IOException { Workbook wb = HSSFTestDataSamples.openSampleWorkbook("46515.xls"); @@ -2961,7 +2995,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { ByteArrayOutputStream imageBAOS = new ByteArrayOutputStream(); ImageIO.write(bimage, "jpeg", imageBAOS); imageBAOS.flush(); - byte[]imageBytes = imageBAOS.toByteArray(); + byte[] imageBytes = imageBAOS.toByteArray(); imageBAOS.close(); // Pop structure into Structure HSSFSheet @@ -3021,23 +3055,23 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFClientAnchor anchor = new HSSFClientAnchor(); HSSFSimpleShape shape; CommonObjectDataSubRecord cmo; - + shape = new HSSFTextbox(null, anchor); shape.setShapeId(1025); - cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0); + cmo = (CommonObjectDataSubRecord) shape.getObjRecord().getSubRecords().get(0); assertEquals(1, cmo.getObjectId()); shape = new HSSFPicture(null, anchor); shape.setShapeId(1026); - cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0); + cmo = (CommonObjectDataSubRecord) shape.getObjRecord().getSubRecords().get(0); assertEquals(2, cmo.getObjectId()); shape = new HSSFComment(null, anchor); shape.setShapeId(1027); - cmo = (CommonObjectDataSubRecord)shape.getObjRecord().getSubRecords().get(0); + cmo = (CommonObjectDataSubRecord) shape.getObjRecord().getSubRecords().get(0); assertEquals(1027, cmo.getObjectId()); } - + // As of POI 3.15 beta 2, LibreOffice does not display the diagonal border while it does display the bottom border // I have not checked Excel to know if this is a LibreOffice or a POI problem. @Test @@ -3045,10 +3079,10 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Page 1"); final short BLUE = 30; - + HSSFSheetConditionalFormatting scf = sheet.getSheetConditionalFormatting(); HSSFConditionalFormattingRule rule = scf.createConditionalFormattingRule(ComparisonOperator.GT, "10"); - + HSSFBorderFormatting bord = rule.createBorderFormatting(); bord.setBorderDiagonal(BorderStyle.THICK); assertEquals(BorderStyle.THICK, bord.getBorderDiagonalEnum()); @@ -3058,7 +3092,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { bord.setForwardDiagonalOn(true); assertTrue(bord.isForwardDiagonalOn()); - + bord.setDiagonalBorderColor(BLUE); assertEquals(BLUE, bord.getDiagonalBorderColor()); @@ -3067,14 +3101,14 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(BorderStyle.THICK, bord.getBorderBottomEnum()); bord.setBottomBorderColor(BLUE); assertEquals(BLUE, bord.getBottomBorderColor()); - + CellRangeAddress[] A2_D4 = {new CellRangeAddress(1, 3, 0, 3)}; scf.addConditionalFormatting(A2_D4, rule); - + // Set a cell value within the conditional formatting range whose rule would resolve to True. Cell C3 = sheet.createRow(2).createCell(2); C3.setCellValue(30.0); - + // Manually check the output file with Excel to see if the diagonal border is present //OutputStream fos = new FileOutputStream("/tmp/53564.xls"); //wb.write(fos); @@ -3099,7 +3133,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void test61287() throws IOException { final Workbook wb = HSSFTestDataSamples.openSampleWorkbook("61287.xls"); - ExcelExtractor ex = new ExcelExtractor((HSSFWorkbook)wb); + ExcelExtractor ex = new ExcelExtractor((HSSFWorkbook) wb); String text = ex.getText(); assertContains(text, "\u8D44\u4EA7\u8D1F\u503A\u8868"); wb.close();