diff options
author | Nick Burch <nick@apache.org> | 2008-08-27 10:34:33 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-08-27 10:34:33 +0000 |
commit | ab3de58257edddff10886d2f0830c07fbdf9abc8 (patch) | |
tree | 8ac7344f0b825d722aba854b57566f8d584d66ca /src/testcases/org | |
parent | 48ef5fb2d3523381ad6ef2c135b7625860a5d9f3 (diff) | |
download | poi-ab3de58257edddff10886d2f0830c07fbdf9abc8.tar.gz poi-ab3de58257edddff10886d2f0830c07fbdf9abc8.zip |
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,678540-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683022,683024-683080,683082-683092,683094-683095,683097-683127,683129-683131,683133-683166,683168-683698,683700-683705,683707-683757,683759-683787,683789-683870,683872-683879,683881-683900,683902-684066,684068-684074,684076-684222,684224-684254,684257-684281,684283-684286,684288-684292,684294-684298,684300-684301,684303-684308,684310-684317,684320,684323-684335,684337-684348,684350-684354,684356-684361,684363-684369,684371-684453,684455-684883,684885-684937,684940-684958,684960-684970,684972-684985,684987-685053,685055-685063,685065-685259,685261-685262,685264-685266,685268-685282,685285-686035,686037-686045,686047-686052,686054-686206,686208-686215,686217-686277,686279-686289,686291-686620,686622-686623,686626-686627,686629-686639,686641-686843,686845-686976,686978-689430 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r687403 | nick | 2008-08-20 19:14:11 +0100 (Wed, 20 Aug 2008) | 1 line
Make an initial start on hpbf code
........
r687423 | nick | 2008-08-20 19:50:15 +0100 (Wed, 20 Aug 2008) | 1 line
More HPBF stuff, and some tests
........
r687429 | nick | 2008-08-20 20:40:05 +0100 (Wed, 20 Aug 2008) | 1 line
Quill CONTENTS bits, and tests
........
r687443 | nick | 2008-08-20 21:13:08 +0100 (Wed, 20 Aug 2008) | 1 line
HPBF text extractor and unit tests
........
r688426 | josh | 2008-08-23 23:47:51 +0100 (Sat, 23 Aug 2008) | 1 line
Fix for bug 45672 - prevent MissingRecordAwareHSSFListener generating multiple LastCellOfRowDummyRecords when shared formulas are present
........
r688642 | josh | 2008-08-25 08:56:37 +0100 (Mon, 25 Aug 2008) | 1 line
JDK 1.4 fixes for new hpbf stuff. Some clean-up
........
r688650 | josh | 2008-08-25 09:09:02 +0100 (Mon, 25 Aug 2008) | 1 line
Initial support for evaluating external add-in functions like YEARFRAC
........
r688655 | josh | 2008-08-25 09:30:54 +0100 (Mon, 25 Aug 2008) | 1 line
Fix for bug 45682 - allow cloning of sheets with conditional formatting
........
r688825 | josh | 2008-08-25 19:57:14 +0100 (Mon, 25 Aug 2008) | 1 line
Fix for small bug introduced in c688655 - keep header field in sync with number of rules
........
r688910 | josh | 2008-08-25 23:41:08 +0100 (Mon, 25 Aug 2008) | 1 line
Replaced calls to deprecated versions of createCell(), getCell(), createRow(), and getRow(). (Changing short to int)
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@689435 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
37 files changed, 755 insertions, 424 deletions
diff --git a/src/testcases/org/apache/poi/hssf/data/ex45672.xls b/src/testcases/org/apache/poi/hssf/data/ex45672.xls Binary files differnew file mode 100644 index 0000000000..fbf48e8a21 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/data/ex45672.xls diff --git a/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls b/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls Binary files differnew file mode 100644 index 0000000000..2b2be7d7d8 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/data/yearfracExamples.xls diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java index 2d3759994e..14e3c2c56d 100644 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java @@ -139,7 +139,7 @@ public class TestModelFactory extends TestCase ByteArrayOutputStream stream = new ByteArrayOutputStream(); HSSFSheet sheet = book.createSheet("Test"); HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell((short)0); + HSSFCell cell = row.createCell(0); cell.setCellValue(10.5); book.write(stream); return stream; diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java index 37e594940c..aa4bbcc6f0 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -31,6 +32,7 @@ import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.LabelSSTRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.RowRecord; +import org.apache.poi.hssf.record.SharedFormulaRecord; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * Tests for MissingRecordAwareHSSFListener @@ -39,25 +41,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { private Record[] r; - public void openNormal() { - HSSFRequest req = new HSSFRequest(); - MockHSSFListener mockListen = new MockHSSFListener(); - MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen); - req.addListenerForAllRecords(listener); - - HSSFEventFactory factory = new HSSFEventFactory(); - try { - InputStream is = HSSFTestDataSamples.openSampleFileStream("MissingBits.xls"); - POIFSFileSystem fs = new POIFSFileSystem(is); - factory.processWorkbookEvents(req, fs); - } catch (IOException e) { - throw new RuntimeException(e); - } - - r = mockListen.getRecords(); - assertTrue(r.length > 100); - } - public void openAlt() { + private void readRecords(String sampleFileName) { HSSFRequest req = new HSSFRequest(); MockHSSFListener mockListen = new MockHSSFListener(); MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen); @@ -65,7 +49,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { HSSFEventFactory factory = new HSSFEventFactory(); try { - InputStream is = HSSFTestDataSamples.openSampleFileStream("MRExtraLines.xls"); + InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); POIFSFileSystem fs = new POIFSFileSystem(is); factory.processWorkbookEvents(req, fs); } catch (IOException e) { @@ -75,8 +59,11 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { r = mockListen.getRecords(); assertTrue(r.length > 100); } + public void openNormal() { + readRecords("MissingBits.xls"); + } - public void testMissingRowRecords() throws Exception { + public void testMissingRowRecords() { openNormal(); // We have rows 0, 1, 2, 20 and 21 @@ -126,7 +113,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { assertEquals(19, mr.getRowNumber()); } - public void testEndOfRowRecords() throws Exception { + public void testEndOfRowRecords() { openNormal(); // Find the cell at 0,0 @@ -248,7 +235,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { } - public void testMissingCellRecords() throws Exception { + public void testMissingCellRecords() { openNormal(); // Find the cell at 0,0 @@ -350,29 +337,21 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { // Make sure we don't put in any extra new lines // that aren't already there - public void testNoExtraNewLines() throws Exception { + public void testNoExtraNewLines() { // Load a different file - openAlt(); - - // This file has has something in lines 1-33 - List lcor = new ArrayList(); + readRecords("MRExtraLines.xls"); + + int rowCount=0; for(int i=0; i<r.length; i++) { - if(r[i] instanceof LastCellOfRowDummyRecord) - lcor.add( (LastCellOfRowDummyRecord)r[i] ); + if(r[i] instanceof LastCellOfRowDummyRecord) { + LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) r[i]; + assertEquals(rowCount, eor.getRow()); + rowCount++; + } } - // Check we got the 33 rows - assertEquals(33, lcor.size()); - LastCellOfRowDummyRecord[] rowEnds = (LastCellOfRowDummyRecord[]) - lcor.toArray(new LastCellOfRowDummyRecord[lcor.size()]); - assertEquals(33, rowEnds.length); - - // And check they have the right stuff in them, - // no repeats - for(int i=0; i<rowEnds.length; i++) { - assertEquals(i, rowEnds[i].getRow()); - } + assertEquals(33, rowCount); } private static final class MockHSSFListener implements HSSFListener { @@ -418,4 +397,29 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase { return result; } } + + /** + * Make sure that the presence of shared formulas does not cause extra + * end-of-row records. + */ + public void testEndOfRow_bug45672() { + readRecords("ex45672.xls"); + Record[] rr = r; + int eorCount=0; + int sfrCount=0; + for (int i = 0; i < rr.length; i++) { + Record record = rr[i]; + if (record instanceof SharedFormulaRecord) { + sfrCount++; + } + if (record instanceof LastCellOfRowDummyRecord) { + eorCount++; + } + } + if (eorCount == 2) { + throw new AssertionFailedError("Identified bug 45672"); + } + assertEquals(1, eorCount); + assertEquals(1, sfrCount); + } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java index de443e1897..eb58e96616 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java @@ -365,8 +365,8 @@ public final class TestSSTRecord extends TestCase { { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("duprich1.xls"); HSSFSheet sheet = wb.getSheetAt( 1 ); - assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue() ); - assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell( (short) 8 ).getStringCellValue() ); + assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell(8 ).getStringCellValue() ); + assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell(8 ).getStringCellValue() ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); wb.write( baos ); @@ -375,12 +375,12 @@ public final class TestSSTRecord extends TestCase { wb = HSSFTestDataSamples.openSampleWorkbook("duprich2.xls"); sheet = wb.getSheetAt( 0 ); int row = 0; - assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); - assertEquals( "rich", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); - assertEquals( "text", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); - assertEquals( "strings", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); - assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); - assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() ); + assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + assertEquals( "rich", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + assertEquals( "text", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + assertEquals( "strings", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); + assertEquals( "Testing", sheet.getRow( row++ ).getCell(0 ).getStringCellValue() ); wb.write( baos ); } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java index 844430fb73..b3c864cdb8 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.poi.hssf.model.RecordStream; @@ -31,6 +32,7 @@ import org.apache.poi.hssf.record.RecordFactory; import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.LittleEndian; /** * Tests the serialization and deserialization of the CFRecordsAggregate @@ -63,7 +65,8 @@ public final class TestCFRecordsAggregate extends TestCase record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0)); // Serialize - byte [] serializedRecord = record.serialize(); + byte [] serializedRecord = new byte[record.getRecordSize()]; + record.serialize(0, serializedRecord); InputStream in = new ByteArrayInputStream(serializedRecord); //Parse @@ -98,4 +101,28 @@ public final class TestCFRecordsAggregate extends TestCase assertEquals(2, cellRanges.length); assertEquals(3, header.getNumberOfConditionalFormats()); } + + /** + * Make sure that the CF Header record is properly updated with the number of rules + */ + public void testNRules() { + HSSFWorkbook workbook = new HSSFWorkbook(); + CellRangeAddress[] cellRanges = { + new CellRangeAddress(0,1,0,0), + new CellRangeAddress(0,1,2,2), + }; + CFRuleRecord[] rules = { + CFRuleRecord.create(workbook, "7"), + CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "2", "5"), + }; + CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules); + byte[] serializedRecord = new byte[agg.getRecordSize()]; + agg.serialize(0, serializedRecord); + + int nRules = LittleEndian.getUShort(serializedRecord, 4); + if (nRules == 0) { + throw new AssertionFailedError("Identified bug 45682 b"); + } + assertEquals(rules.length, nRules); + } } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java index 2ae2eebc42..3464c407d0 100755 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java @@ -257,7 +257,7 @@ public class TestValueRecordsAggregate extends TestCase } } private static String getFormulaFromFirstCell(HSSFSheet s, int rowIx) { - return s.getRow(rowIx).getCell((short)0).getCellFormula(); + return s.getRow(rowIx).getCell(0).getCellFormula(); } /** diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java index 8dd8a33681..0dd5758479 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java @@ -34,7 +34,7 @@ public class TestAreaErrPtg extends AbstractPtgTestCase { HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls"); assertEquals("Wrong formula string for area error", "SUM(#REF!)", - workbook.getSheetAt(0).getRow(0).getCell((short) 2).getCellFormula()); + workbook.getSheetAt(0).getRow(0).getCell(2).getCellFormula()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java index 14bcde38b3..2906f5e020 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java @@ -103,7 +103,7 @@ public final class TestArrayPtg extends TestCase { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex42564-elementOrder.xls"); // The formula has an array with 3 rows and 5 columns - String formula = wb.getSheetAt(0).getRow(0).getCell((short)0).getCellFormula(); + String formula = wb.getSheetAt(0).getRow(0).getCell(0).getCellFormula(); // TODO - These number literals should not have '.0'. Excel has different number rendering rules if (formula.equals("SUM({1.0,6.0,11.0;2.0,7.0,12.0;3.0,8.0,13.0;4.0,9.0,14.0;5.0,10.0,15.0})")) { diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java index c8c879c8e2..a7d140cae2 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java @@ -34,7 +34,7 @@ public class TestErrPtg extends AbstractPtgTestCase public void testReading() throws Exception { HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 0); + HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0); assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0); assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula()); } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java b/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java index 2e393d6107..cc5198acfa 100755 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java @@ -71,7 +71,7 @@ public final class TestExternalFunctionFormulas extends TestCase { } } - public void DISABLEDtestEvaluate() { + public void testEvaluate() { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("externalFunctionExample.xls"); HSSFSheet sheet = wb.getSheetAt(0); HSSFCell cell = sheet.getRow(0).getCell(0); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java index 1ddd4df52d..a80ce11837 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java @@ -34,7 +34,7 @@ public class TestIntersectionPtg extends AbstractPtgTestCase public void testReading() throws Exception { HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2); + HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0); assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula()); } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java index fb20f18218..e4b89abb31 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java @@ -37,11 +37,11 @@ public class TestPercentPtg extends AbstractPtgTestCase HSSFSheet sheet = workbook.getSheetAt(0); assertEquals("Wrong numeric value for original number", 53000.0, - sheet.getRow(0).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for percent formula result", 5300.0, - sheet.getRow(1).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for percent formula", "A1*10%", - sheet.getRow(1).getCell((short) 0).getCellFormula()); + sheet.getRow(1).getCell(0).getCellFormula()); } } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java index f871cefba8..2131777f80 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java @@ -34,7 +34,7 @@ public class TestRangePtg extends AbstractPtgTestCase public void testReading() throws Exception { HSSFWorkbook workbook = loadWorkbook("RangePtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 1); + HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(1); assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0); assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula()); } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java index 2bc1f42ff3..b50bb76b45 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java @@ -41,41 +41,41 @@ public final class TestReferencePtg extends TestCase { // First row assertEquals("Wrong numeric value for original number", 55.0, - sheet.getRow(0).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 55.0, - sheet.getRow(0).getCell((short) 1).getNumericCellValue(), 0.0); + sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A1", - sheet.getRow(0).getCell((short) 1).getCellFormula()); + sheet.getRow(0).getCell(1).getCellFormula()); // Now moving over the 2**15 boundary // (Remember that excel row (n) is poi row (n-1) assertEquals("Wrong numeric value for original number", 32767.0, - sheet.getRow(32766).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(32766).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32767.0, - sheet.getRow(32766).getCell((short) 1).getNumericCellValue(), 0.0); + sheet.getRow(32766).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32767", - sheet.getRow(32766).getCell((short) 1).getCellFormula()); + sheet.getRow(32766).getCell(1).getCellFormula()); assertEquals("Wrong numeric value for original number", 32768.0, - sheet.getRow(32767).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(32767).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32768.0, - sheet.getRow(32767).getCell((short) 1).getNumericCellValue(), 0.0); + sheet.getRow(32767).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32768", - sheet.getRow(32767).getCell((short) 1).getCellFormula()); + sheet.getRow(32767).getCell(1).getCellFormula()); assertEquals("Wrong numeric value for original number", 32769.0, - sheet.getRow(32768).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(32768).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32769.0, - sheet.getRow(32768).getCell((short) 1).getNumericCellValue(), 0.0); + sheet.getRow(32768).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32769", - sheet.getRow(32768).getCell((short) 1).getCellFormula()); + sheet.getRow(32768).getCell(1).getCellFormula()); assertEquals("Wrong numeric value for original number", 32770.0, - sheet.getRow(32769).getCell((short) 0).getNumericCellValue(), 0.0); + sheet.getRow(32769).getCell(0).getNumericCellValue(), 0.0); assertEquals("Wrong numeric value for referemce", 32770.0, - sheet.getRow(32769).getCell((short) 1).getNumericCellValue(), 0.0); + sheet.getRow(32769).getCell(1).getNumericCellValue(), 0.0); assertEquals("Wrong formula string for reference", "A32770", - sheet.getRow(32769).getCell((short) 1).getCellFormula()); + sheet.getRow(32769).getCell(1).getCellFormula()); } public void testBug44921() { diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java index b990761d2e..3c9f439752 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java @@ -34,7 +34,7 @@ public class TestUnionPtg extends AbstractPtgTestCase public void testReading() throws Exception { HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls"); - HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2); + HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2); assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0); assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula()); } diff --git a/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java new file mode 100644 index 0000000000..aaf03a238e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java @@ -0,0 +1,66 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.record.formula.atp; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import org.apache.poi.hssf.record.formula.eval.EvaluationException; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; + +/** + * Specific test cases for YearFracCalculator + */ +public final class TestYearFracCalculator extends TestCase { + + public void testBasis1() { + confirm(md(1999, 1, 1), md(1999, 4, 5), 1, 0.257534247); + confirm(md(1999, 4, 1), md(1999, 4, 5), 1, 0.010958904); + confirm(md(1999, 4, 1), md(1999, 4, 4), 1, 0.008219178); + confirm(md(1999, 4, 2), md(1999, 4, 5), 1, 0.008219178); + confirm(md(1999, 3, 31), md(1999, 4, 3), 1, 0.008219178); + confirm(md(1999, 4, 5), md(1999, 4, 8), 1, 0.008219178); + confirm(md(1999, 4, 4), md(1999, 4, 7), 1, 0.008219178); + } + + private void confirm(double startDate, double endDate, int basis, double expectedValue) { + double actualValue; + try { + actualValue = YearFracCalculator.calculate(startDate, endDate, basis); + } catch (EvaluationException e) { + throw new RuntimeException(e); + } + double diff = actualValue - expectedValue; + if (Math.abs(diff) > 0.000000001) { + double hours = diff * 365 * 24; + System.out.println(startDate + " " + endDate + " off by " + hours + " hours"); + assertEquals(expectedValue, actualValue, 0.000000001); + } + + } + + private static double md(int year, int month, int day) { + Calendar c = new GregorianCalendar(); + + c.set(year, month-1, day, 0, 0, 0); + c.set(Calendar.MILLISECOND, 0); + return HSSFDateUtil.getExcelDate(c.getTime()); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java new file mode 100644 index 0000000000..2cad8e3620 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculatorFromSpreadsheet.java @@ -0,0 +1,178 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.record.formula.atp; + +import java.io.PrintStream; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Iterator; + +import junit.framework.Assert; +import junit.framework.AssertionFailedError; +import junit.framework.ComparisonFailure; +import junit.framework.TestCase; + +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.record.formula.eval.EvaluationException; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; + +/** + * Tests YearFracCalculator using test-cases listed in a sample spreadsheet + * + * @author Josh Micich + */ +public final class TestYearFracCalculatorFromSpreadsheet extends TestCase { + + private static final class SS { + + public static final int BASIS_COLUMN = 1; // "B" + public static final int START_YEAR_COLUMN = 2; // "C" + public static final int END_YEAR_COLUMN = 5; // "F" + public static final int YEARFRAC_FORMULA_COLUMN = 11; // "L" + public static final int EXPECTED_RESULT_COLUMN = 13; // "N" + } + + public void testAll() { + + HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("yearfracExamples.xls"); + HSSFSheet sheet = wb.getSheetAt(0); + HSSFFormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator(sheet, wb); + int nSuccess = 0; + int nFailures = 0; + int nUnexpectedErrors = 0; + Iterator rowIterator = sheet.rowIterator(); + while(rowIterator.hasNext()) { + HSSFRow row = (HSSFRow) rowIterator.next(); + + HSSFCell cell = row.getCell(SS.YEARFRAC_FORMULA_COLUMN); + if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) { + continue; + } + try { + processRow(row, cell, formulaEvaluator); + nSuccess++; + } catch (RuntimeException e) { + nUnexpectedErrors ++; + printShortStackTrace(System.err, e); + } catch (AssertionFailedError e) { + nFailures ++; + printShortStackTrace(System.err, e); + } + } + if (nUnexpectedErrors + nFailures > 0) { + String msg = nFailures + " failures(s) and " + nUnexpectedErrors + + " unexpected errors(s) occurred. See stderr for details"; + throw new AssertionFailedError(msg); + } + if (nSuccess < 1) { + throw new RuntimeException("No test sample cases found"); + } + } + + private static void processRow(HSSFRow row, HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) { + + double startDate = makeDate(row, SS.START_YEAR_COLUMN); + double endDate = makeDate(row, SS.END_YEAR_COLUMN); + + int basis = getIntCell(row, SS.BASIS_COLUMN); + + double expectedValue = getDoubleCell(row, SS.EXPECTED_RESULT_COLUMN); + + double actualValue; + try { + actualValue = YearFracCalculator.calculate(startDate, endDate, basis); + } catch (EvaluationException e) { + throw new RuntimeException(e); + } + if (expectedValue != actualValue) { + throw new ComparisonFailure("Direct calculate failed - row " + (row.getRowNum()+1), + String.valueOf(expectedValue), String.valueOf(actualValue)); + } + actualValue = formulaEvaluator.evaluate(cell).getNumberValue(); + if (expectedValue != actualValue) { + throw new ComparisonFailure("Formula evaluate failed - row " + (row.getRowNum()+1), + String.valueOf(expectedValue), String.valueOf(actualValue)); + } + } + + private static double makeDate(HSSFRow row, int yearColumn) { + int year = getIntCell(row, yearColumn + 0); + int month = getIntCell(row, yearColumn + 1); + int day = getIntCell(row, yearColumn + 2); + Calendar c = new GregorianCalendar(year, month-1, day, 0, 0, 0); + c.set(Calendar.MILLISECOND, 0); + return HSSFDateUtil.getExcelDate(c.getTime()); + } + + private static int getIntCell(HSSFRow row, int colIx) { + double dVal = getDoubleCell(row, colIx); + if (Math.floor(dVal) != dVal) { + throw new RuntimeException("Non integer value (" + dVal + + ") cell found at column " + (char)('A' + colIx)); + } + return (int)dVal; + } + + private static double getDoubleCell(HSSFRow row, int colIx) { + HSSFCell cell = row.getCell(colIx); + if (cell == null) { + throw new RuntimeException("No cell found at column " + colIx); + } + double dVal = cell.getNumericCellValue(); + return dVal; + } + + /** + * Useful to keep output concise when expecting many failures to be reported by this test case + * TODO - refactor duplicates in other Test~FromSpreadsheet classes + */ + private static void printShortStackTrace(PrintStream ps, Throwable e) { + StackTraceElement[] stes = e.getStackTrace(); + + int startIx = 0; + // skip any top frames inside junit.framework.Assert + while(startIx<stes.length) { + if(!stes[startIx].getClassName().equals(Assert.class.getName())) { + break; + } + startIx++; + } + // skip bottom frames (part of junit framework) + int endIx = startIx+1; + while(endIx < stes.length) { + if(stes[endIx].getClassName().equals(TestCase.class.getName())) { + break; + } + endIx++; + } + if(startIx >= endIx) { + // something went wrong. just print the whole stack trace + e.printStackTrace(ps); + } + endIx -= 4; // skip 4 frames of reflection invocation + ps.println(e.toString()); + for(int i=startIx; i<endIx; i++) { + ps.println("\tat " + stes[i].toString()); + } + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java b/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java index 0a62d64cdb..5d8ccc7521 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/TestReadMissingBuiltInFuncs.java @@ -150,7 +150,7 @@ public final class TestReadMissingBuiltInFuncs extends TestCase { // some other unexpected error throw e; } - String result = sheet.getRow(rowIx).getCell((short)0).getCellFormula(); + String result = sheet.getRow(rowIx).getCell(0).getCellFormula(); if (false) { System.err.println(result); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java index 39b949f7de..1dc826cc6f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java @@ -85,7 +85,7 @@ public class TestCellStyle c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); - c = r.createCell(( short ) (cellnum + 1)); + c = r.createCell(cellnum + 1); c.setCellValue("TEST"); c.setCellStyle(cs); } @@ -112,16 +112,16 @@ public class TestCellStyle HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); - HSSFRow row = s.createRow((short)0); + HSSFRow row = s.createRow(0); // with Date: - HSSFCell cell = row.createCell((short)1); + HSSFCell cell = row.createCell(1); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); cell.setCellStyle(cs); cell.setCellValue(new Date()); // with Calendar: - cell = row.createCell((short)2); + cell = row.createCell(2); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); cell.setCellStyle(cs); Calendar cal = Calendar.getInstance(); @@ -143,9 +143,9 @@ public class TestCellStyle HSSFSheet s = wb.createSheet(); HSSFCellStyle cs1 = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); - HSSFRow row = s.createRow((short)0); - HSSFCell cell1 = row.createCell((short)1); - HSSFCell cell2 = row.createCell((short)2); + HSSFRow row = s.createRow(0); + HSSFCell cell1 = row.createCell(1); + HSSFCell cell2 = row.createCell(2); cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/dd/yy")); @@ -215,7 +215,7 @@ public class TestCellStyle + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); c.setCellStyle(cs); - c = r.createCell(( short ) (cellnum + 1)); + c = r.createCell(cellnum + 1); c.setCellValue("TEST"); c.setCellStyle(cs2); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java index 299372c121..15a5b8250f 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestDataValidation.java @@ -111,7 +111,7 @@ public final class TestDataValidation extends TestCase { inputBox, errorBox); if (_cellStyle != null) { HSSFRow row = _sheet.getRow(_sheet.getPhysicalNumberOfRows() - 1); - HSSFCell cell = row.createCell((short) 0); + HSSFCell cell = row.createCell(0); cell.setCellStyle(_cellStyle); } writeOtherSettings(_sheet, _style_1, promptDescr); @@ -144,26 +144,26 @@ public final class TestDataValidation extends TestCase { boolean errorBox) { HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows()); // condition's string - HSSFCell cell = row.createCell((short) 1); + HSSFCell cell = row.createCell(1); cell.setCellStyle(style_1); setCellValue(cell, strCondition); // allow empty cells - cell = row.createCell((short) 2); + cell = row.createCell(2); cell.setCellStyle(style_2); setCellValue(cell, ((allowEmpty) ? "yes" : "no")); // show input box - cell = row.createCell((short) 3); + cell = row.createCell(3); cell.setCellStyle(style_2); setCellValue(cell, ((inputBox) ? "yes" : "no")); // show error box - cell = row.createCell((short) 4); + cell = row.createCell(4); cell.setCellStyle(style_2); setCellValue(cell, ((errorBox) ? "yes" : "no")); } private static void writeOtherSettings(HSSFSheet sheet, HSSFCellStyle style, String strStettings) { HSSFRow row = sheet.getRow(sheet.getPhysicalNumberOfRows() - 1); - HSSFCell cell = row.createCell((short) 5); + HSSFCell cell = row.createCell(5); cell.setCellStyle(style); setCellValue(cell, strStettings); } @@ -256,7 +256,7 @@ public final class TestDataValidation extends TestCase { HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows()); row = sheet.createRow(sheet.getPhysicalNumberOfRows()); sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows()-1, sheet.getPhysicalNumberOfRows()-1, 0, 5)); - HSSFCell cell = row.createCell((short) 0); + HSSFCell cell = row.createCell(0); setCellValue(cell, strTypeDescription); cell.setCellStyle(_style_3); row = sheet.createRow(sheet.getPhysicalNumberOfRows()); @@ -267,7 +267,7 @@ public final class TestDataValidation extends TestCase { HSSFRow row = sheet.createRow(sheet.getPhysicalNumberOfRows()); row.setHeight((short) 400); for (int i = 0; i < 6; i++) { - row.createCell((short) i).setCellStyle(_style_4); + row.createCell(i).setCellStyle(_style_4); if (i == 2 || i == 3 || i == 4) { sheet.setColumnWidth((short) i, (short) 3500); } else if (i == 5) { @@ -276,17 +276,17 @@ public final class TestDataValidation extends TestCase { sheet.setColumnWidth((short) i, (short) 8000); } } - HSSFCell cell = row.getCell((short) 0); + HSSFCell cell = row.getCell(0); setCellValue(cell, "Data validation cells"); - cell = row.getCell((short) 1); + cell = row.getCell(1); setCellValue(cell, "Condition"); - cell = row.getCell((short) 2); + cell = row.getCell(2); setCellValue(cell, "Allow blank"); - cell = row.getCell((short) 3); + cell = row.getCell(3); setCellValue(cell, "Prompt box"); - cell = row.getCell((short) 4); + cell = row.getCell(4); setCellValue(cell, "Error box"); - cell = row.getCell((short) 5); + cell = row.getCell(5); setCellValue(cell, "Other settings"); } @@ -298,7 +298,7 @@ public final class TestDataValidation extends TestCase { HSSFSheet sheet = _currentSheet; HSSFRow row = sheet.getRow(sheet.getPhysicalNumberOfRows()-1); sheet.addMergedRegion(new CellRangeAddress(sheet.getPhysicalNumberOfRows()-1, sheet.getPhysicalNumberOfRows()-1, 0, 5)); - HSSFCell cell = row.createCell((short)0); + HSSFCell cell = row.createCell(0); setCellValue(cell, strTypeDescription); cell.setCellStyle(_style_3); row = sheet.createRow(sheet.getPhysicalNumberOfRows()); @@ -395,14 +395,14 @@ public final class TestDataValidation extends TestCase { // add list data on same sheet for (int i = 0; i < 10; i++) { HSSFRow currRow = fSheet.createRow(i + 29); - setCellValue(currRow.createCell((short) 0), cellStrValue); + setCellValue(currRow.createCell(0), cellStrValue); } // add list data on another sheet for (int i = 0; i < 10; i++) { HSSFRow currRow = dataSheet.createRow(i + 0); - setCellValue(currRow.createCell((short) 0), "Data a" + i); - setCellValue(currRow.createCell((short) 1), "Data b" + i); - setCellValue(currRow.createCell((short) 2), "Data c" + i); + setCellValue(currRow.createCell(0), "Data a" + i); + setCellValue(currRow.createCell(1), "Data b" + i); + setCellValue(currRow.createCell(2), "Data c" + i); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index 3fdc1a9dba..36eaf92f32 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -54,8 +54,8 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; //get our minimum values - r = s.createRow((short)1); - c = r.createCell((short)1); + r = s.createRow(1); + c = r.createCell(1); c.setCellFormula(1 + "+" + 1); wb.write(out); @@ -64,8 +64,8 @@ public final class TestFormulas extends TestCase { FileInputStream in = new FileInputStream(file); wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); - r = s.getRow((short)1); - c = r.getCell((short)1); + r = s.getRow(1); + c = r.getCell(1); assertTrue("Formula is as expected",("1+1".equals(c.getCellFormula()))); in.close(); @@ -176,24 +176,24 @@ public final class TestFormulas extends TestCase { //get our minimum values - r = s.createRow((short)0); - c = r.createCell((short)1); + r = s.createRow(0); + c = r.createCell(1); c.setCellFormula(""+Float.MIN_VALUE + operator + Float.MIN_VALUE); for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2) ) { - r = s.createRow((short) x); + r = s.createRow(x); for (short y = 1; y < 256 && y > 0; y= (short) (y +2)) { - c = r.createCell((short) y); + c = r.createCell(y); c.setCellFormula("" + x+"."+y + operator + y +"."+x); } } if (s.getLastRowNum() < Short.MAX_VALUE) { - r = s.createRow((short)0); - c = r.createCell((short)0); + r = s.createRow(0); + c = r.createCell(0); c.setCellFormula("" + Float.MAX_VALUE + operator + Float.MAX_VALUE); } wb.write(out); @@ -216,11 +216,11 @@ public final class TestFormulas extends TestCase { // dont know how to check correct result .. for the moment, we just verify that the file can be read. for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { - r = s.getRow((short) x); + r = s.getRow(x); for (short y = 1; y < 256 && y > 0; y=(short)(y+2)) { - c = r.getCell((short) y); + c = r.getCell(y); assertTrue("got a formula",c.getCellFormula()!=null); assertTrue("loop Formula is as expected "+x+"."+y+operator+y+"."+x+"!="+c.getCellFormula(),( @@ -337,8 +337,8 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; //get our minimum values - r = s.getRow((short)0); - c = r.getCell((short)1); + r = s.getRow(0); + c = r.getCell(1); //get our minimum values assertTrue("minval Formula is as expected A2"+operator+"A3 != "+c.getCellFormula(), ( ("A2"+operator+"A3").equals(c.getCellFormula()) @@ -346,7 +346,7 @@ public final class TestFormulas extends TestCase { for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { - r = s.getRow((short) x); + r = s.getRow(x); for (short y = 1; y < 256 && y > 0; y++) { @@ -372,7 +372,7 @@ public final class TestFormulas extends TestCase { refy2=(short)(y-3); } - c = r.getCell((short) y); + c = r.getCell(y); CellReference cr= new CellReference(refx1, refy1, false, false); ref=cr.formatAsString(); cr=new CellReference(refx2,refy2, false, false); @@ -389,8 +389,8 @@ public final class TestFormulas extends TestCase { } //test our maximum values - r = s.getRow((short)0); - c = r.getCell((short)0); + r = s.getRow(0); + c = r.getCell(0); assertTrue("maxval Formula is as expected",( ("B1"+operator+"IV255").equals(c.getCellFormula()) @@ -416,8 +416,8 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; //get our minimum values - r = s.createRow((short)0); - c = r.createCell((short)1); + r = s.createRow(0); + c = r.createCell(1); c.setCellFormula(formula); wb.write(out); @@ -429,8 +429,8 @@ public final class TestFormulas extends TestCase { s = wb.getSheetAt(0); //get our minimum values - r = s.getRow((short)0); - c = r.getCell((short)1); + r = s.getRow(0); + c = r.getCell(1); assertTrue("minval Formula is as expected", formula.equals(c.getCellFormula()) ); @@ -496,18 +496,18 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; //get our minimum values - r = s.getRow((short)0); - c = r.getCell((short)1); + r = s.getRow(0); + c = r.getCell(1); assertTrue("minval Formula is as expected 1"+operator+"1 != "+c.getCellFormula(), ( ("1"+operator+"1").equals(c.getCellFormula()) )); for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) { - r = s.getRow((short) x); + r = s.getRow(x); for (short y = 1; y < 256 && y > 0; y++) { - c = r.getCell((short) y); + c = r.getCell(y); assertTrue("loop Formula is as expected "+x+operator+y+"!="+c.getCellFormula(),( (""+x+operator+y).equals(c.getCellFormula()) @@ -519,8 +519,8 @@ public final class TestFormulas extends TestCase { } //test our maximum values - r = s.getRow((short)0); - c = r.getCell((short)0); + r = s.getRow(0); + c = r.getCell(0); assertTrue("maxval Formula is as expected",( @@ -549,9 +549,9 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; - r = s.createRow((short) 0); + r = s.createRow(0); - c = r.createCell((short) 0); + c = r.createCell(0); c.setCellFormula(function+"(A2:A3)"); @@ -563,7 +563,7 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("function ="+function+"(A2:A3)", ( (function+"(A2:A3)").equals((function+"(A2:A3)")) ) @@ -586,9 +586,9 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; - r = s.createRow((short) 0); + r = s.createRow(0); - c = r.createCell((short) 0); + c = r.createCell(0); c.setCellFormula(function+"(A2,A3)"); @@ -600,7 +600,7 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("function ="+function+"(A2,A3)", ( (function+"(A2,A3)").equals(c.getCellFormula()) ) @@ -624,11 +624,11 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; - r = s.createRow((short) 0); + r = s.createRow(0); - c = r.createCell((short) 0); + c = r.createCell(0); c.setCellFormula(function+"(A2:A4,B2:B4)"); - c=r.createCell((short) 1); + c=r.createCell(1); c.setCellFormula(function+"($A$2:$A4,B$2:B4)"); wb.write(out); @@ -639,13 +639,13 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("function ="+function+"(A2:A4,B2:B4)", ( (function+"(A2:A4,B2:B4)").equals(c.getCellFormula()) ) ); - c=r.getCell((short) 1); + c=r.getCell(1); assertTrue("function ="+function+"($A$2:$A4,B$2:B4)", ( (function+"($A$2:$A4,B$2:B4)").equals(c.getCellFormula()) ) ); @@ -663,17 +663,17 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; - r = s.createRow((short) 0); + r = s.createRow(0); - c = r.createCell((short) 0); + c = r.createCell(0); c.setCellFormula("A3+A2"); - c=r.createCell( (short) 1); + c=r.createCell(1); c.setCellFormula("$A3+$A2"); - c=r.createCell( (short) 2); + c=r.createCell(2); c.setCellFormula("A$3+A$2"); - c=r.createCell( (short) 3); + c=r.createCell(3); c.setCellFormula("$A$3+$A$2"); - c=r.createCell( (short) 4); + c=r.createCell(4); c.setCellFormula("SUM($A$3,$A$2)"); wb.write(out); @@ -684,15 +684,15 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("A3+A2", ("A3+A2").equals(c.getCellFormula())); - c = r.getCell((short)1); + c = r.getCell(1); assertTrue("$A3+$A2", ("$A3+$A2").equals(c.getCellFormula())); - c = r.getCell((short)2); + c = r.getCell(2); assertTrue("A$3+A$2", ("A$3+A$2").equals(c.getCellFormula())); - c = r.getCell((short)3); + c = r.getCell(3); assertTrue("$A$3+$A$2", ("$A$3+$A$2").equals(c.getCellFormula())); - c = r.getCell((short)4); + c = r.getCell(4); assertTrue("SUM($A$3,$A$2)", ("SUM($A$3,$A$2)").equals(c.getCellFormula())); in.close(); } @@ -706,15 +706,15 @@ public final class TestFormulas extends TestCase { HSSFSheet s = wb.createSheet("A"); HSSFRow r = null; HSSFCell c = null; - r = s.createRow((short)0); - c = r.createCell((short)0);c.setCellValue(1); - c = r.createCell((short)1);c.setCellValue(2); + r = s.createRow(0); + c = r.createCell(0);c.setCellValue(1); + c = r.createCell(1);c.setCellValue(2); s = wb.createSheet("B"); - r = s.createRow((short)0); - c=r.createCell((short)0); c.setCellFormula("AVERAGE(A!A1:B1)"); - c=r.createCell((short)1); c.setCellFormula("A!A1+A!B1"); - c=r.createCell((short)2); c.setCellFormula("A!$A$1+A!$B1"); + r = s.createRow(0); + c=r.createCell(0); c.setCellFormula("AVERAGE(A!A1:B1)"); + c=r.createCell(1); c.setCellFormula("A!A1+A!B1"); + c=r.createCell(2); c.setCellFormula("A!$A$1+A!$B1"); wb.write(out); out.close(); @@ -724,9 +724,9 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheet("B"); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("expected: AVERAGE(A!A1:B1) got: "+c.getCellFormula(), ("AVERAGE(A!A1:B1)").equals(c.getCellFormula())); - c = r.getCell((short)1); + c = r.getCell(1); assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula())); in.close(); } @@ -740,29 +740,29 @@ public final class TestFormulas extends TestCase { HSSFCell c = null; - r = s.createRow((short) 0); + r = s.createRow(0); - c = r.createCell((short) 0); + c = r.createCell(0); c.setCellFormula("A3+A2"); - c=r.createCell( (short) 1); + c=r.createCell(1); c.setCellFormula("AVERAGE(A3,A2)"); - c=r.createCell( (short) 2); + c=r.createCell(2); c.setCellFormula("ROW(A3)"); - c=r.createCell( (short) 3); + c=r.createCell(3); c.setCellFormula("AVERAGE(A2:A3)"); - c=r.createCell( (short) 4); + c=r.createCell(4); c.setCellFormula("POWER(A2,A3)"); - c=r.createCell( (short) 5); + c=r.createCell(5); c.setCellFormula("SIN(A2)"); - c=r.createCell( (short) 6); + c=r.createCell(6); c.setCellFormula("SUM(A2:A3)"); - c=r.createCell( (short) 7); + c=r.createCell(7); c.setCellFormula("SUM(A2,A3)"); - r = s.createRow((short) 1);c=r.createCell( (short) 0); c.setCellValue(2.0); - r = s.createRow((short) 2);c=r.createCell( (short) 0); c.setCellValue(3.0); + r = s.createRow(1);c=r.createCell(0); c.setCellValue(2.0); + r = s.createRow(2);c=r.createCell(0); c.setCellValue(3.0); wb.write(out); out.close(); @@ -778,10 +778,10 @@ public final class TestFormulas extends TestCase { HSSFSheet s = wb.createSheet("A"); HSSFRow r = null; HSSFCell c = null; - r = s.createRow((short)0); - c=r.createCell((short)1); c.setCellFormula("UPPER(\"abc\")"); - c=r.createCell((short)2); c.setCellFormula("LOWER(\"ABC\")"); - c=r.createCell((short)3); c.setCellFormula("CONCATENATE(\" my \",\" name \")"); + r = s.createRow(0); + c=r.createCell(1); c.setCellFormula("UPPER(\"abc\")"); + c=r.createCell(2); c.setCellFormula("LOWER(\"ABC\")"); + c=r.createCell(3); c.setCellFormula("CONCATENATE(\" my \",\" name \")"); wb.write(out); out.close(); @@ -789,7 +789,7 @@ public final class TestFormulas extends TestCase { wb = openSample("StringFormulas.xls"); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("expected: UPPER(\"xyz\") got "+c.getCellFormula(), ("UPPER(\"xyz\")").equals(c.getCellFormula())); //c = r.getCell((short)1); //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula())); @@ -807,8 +807,8 @@ public final class TestFormulas extends TestCase { HSSFSheet s = wb.createSheet("A"); HSSFRow r = null; HSSFCell c = null; - r = s.createRow((short)0); - c=r.createCell((short)1); c.setCellFormula("IF(A1<A2,B1,B2)"); + r = s.createRow(0); + c=r.createCell(1); c.setCellFormula("IF(A1<A2,B1,B2)"); wb.write(out); @@ -820,7 +820,7 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)1); + c = r.getCell(1); assertEquals("Formula in cell 1 ","IF(A1<A2,B1,B2)",c.getCellFormula()); in.close(); } @@ -835,8 +835,8 @@ public final class TestFormulas extends TestCase { HSSFRow r = null; HSSFCell c = null; - r = s.createRow( (short)0 ); - c = r.createCell( (short)0 ); + r = s.createRow(0 ); + c = r.createCell(0 ); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); @@ -847,8 +847,8 @@ public final class TestFormulas extends TestCase { // HSSFDateUtil.getJavaDate(excelDate).getTime()); for (int k=1; k < 100; k++) { - r=s.createRow((short)k); - c=r.createCell((short)0); + r=s.createRow(k); + c=r.createCell(0); c.setCellFormula("A"+(k)+"+1"); c.setCellStyle(cellStyle); } @@ -870,11 +870,11 @@ public final class TestFormulas extends TestCase { HSSFSheet s = wb.createSheet("testSheet1"); HSSFRow r = null; HSSFCell c = null; - r = s.createRow((short)0); - c=r.createCell((short)1); c.setCellValue(1); - c=r.createCell((short)2); c.setCellValue(2); - c=r.createCell((short)3); c.setCellFormula("MAX(A1:B1)"); - c=r.createCell((short)4); c.setCellFormula("IF(A1=D1,\"A1\",\"B1\")"); + r = s.createRow(0); + c=r.createCell(1); c.setCellValue(1); + c=r.createCell(2); c.setCellValue(2); + c=r.createCell(3); c.setCellFormula("MAX(A1:B1)"); + c=r.createCell(4); c.setCellFormula("IF(A1=D1,\"A1\",\"B1\")"); wb.write(out); out.close(); @@ -885,7 +885,7 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(in); s = wb.getSheetAt(0); r = s.getRow(0); - c = r.getCell((short)4); + c = r.getCell(4); assertTrue("expected: IF(A1=D1,\"A1\",\"B1\") got "+c.getCellFormula(), ("IF(A1=D1,\"A1\",\"B1\")").equals(c.getCellFormula())); in.close(); @@ -893,7 +893,7 @@ public final class TestFormulas extends TestCase { wb = openSample("IfFormulaTest.xls"); s = wb.getSheetAt(0); r = s.getRow(3); - c = r.getCell((short)0); + c = r.getCell(0); assertTrue("expected: IF(A3=A1,\"A1\",\"A2\") got "+c.getCellFormula(), ("IF(A3=A1,\"A1\",\"A2\")").equals(c.getCellFormula())); //c = r.getCell((short)1); //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula())); @@ -905,8 +905,8 @@ public final class TestFormulas extends TestCase { s = wb.createSheet("testSheet1"); r = null; c = null; - r = s.createRow((short)0); - c=r.createCell((short)0); c.setCellFormula("IF(1=1,0,1)"); + r = s.createRow(0); + c=r.createCell(0); c.setCellFormula("IF(1=1,0,1)"); wb.write(out); out.close(); @@ -920,21 +920,21 @@ public final class TestFormulas extends TestCase { s = wb.createSheet("testSheet1"); r = null; c = null; - r = s.createRow((short)0); - c=r.createCell((short)0); + r = s.createRow(0); + c=r.createCell(0); c.setCellValue(1); - c=r.createCell((short)1); + c=r.createCell(1); c.setCellValue(3); - HSSFCell formulaCell=r.createCell((short)3); + HSSFCell formulaCell=r.createCell(3); - r = s.createRow((short)1); - c=r.createCell((short)0); + r = s.createRow(1); + c=r.createCell(0); c.setCellValue(3); - c=r.createCell((short)1); + c=r.createCell(1); c.setCellValue(7); formulaCell.setCellFormula("IF(A1=B1,AVERAGE(A1:B1),AVERAGE(A2:B2))"); @@ -956,7 +956,7 @@ public final class TestFormulas extends TestCase { HSSFSheet s = wb.getSheetAt(0); HSSFRow r = s.getRow(0); - HSSFCell c = r.getCell((short)2); + HSSFCell c = r.getCell(2); assertEquals(function, c.getCellFormula()); @@ -965,29 +965,29 @@ public final class TestFormulas extends TestCase { wb = new HSSFWorkbook(); s = wb.createSheet(); - r = s.createRow((short)0); - c=r.createCell((short)0); c.setCellValue((double)1000); - c=r.createCell((short)1); c.setCellValue((double)1); + r = s.createRow(0); + c=r.createCell(0); c.setCellValue((double)1000); + c=r.createCell(1); c.setCellValue((double)1); - r = s.createRow((short)1); - c=r.createCell((short)0); c.setCellValue((double)2000); - c=r.createCell((short)1); c.setCellValue((double)2); + r = s.createRow(1); + c=r.createCell(0); c.setCellValue((double)2000); + c=r.createCell(1); c.setCellValue((double)2); - r = s.createRow((short)2); - c=r.createCell((short)0); c.setCellValue((double)3000); - c=r.createCell((short)1); c.setCellValue((double)3); + r = s.createRow(2); + c=r.createCell(0); c.setCellValue((double)3000); + c=r.createCell(1); c.setCellValue((double)3); - r = s.createRow((short)3); - c=r.createCell((short)0); c.setCellValue((double)4000); - c=r.createCell((short)1); c.setCellValue((double)4); + r = s.createRow(3); + c=r.createCell(0); c.setCellValue((double)4000); + c=r.createCell(1); c.setCellValue((double)4); - r = s.createRow((short)4); - c=r.createCell((short)0); c.setCellValue((double)5000); - c=r.createCell((short)1); c.setCellValue((double)5); + r = s.createRow(4); + c=r.createCell(0); c.setCellValue((double)5000); + c=r.createCell(1); c.setCellValue((double)5); r = s.getRow(0); - c=r.createCell((short)2); c.setCellFormula(function); + c=r.createCell(2); c.setCellFormula(function); wb.write(out); out.close(); @@ -1002,42 +1002,42 @@ public final class TestFormulas extends TestCase { HSSFSheet s0 = w.getSheetAt(0); HSSFRow[] r = {s0.getRow(0), s0.getRow(1)}; - HSSFCell a1 = r[0].getCell((short) 0); + HSSFCell a1 = r[0].getCell(0); assertEquals("square(1)", a1.getCellFormula()); assertEquals(1d, a1.getNumericCellValue(), 1e-9); - HSSFCell a2 = r[1].getCell((short) 0); + HSSFCell a2 = r[1].getCell(0); assertEquals("square(2)", a2.getCellFormula()); assertEquals(4d, a2.getNumericCellValue(), 1e-9); - HSSFCell b1 = r[0].getCell((short) 1); + HSSFCell b1 = r[0].getCell(1); assertEquals("IF(TRUE,square(1))", b1.getCellFormula()); assertEquals(1d, b1.getNumericCellValue(), 1e-9); - HSSFCell b2 = r[1].getCell((short) 1); + HSSFCell b2 = r[1].getCell(1); assertEquals("IF(TRUE,square(2))", b2.getCellFormula()); assertEquals(4d, b2.getNumericCellValue(), 1e-9); - HSSFCell c1 = r[0].getCell((short) 2); + HSSFCell c1 = r[0].getCell(2); assertEquals("square(square(1))", c1.getCellFormula()); assertEquals(1d, c1.getNumericCellValue(), 1e-9); - HSSFCell c2 = r[1].getCell((short) 2); + HSSFCell c2 = r[1].getCell(2); assertEquals("square(square(2))", c2.getCellFormula()); assertEquals(16d, c2.getNumericCellValue(), 1e-9); - HSSFCell d1 = r[0].getCell((short) 3); + HSSFCell d1 = r[0].getCell(3); assertEquals("square(one())", d1.getCellFormula()); assertEquals(1d, d1.getNumericCellValue(), 1e-9); - HSSFCell d2 = r[1].getCell((short) 3); + HSSFCell d2 = r[1].getCell(3); assertEquals("square(two())", d2.getCellFormula()); assertEquals(4d, d2.getNumericCellValue(), 1e-9); } public void testStringFormulaRead() { HSSFWorkbook w = openSample("StringFormulas.xls"); - HSSFCell c = w.getSheetAt(0).getRow(0).getCell((short)0); + HSSFCell c = w.getSheetAt(0).getRow(0).getCell(0); assertEquals("String Cell value","XYZ",c.getRichStringCellValue().getString()); } @@ -1046,8 +1046,8 @@ public final class TestFormulas extends TestCase { HSSFWorkbook sb = new HSSFWorkbook(); HSSFSheet s1 = sb.createSheet("Sheet a.1"); HSSFSheet s2 = sb.createSheet("Sheet.A"); - s2.createRow(1).createCell((short) 2).setCellFormula("'Sheet a.1'!A1"); - s1.createRow(1).createCell((short) 2).setCellFormula("'Sheet.A'!A1"); + s2.createRow(1).createCell(2).setCellFormula("'Sheet a.1'!A1"); + s1.createRow(1).createCell(2).setCellFormula("'Sheet.A'!A1"); File file = TempFile.createTempFile("testComplexSheetRefs",".xls"); sb.write(new FileOutputStream(file)); } @@ -1073,17 +1073,17 @@ public final class TestFormulas extends TestCase { /* MissingArgPtg */ public void testMissingArgPtg() throws Exception { HSSFWorkbook wb = new HSSFWorkbook(); - HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell((short) 0); + HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell(0); cell.setCellFormula("IF(A1=\"A\",1,)"); } public void testSharedFormula() { HSSFWorkbook wb = openSample("SharedFormulaTest.xls"); - assertEquals("A$1*2", wb.getSheetAt(0).getRow(1).getCell((short)1).toString()); - assertEquals("$A11*2", wb.getSheetAt(0).getRow(11).getCell((short)1).toString()); - assertEquals("DZ2*2", wb.getSheetAt(0).getRow(1).getCell((short)128).toString()); - assertEquals("B32770*2", wb.getSheetAt(0).getRow(32768).getCell((short)1).toString()); + assertEquals("A$1*2", wb.getSheetAt(0).getRow(1).getCell(1).toString()); + assertEquals("$A11*2", wb.getSheetAt(0).getRow(11).getCell(1).toString()); + assertEquals("DZ2*2", wb.getSheetAt(0).getRow(1).getCell(128).toString()); + assertEquals("B32770*2", wb.getSheetAt(0).getRow(32768).getCell(1).toString()); } public static void main(String [] args) { diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index da5d2cc6a9..30f63ab4a2 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -76,7 +76,7 @@ public final class TestHSSFCell extends TestCase { HSSFSheet s = wb.createSheet("testSheet1"); HSSFRow r = null; HSSFCell c = null; - r = s.createRow((short)0); + r = s.createRow(0); c=r.createCell(1); //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN); c.setCellValue(true); @@ -85,7 +85,7 @@ public final class TestHSSFCell extends TestCase { //c.setCellType(HSSFCell.CELL_TYPE_BOOLEAN); c.setCellValue(false); - r = s.createRow((short)1); + r = s.createRow(1); c=r.createCell(1); //c.setCellType(HSSFCell.CELL_TYPE_ERROR); c.setCellErrorValue((byte)0); @@ -241,7 +241,7 @@ public final class TestHSSFCell extends TestCase { cs.setBorderLeft((short)1); cs.setBorderBottom((short)1); - r = s.createRow((short)0); + r = s.createRow(0); c=r.createCell(0); c.setCellStyle(cs); c.setCellFormula("2*3"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java index 978f435773..4ea0762dda 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java @@ -116,7 +116,7 @@ public final class TestHSSFComment extends TestCase { for (int rownum = 0; rownum < 3; rownum++) { row = sheet.getRow(rownum); - cell = row.getCell((short)0); + cell = row.getCell(0); comment = cell.getCellComment(); assertNull("Cells in the first column are not commented", comment); assertNull(sheet.getCellComment(rownum, 0)); @@ -124,7 +124,7 @@ public final class TestHSSFComment extends TestCase { for (int rownum = 0; rownum < 3; rownum++) { row = sheet.getRow(rownum); - cell = row.getCell((short)1); + cell = row.getCell(1); comment = cell.getCellComment(); assertNotNull("Cells in the second column have comments", comment); assertNotNull("Cells in the second column have comments", sheet.getCellComment(rownum, 1)); @@ -153,7 +153,7 @@ public final class TestHSSFComment extends TestCase { for (int rownum = 0; rownum < 3; rownum++) { row = sheet.getRow(rownum); - cell = row.getCell((short)1); + cell = row.getCell(1); comment = cell.getCellComment(); comment.setAuthor("Mofified["+rownum+"] by Yegor"); comment.setString(new HSSFRichTextString("Modified comment at row " + rownum)); @@ -168,7 +168,7 @@ public final class TestHSSFComment extends TestCase { for (int rownum = 0; rownum < 3; rownum++) { row = sheet.getRow(rownum); - cell = row.getCell((short)1); + cell = row.getCell(1); comment = cell.getCellComment(); assertEquals("Mofified["+rownum+"] by Yegor", comment.getAuthor()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java index fcb0b8f41e..f9e62ffbf9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.usermodel; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator; @@ -109,4 +110,44 @@ public final class TestHSSFConditionalFormatting extends TestCase assertEquals("2",rule2.getFormula2()); assertEquals("1",rule2.getFormula1()); } + + public void testClone() { + + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + String formula = "7"; + + HSSFSheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); + + HSSFConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(formula); + HSSFFontFormatting fontFmt = rule1.createFontFormatting(); + fontFmt.setFontStyle(true, false); + + HSSFPatternFormatting patternFmt = rule1.createPatternFormatting(); + patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index); + + + HSSFConditionalFormattingRule rule2 = sheetCF.createConditionalFormattingRule(ComparisonOperator.BETWEEN, "1", "2"); + HSSFConditionalFormattingRule [] cfRules = + { + rule1, rule2 + }; + + short col = 1; + CellRangeAddress [] regions = { + new CellRangeAddress(0, 65535, col, col) + }; + + sheetCF.addConditionalFormatting(regions, cfRules); + + try { + wb.cloneSheet(0); + } catch (RuntimeException e) { + if (e.getMessage().indexOf("needs to define a clone method") > 0) { + throw new AssertionFailedError("Indentified bug 45682"); + } + throw e; + } + assertEquals(2, wb.getNumberOfSheets()); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java index 377a8ffe24..9e451ee052 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java @@ -16,7 +16,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.usermodel; import java.util.Calendar; @@ -52,9 +51,7 @@ public final class TestHSSFDateUtil extends TestCase { * Checks the date conversion functions in the HSSFDateUtil class. */ - public void testDateConversion() - throws Exception - { + public void testDateConversion() { // Iteratating over the hours exposes any rounding issues. for (int hour = 0; hour < 23; hour++) @@ -131,7 +128,7 @@ public final class TestHSSFDateUtil extends TestCase { for (int hour = 0; hour < 24; hour++, excelDate += oneHour) { // Skip 02:00 CET as that is the Daylight change time - // and Java converts it automatically to 03:00 CEST + // and Java converts it automatically to 03:00 CEST if (hour == 2) { continue; } @@ -186,7 +183,7 @@ public final class TestHSSFDateUtil extends TestCase { HSSFDateUtil.getExcelDate(javaDate, false), oneMinute); } } - + /** * Tests that we deal with time-zones properly */ @@ -207,8 +204,7 @@ public final class TestHSSFDateUtil extends TestCase { assertEquals("Checking timezone " + id, expected.getTime(), javaDate.getTime()); } } - - + /** * Tests that we correctly detect date formats as such */ @@ -220,7 +216,7 @@ public final class TestHSSFDateUtil extends TestCase { assertTrue( HSSFDateUtil.isInternalDateFormat(builtins[i]) ); assertTrue( HSSFDateUtil.isADateFormat(builtins[i],formatStr) ); } - + // Now try a few built-in non date formats builtins = new short[] { 0x01, 0x02, 0x17, 0x1f, 0x30 }; for(int i=0; i<builtins.length; i++) { @@ -228,14 +224,14 @@ public final class TestHSSFDateUtil extends TestCase { assertFalse( HSSFDateUtil.isInternalDateFormat(builtins[i]) ); assertFalse( HSSFDateUtil.isADateFormat(builtins[i],formatStr) ); } - + // Now for some non-internal ones // These come after the real ones int numBuiltins = HSSFDataFormat.getNumberOfBuiltinBuiltinFormats(); assertTrue(numBuiltins < 60); short formatId = 60; assertFalse( HSSFDateUtil.isInternalDateFormat(formatId) ); - + // Valid ones first String[] formats = new String[] { "yyyy-mm-dd", "yyyy/mm/dd", "yy/mm/dd", "yy/mmm/dd", @@ -243,7 +239,7 @@ public final class TestHSSFDateUtil extends TestCase { "dd-mm-yy", "dd-mm-yyyy", "DD-MM-YY", "DD-mm-YYYY", "dd\\-mm\\-yy", // Sometimes escaped - + // These crazy ones are valid "yyyy-mm-dd;@", "yyyy/mm/dd;@", "dd-mm-yy;@", "dd-mm-yyyy;@", @@ -257,14 +253,14 @@ public final class TestHSSFDateUtil extends TestCase { }; for(int i=0; i<formats.length; i++) { assertTrue( - formats[i] + " is a date format", - HSSFDateUtil.isADateFormat(formatId, formats[i]) + formats[i] + " is a date format", + HSSFDateUtil.isADateFormat(formatId, formats[i]) ); } - + // Then time based ones too formats = new String[] { - "yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS", + "yyyy-mm-dd hh:mm:ss", "yyyy/mm/dd HH:MM:SS", "mm/dd HH:MM", "yy/mmm/dd SS", "mm/dd HH:MM AM", "mm/dd HH:MM am", "mm/dd HH:MM PM", "mm/dd HH:MM pm", @@ -272,30 +268,30 @@ public final class TestHSSFDateUtil extends TestCase { }; for(int i=0; i<formats.length; i++) { assertTrue( - formats[i] + " is a datetime format", - HSSFDateUtil.isADateFormat(formatId, formats[i]) + formats[i] + " is a datetime format", + HSSFDateUtil.isADateFormat(formatId, formats[i]) ); } - + // Then invalid ones formats = new String[] { - "yyyy*mm*dd", + "yyyy*mm*dd", "0.0", "0.000", "0%", "0.0%", "[]Foo", "[BLACK]0.00%", "", null }; for(int i=0; i<formats.length; i++) { - assertFalse( - formats[i] + " is not a date or datetime format", - HSSFDateUtil.isADateFormat(formatId, formats[i]) + assertFalse( + formats[i] + " is not a date or datetime format", + HSSFDateUtil.isADateFormat(formatId, formats[i]) ); } - + // And these are ones we probably shouldn't allow, // but would need a better regexp formats = new String[] { - "yyyy:mm:dd", + "yyyy:mm:dd", }; for(int i=0; i<formats.length; i++) { // assertFalse( HSSFDateUtil.isADateFormat(formatId, formats[i]) ); @@ -306,63 +302,63 @@ public final class TestHSSFDateUtil extends TestCase { * Test that against a real, test file, we still do everything * correctly */ - public void testOnARealFile() throws Exception { + public void testOnARealFile() { HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls"); HSSFSheet sheet = workbook.getSheetAt(0); Workbook wb = workbook.getWorkbook(); - + HSSFRow row; HSSFCell cell; HSSFCellStyle style; - + double aug_10_2007 = 39304.0; - + // Should have dates in 2nd column // All of them are the 10th of August // 2 US dates, 3 UK dates row = sheet.getRow(0); - cell = row.getCell((short)1); + cell = row.getCell(1); style = cell.getCellStyle(); assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001); assertEquals("d-mmm-yy", style.getDataFormatString()); assertTrue(HSSFDateUtil.isInternalDateFormat(style.getDataFormat())); assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString())); assertTrue(HSSFDateUtil.isCellDateFormatted(cell)); - + row = sheet.getRow(1); - cell = row.getCell((short)1); + cell = row.getCell(1); style = cell.getCellStyle(); assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001); assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat())); assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString())); assertTrue(HSSFDateUtil.isCellDateFormatted(cell)); - + row = sheet.getRow(2); - cell = row.getCell((short)1); + cell = row.getCell(1); style = cell.getCellStyle(); assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001); assertTrue(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat())); assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString())); assertTrue(HSSFDateUtil.isCellDateFormatted(cell)); - + row = sheet.getRow(3); - cell = row.getCell((short)1); + cell = row.getCell(1); style = cell.getCellStyle(); assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001); assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat())); assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString())); assertTrue(HSSFDateUtil.isCellDateFormatted(cell)); - + row = sheet.getRow(4); - cell = row.getCell((short)1); + cell = row.getCell(1); style = cell.getCellStyle(); assertEquals(aug_10_2007, cell.getNumericCellValue(), 0.0001); assertFalse(HSSFDateUtil.isInternalDateFormat(cell.getCellStyle().getDataFormat())); assertTrue(HSSFDateUtil.isADateFormat(style.getDataFormat(), style.getDataFormatString())); assertTrue(HSSFDateUtil.isCellDateFormatted(cell)); } - + public void testDateBug_2Excel() { assertEquals(59.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_FEBRUARY, 28), false), 0.00001); assertEquals(61.0, HSSFDateUtil.getExcelDate(createDate(1900, CALENDAR_MARCH, 1), false), 0.00001); @@ -372,41 +368,49 @@ public final class TestHSSFDateUtil extends TestCase { assertEquals(37257.00, HSSFDateUtil.getExcelDate(createDate(2002, CALENDAR_JANUARY, 1), false), 0.00001); assertEquals(38074.00, HSSFDateUtil.getExcelDate(createDate(2004, CALENDAR_MARCH, 28), false), 0.00001); } - + public void testDateBug_2Java() { assertEquals(createDate(1900, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(59.0, false)); assertEquals(createDate(1900, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(61.0, false)); - + assertEquals(createDate(2002, CALENDAR_FEBRUARY, 28), HSSFDateUtil.getJavaDate(37315.00, false)); assertEquals(createDate(2002, CALENDAR_MARCH, 1), HSSFDateUtil.getJavaDate(37316.00, false)); assertEquals(createDate(2002, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(37257.00, false)); assertEquals(createDate(2004, CALENDAR_MARCH, 28), HSSFDateUtil.getJavaDate(38074.00, false)); } - + public void testDate1904() { assertEquals(createDate(1904, CALENDAR_JANUARY, 2), HSSFDateUtil.getJavaDate(1.0, true)); assertEquals(createDate(1904, CALENDAR_JANUARY, 1), HSSFDateUtil.getJavaDate(0.0, true)); assertEquals(0.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 1), true), 0.00001); assertEquals(1.0, HSSFDateUtil.getExcelDate(createDate(1904, CALENDAR_JANUARY, 2), true), 0.00001); - + assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(35981, false)); assertEquals(createDate(1998, CALENDAR_JULY, 5), HSSFDateUtil.getJavaDate(34519, true)); - + assertEquals(35981.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), false), 0.00001); assertEquals(34519.0, HSSFDateUtil.getExcelDate(createDate(1998, CALENDAR_JULY, 5), true), 0.00001); } - + /** - * @param month zero based + * @param month zero based * @param day one based */ private static Date createDate(int year, int month, int day) { + return createDate(year, month, day, 0, 0, 0); + } + + /** + * @param month zero based + * @param day one based + */ + private static Date createDate(int year, int month, int day, int hour, int minute, int second) { Calendar c = new GregorianCalendar(); - c.set(year, month, day, 0, 0, 0); + c.set(year, month, day, hour, minute, second); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } - + /** * Check if HSSFDateUtil.getAbsoluteDay works as advertised. */ @@ -420,16 +424,27 @@ public final class TestHSSFDateUtil extends TestCase { } public void testConvertTime() { - + final double delta = 1E-7; // a couple of digits more accuracy than strictly required assertEquals(0.5, HSSFDateUtil.convertTime("12:00"), delta); assertEquals(2.0/3, HSSFDateUtil.convertTime("16:00"), delta); assertEquals(0.0000116, HSSFDateUtil.convertTime("0:00:01"), delta); assertEquals(0.7330440, HSSFDateUtil.convertTime("17:35:35"), delta); } - + public void testParseDate() { assertEquals(createDate(2008, Calendar.AUGUST, 3), HSSFDateUtil.parseYYYYMMDDDate("2008/08/03")); assertEquals(createDate(1994, Calendar.MAY, 1), HSSFDateUtil.parseYYYYMMDDDate("1994/05/01")); } + + /** + * Ensure that date values *with* a fractional portion get the right time of day + */ + public void testConvertDateTime() { + // Excel day 30000 is date 18-Feb-1982 + // 0.7 corresponds to time 16:48:00 + Date actual = HSSFDateUtil.getJavaDate(30000.7); + Date expected = createDate(1982, 1, 18, 16, 48, 0); + assertEquals(expected, actual); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java index 15ec903b4d..071e265bd7 100755 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFHyperlink.java @@ -42,14 +42,14 @@ public final class TestHSSFHyperlink extends TestCase { HSSFHyperlink link;
sheet = wb.getSheet("WebLinks");
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("POI", link.getLabel());
assertEquals("POI", cell.getRichStringCellValue().getString());
assertEquals("http://poi.apache.org/", link.getAddress());
- cell = sheet.getRow(8).getCell((short)0);
+ cell = sheet.getRow(8).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("HSSF", link.getLabel());
@@ -57,7 +57,7 @@ public final class TestHSSFHyperlink extends TestCase { assertEquals("http://poi.apache.org/hssf/", link.getAddress());
sheet = wb.getSheet("Emails");
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("dev", link.getLabel());
@@ -65,7 +65,7 @@ public final class TestHSSFHyperlink extends TestCase { assertEquals("mailto:dev@poi.apache.org", link.getAddress());
sheet = wb.getSheet("Internal");
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("Link To First Sheet", link.getLabel());
@@ -81,7 +81,7 @@ public final class TestHSSFHyperlink extends TestCase { HSSFHyperlink link;
sheet = wb.getSheet("WebLinks");
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
//modify the link
link.setAddress("www.apache.org");
@@ -92,7 +92,7 @@ public final class TestHSSFHyperlink extends TestCase { wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
sheet = wb.getSheet("WebLinks");
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("www.apache.org", link.getAddress());
@@ -106,21 +106,21 @@ public final class TestHSSFHyperlink extends TestCase { HSSFSheet sheet = wb.createSheet("Hyperlinks");
//URL
- cell = sheet.createRow(0).createCell((short)0);
+ cell = sheet.createRow(0).createCell(0);
cell.setCellValue("URL Link");
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/");
cell.setHyperlink(link);
//link to a file in the current directory
- cell = sheet.createRow(1).createCell((short)0);
+ cell = sheet.createRow(1).createCell(0);
cell.setCellValue("File Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
link.setAddress("link1.xls");
cell.setHyperlink(link);
//e-mail link
- cell = sheet.createRow(2).createCell((short)0);
+ cell = sheet.createRow(2).createCell(0);
cell.setCellValue("Email Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
//note, if subject contains white spaces, make sure they are url-encoded
@@ -131,9 +131,9 @@ public final class TestHSSFHyperlink extends TestCase { //create a target sheet and cell
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
- sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
+ sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
- cell = sheet.createRow(3).createCell((short)0);
+ cell = sheet.createRow(3).createCell(0);
cell.setCellValue("Worksheet Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link.setAddress("'Target Sheet'!A1");
@@ -145,22 +145,22 @@ public final class TestHSSFHyperlink extends TestCase { wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
sheet = wb.getSheet("Hyperlinks");
- cell = sheet.getRow(0).getCell((short)0);
+ cell = sheet.getRow(0).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("http://poi.apache.org/", link.getAddress());
- cell = sheet.getRow(1).getCell((short)0);
+ cell = sheet.getRow(1).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("link1.xls", link.getAddress());
- cell = sheet.getRow(2).getCell((short)0);
+ cell = sheet.getRow(2).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("mailto:poi@apache.org?subject=Hyperlinks", link.getAddress());
- cell = sheet.getRow(3).getCell((short)0);
+ cell = sheet.getRow(3).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("'Target Sheet'!A1", link.getAddress());
@@ -174,12 +174,12 @@ public final class TestHSSFHyperlink extends TestCase { HSSFSheet sheet = wb.cloneSheet(0);
- cell = sheet.getRow(4).getCell((short)0);
+ cell = sheet.getRow(4).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("http://poi.apache.org/", link.getAddress());
- cell = sheet.getRow(8).getCell((short)0);
+ cell = sheet.getRow(8).getCell(0);
link = cell.getHyperlink();
assertNotNull(link);
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java index b998fdd519..a3efa0393d 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFOptimiser.java @@ -107,13 +107,13 @@ public class TestHSSFOptimiser extends TestCase { HSSFRichTextString rtr1 = new HSSFRichTextString("Test"); rtr1.applyFont(0, 2, f1); rtr1.applyFont(3, 4, f2); - r.createCell((short)0).setCellValue(rtr1); + r.createCell(0).setCellValue(rtr1); HSSFRichTextString rtr2 = new HSSFRichTextString("AlsoTest"); rtr2.applyFont(0, 2, f3); rtr2.applyFont(3, 5, f5); rtr2.applyFont(6, 8, f6); - r.createCell((short)1).setCellValue(rtr2); + r.createCell(1).setCellValue(rtr2); // Check what we have now @@ -198,14 +198,14 @@ public class TestHSSFOptimiser extends TestCase { HSSFSheet s = wb.createSheet(); HSSFRow r = s.createRow(0); - r.createCell((short)0).setCellStyle(cs1); - r.createCell((short)1).setCellStyle(cs2); - r.createCell((short)2).setCellStyle(cs3); - r.createCell((short)3).setCellStyle(cs4); - r.createCell((short)4).setCellStyle(cs5); - r.createCell((short)5).setCellStyle(cs6); - r.createCell((short)6).setCellStyle(cs1); - r.createCell((short)7).setCellStyle(cs2); + r.createCell(0).setCellStyle(cs1); + r.createCell(1).setCellStyle(cs2); + r.createCell(2).setCellStyle(cs3); + r.createCell(3).setCellStyle(cs4); + r.createCell(4).setCellStyle(cs5); + r.createCell(5).setCellStyle(cs6); + r.createCell(6).setCellStyle(cs1); + r.createCell(7).setCellStyle(cs2); assertEquals(21, r.getCell(0).getCellValueRecord().getXFIndex()); assertEquals(26, r.getCell(5).getCellValueRecord().getXFIndex()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java index c3c0ed2259..3ce255a0e4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java @@ -94,11 +94,11 @@ public final class TestHSSFPalette extends TestCase { HSSFPalette p = book.getCustomPalette(); - HSSFCell cellA = book.getSheetAt(0).getRow(0).getCell((short)0); - HSSFCell cellB = book.getSheetAt(0).getRow(1).getCell((short)0); - HSSFCell cellC = book.getSheetAt(0).getRow(2).getCell((short)0); - HSSFCell cellD = book.getSheetAt(0).getRow(3).getCell((short)0); - HSSFCell cellE = book.getSheetAt(0).getRow(4).getCell((short)0); + HSSFCell cellA = book.getSheetAt(0).getRow(0).getCell(0); + HSSFCell cellB = book.getSheetAt(0).getRow(1).getCell(0); + HSSFCell cellC = book.getSheetAt(0).getRow(2).getCell(0); + HSSFCell cellD = book.getSheetAt(0).getRow(3).getCell(0); + HSSFCell cellE = book.getSheetAt(0).getRow(4).getCell(0); // Plain assertEquals("I'm plain", cellA.getStringCellValue()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java index b09753bcbd..c9b3bc74d1 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java @@ -36,16 +36,16 @@ public final class TestHSSFRow extends TestCase { assertEquals(-1, row.getFirstCellNum()); assertEquals(-1, row.getLastCellNum()); - row.createCell((short) 2); + row.createCell(2); assertEquals(2, row.getFirstCellNum()); assertEquals(3, row.getLastCellNum()); - row.createCell((short) 1); + row.createCell(1); assertEquals(1, row.getFirstCellNum()); assertEquals(3, row.getLastCellNum()); // check the exact case reported in 'bug' 43901 - notice that the cellNum is '0' based - row.createCell((short) 3); + row.createCell(3); assertEquals(1, row.getFirstCellNum()); assertEquals(4, row.getLastCellNum()); } @@ -59,20 +59,20 @@ public final class TestHSSFRow extends TestCase { HSSFSheet sheet = workbook.createSheet(); HSSFRow rowA = sheet.createRow(0); - rowA.createCell((short) 10); - rowA.createCell((short) 5); + rowA.createCell(10); + rowA.createCell(5); assertEquals(5, rowA.getFirstCellNum()); assertEquals(11, rowA.getLastCellNum()); HSSFRow rowB = sheet.createRow(1); - rowB.createCell((short) 15); - rowB.createCell((short) 30); + rowB.createCell(15); + rowB.createCell(30); assertEquals(15, rowB.getFirstCellNum()); assertEquals(31, rowB.getLastCellNum()); assertEquals(5, rowA.getFirstCellNum()); assertEquals(11, rowA.getLastCellNum()); - rowA.createCell((short) 50); + rowA.createCell(50); assertEquals(51, rowA.getLastCellNum()); assertEquals(31, rowB.getLastCellNum()); @@ -81,19 +81,19 @@ public final class TestHSSFRow extends TestCase { public void testRemoveCell() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); - HSSFRow row = sheet.createRow((short) 0); + HSSFRow row = sheet.createRow(0); assertEquals(-1, row.getLastCellNum()); assertEquals(-1, row.getFirstCellNum()); - row.createCell((short) 1); + row.createCell(1); assertEquals(2, row.getLastCellNum()); assertEquals(1, row.getFirstCellNum()); - row.createCell((short) 3); + row.createCell(3); assertEquals(4, row.getLastCellNum()); assertEquals(1, row.getFirstCellNum()); - row.removeCell(row.getCell((short) 3)); + row.removeCell(row.getCell(3)); assertEquals(2, row.getLastCellNum()); assertEquals(1, row.getFirstCellNum()); - row.removeCell(row.getCell((short) 1)); + row.removeCell(row.getCell(1)); assertEquals(-1, row.getLastCellNum()); assertEquals(-1, row.getFirstCellNum()); @@ -114,18 +114,18 @@ public final class TestHSSFRow extends TestCase { public void testMoveCell() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); - HSSFRow row = sheet.createRow((short) 0); - HSSFRow rowB = sheet.createRow((short) 1); + HSSFRow row = sheet.createRow(0); + HSSFRow rowB = sheet.createRow(1); - HSSFCell cellA2 = rowB.createCell((short)0); + HSSFCell cellA2 = rowB.createCell(0); assertEquals(0, rowB.getFirstCellNum()); assertEquals(0, rowB.getFirstCellNum()); assertEquals(-1, row.getLastCellNum()); assertEquals(-1, row.getFirstCellNum()); - HSSFCell cellB2 = row.createCell((short) 1); - HSSFCell cellB3 = row.createCell((short) 2); - HSSFCell cellB4 = row.createCell((short) 3); + HSSFCell cellB2 = row.createCell(1); + HSSFCell cellB3 = row.createCell(2); + HSSFCell cellB4 = row.createCell(3); assertEquals(1, row.getFirstCellNum()); assertEquals(4, row.getLastCellNum()); @@ -147,10 +147,10 @@ public final class TestHSSFRow extends TestCase { } // Move somewhere spare - assertNotNull(row.getCell((short)1)); + assertNotNull(row.getCell(1)); row.moveCell(cellB2, (short)5); - assertNull(row.getCell((short)1)); - assertNotNull(row.getCell((short)5)); + assertNull(row.getCell(1)); + assertNotNull(row.getCell(5)); assertEquals(5, cellB2.getCellNum()); assertEquals(2, row.getFirstCellNum()); @@ -161,7 +161,7 @@ public final class TestHSSFRow extends TestCase { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); //Test low row bound - sheet.createRow( (short) 0); + sheet.createRow(0); //Test low row bound exception try { sheet.createRow(-1); @@ -200,9 +200,9 @@ public final class TestHSSFRow extends TestCase { // Create two cells, will return one higher // than that for the last number - row.createCell((short) 0); + row.createCell(0); assertEquals(1, row.getLastCellNum()); - row.createCell((short) 255); + row.createCell(255); assertEquals(256, row.getLastCellNum()); } @@ -220,10 +220,10 @@ public final class TestHSSFRow extends TestCase { // 3 missing // 4 -> blank // 5 -> num - row.createCell((short)0).setCellValue(new HSSFRichTextString("test")); - row.createCell((short)1).setCellValue(3.2); - row.createCell((short)4, HSSFCell.CELL_TYPE_BLANK); - row.createCell((short)5).setCellValue(4); + row.createCell(0).setCellValue(new HSSFRichTextString("test")); + row.createCell(1).setCellValue(3.2); + row.createCell(4, HSSFCell.CELL_TYPE_BLANK); + row.createCell(5).setCellValue(4); // First up, no policy given, uses default assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType()); @@ -281,12 +281,12 @@ public final class TestHSSFRow extends TestCase { public void testRowHeight() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); - HSSFRow row1 = sheet.createRow( (short) 0); + HSSFRow row1 = sheet.createRow(0); assertEquals(0xFF, row1.getHeight()); assertEquals(sheet.getDefaultRowHeight(), row1.getHeight()); - HSSFRow row2 = sheet.createRow( (short) 1); + HSSFRow row2 = sheet.createRow(1); row2.setHeight((short)400); assertEquals(400, row2.getHeight()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index a24e5e7970..4c8c8c5d6a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -147,10 +147,10 @@ public final class TestHSSFSheet extends TestCase { public void testReadBooleans() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Test boolean"); - HSSFRow row = sheet.createRow((short) 2); - HSSFCell cell = row.createCell((short) 9); + HSSFRow row = sheet.createRow(2); + HSSFCell cell = row.createCell(9); cell.setCellValue(true); - cell = row.createCell((short) 11); + cell = row.createCell(11); cell.setCellValue(true); workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook); @@ -164,7 +164,7 @@ public final class TestHSSFSheet extends TestCase { public void testRemoveRow() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Test boolean"); - HSSFRow row = sheet.createRow((short) 2); + HSSFRow row = sheet.createRow(2); sheet.removeRow(row); } @@ -186,8 +186,8 @@ public final class TestHSSFSheet extends TestCase { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Test Clone"); HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell((short) 0); - HSSFCell cell2 = row.createCell((short) 1); + HSSFCell cell = row.createCell(0); + HSSFCell cell2 = row.createCell(1); cell.setCellValue(new HSSFRichTextString("clone_test")); cell2.setCellFormula("sin(1)"); @@ -216,8 +216,8 @@ public final class TestHSSFSheet extends TestCase { public void testCloneSheetMultipleTimes() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Test Clone"); - HSSFRow row = sheet.createRow((short) 0); - HSSFCell cell = row.createCell((short) 0); + HSSFRow row = sheet.createRow(0); + HSSFCell cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("clone_test")); //Clone the sheet multiple times workbook.cloneSheet(0); @@ -510,11 +510,11 @@ public final class TestHSSFSheet extends TestCase { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell((short)0); + HSSFCell cell = row.createCell(0); cell.setCellValue(new HSSFRichTextString("first row, first cell")); row = sheet.createRow(1); - cell = row.createCell((short)1); + cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString("second row, second cell")); CellRangeAddress region = new CellRangeAddress(1, 1, 0, 1); @@ -617,13 +617,13 @@ public final class TestHSSFSheet extends TestCase { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet("Sheet1"); HSSFRow r = s.createRow(0); - r.createCell((short) 0).setCellValue(1); - r.createCell((short) 1).setCellFormula("A1*2"); + r.createCell(0).setCellValue(1); + r.createCell(1).setCellFormula("A1*2"); HSSFSheet s1 = wb.cloneSheet(0); r = s1.getRow(0); - assertEquals("double", r.getCell((short) 0).getNumericCellValue(), 1, 0); // sanity check - assertNotNull(r.getCell((short) 1)); - assertEquals("formula", r.getCell((short) 1).getCellFormula(), "A1*2"); + assertEquals("double", r.getCell(0).getNumericCellValue(), 1, 0); // sanity check + assertNotNull(r.getCell(1)); + assertEquals("formula", r.getCell(1).getCellFormula(), "A1*2"); } /** test that new default column styles get applied */ @@ -633,7 +633,7 @@ public final class TestHSSFSheet extends TestCase { HSSFSheet s = wb.createSheet(); s.setDefaultColumnStyle((short) 0, style); HSSFRow r = s.createRow(0); - HSSFCell c = r.createCell((short) 0); + HSSFCell c = r.createCell(0); assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex()); } @@ -710,8 +710,8 @@ public final class TestHSSFSheet extends TestCase { HSSFSheet sheet = workbook.getSheetAt(0); HSSFSheet sheet2 = workbook.getSheetAt(0); HSSFRow row = sheet.getRow(0); - row.createCell((short) 0).setCellValue(5); - row.createCell((short) 1).setCellValue(8); + row.createCell(0).setCellValue(5); + row.createCell(1).setCellValue(8); assertFalse(sheet.getForceFormulaRecalculation()); assertFalse(sheet2.getForceFormulaRecalculation()); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 35a2d955fb..658a3f4884 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -290,10 +290,10 @@ public final class TestHSSFWorkbook extends TestCase { assertEquals(true, sheet3.isActive()); if (false) { // helpful if viewing this workbook in excel: - sheet1.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet1")); - sheet2.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet2")); - sheet3.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet3")); - sheet4.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet4")); + sheet1.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet1")); + sheet2.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet2")); + sheet3.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet3")); + sheet4.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Sheet4")); try { File fOut = TempFile.createTempFile("sheetMultiSelect", ".xls"); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java index 342f6e26f1..186ee18a6b 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestReadWriteChart.java @@ -39,14 +39,14 @@ public final class TestReadWriteChart extends TestCase { HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls"); HSSFSheet sheet = workbook.getSheetAt(0); HSSFRow firstRow = sheet.getRow(0); - HSSFCell firstCell = firstRow.getCell(( short ) 0); + HSSFCell firstCell = firstRow.getCell(0); //System.out.println("first assertion for date"); assertEquals(new GregorianCalendar(2000, 0, 1, 10, 51, 2).getTime(), HSSFDateUtil .getJavaDate(firstCell.getNumericCellValue(), false)); - HSSFRow row = sheet.createRow(( short ) 15); - HSSFCell cell = row.createCell(( short ) 1); + HSSFRow row = sheet.createRow(15); + HSSFCell cell = row.createCell(1); cell.setCellValue(22); Sheet newSheet = workbook.getSheetAt(0).getSheet(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java index 62a26e90b5..ddd9101593 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetHiding.java @@ -61,10 +61,10 @@ public final class TestSheetHiding extends TestCase { assertEquals(1, wbU.getSheetAt(1).getRow(0).getLastCellNum()); // Text should be sheet based - assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); - assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); - assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell((short)0).getRichStringCellValue().getString()); - assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell((short)0).getRichStringCellValue().getString()); + assertEquals("Sheet1A1", wbH.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString()); + assertEquals("Sheet2A1", wbH.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString()); + assertEquals("Sheet1A1", wbU.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().getString()); + assertEquals("Sheet2A1", wbU.getSheetAt(1).getRow(0).getCell(0).getRichStringCellValue().getString()); } /** diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java index 03d67cc21c..101bd325df 100755 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestSheetShiftRows.java @@ -99,8 +99,8 @@ public final class TestSheetShiftRows extends TestCase { public void testShiftRow(){ HSSFWorkbook b = new HSSFWorkbook(); HSSFSheet s = b.createSheet(); - s.createRow(0).createCell((short)0).setCellValue("TEST1"); - s.createRow(3).createCell((short)0).setCellValue("TEST2"); + s.createRow(0).createCell(0).setCellValue("TEST1"); + s.createRow(3).createCell(0).setCellValue("TEST2"); s.shiftRows(0,4,1); } @@ -112,8 +112,8 @@ public final class TestSheetShiftRows extends TestCase { public void testShiftRow0(){ HSSFWorkbook b = new HSSFWorkbook(); HSSFSheet s = b.createSheet(); - s.createRow(0).createCell((short)0).setCellValue("TEST1"); - s.createRow(3).createCell((short)0).setCellValue("TEST2"); + s.createRow(0).createCell(0).setCellValue("TEST1"); + s.createRow(3).createCell(0).setCellValue("TEST2"); s.shiftRows(0,4,1); } @@ -125,7 +125,7 @@ public final class TestSheetShiftRows extends TestCase { HSSFWorkbook b = new HSSFWorkbook(); HSSFSheet s = b.createSheet(); HSSFRow row = s.createRow(4); - row.createCell((short)0).setCellValue("test"); + row.createCell(0).setCellValue("test"); s.setRowBreak(4); s.shiftRows(4, 4, 2); @@ -203,34 +203,34 @@ public final class TestSheetShiftRows extends TestCase { HSSFSheet sheet = wb.getSheet("Sheet1"); assertEquals(19, sheet.getLastRowNum()); - assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula()); - assertEquals("cell B2 (ref)", sheet.getRow(1).getCell((short)3).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(1).getCell((short)3).getCellFormula()); - assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula()); - assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula()); + assertEquals("cell B1 (ref)", sheet.getRow(0).getCell(3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell(3).getCellFormula()); + assertEquals("cell B2 (ref)", sheet.getRow(1).getCell(3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(1).getCell(3).getCellFormula()); + assertEquals("cell B3 (ref)", sheet.getRow(2).getCell(3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell(3).getCellFormula()); + assertEquals("cell B2 (ref)", sheet.getRow(6).getCell(1).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B2,\" (ref)\")", sheet.getRow(6).getCell(1).getCellFormula()); sheet.shiftRows(1, 1, 10); // Row 1 => Row 11 // So strings on row 11 unchanged, but reference in formula is - assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula()); + assertEquals("cell B1 (ref)", sheet.getRow(0).getCell(3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell(3).getCellFormula()); assertEquals(0, sheet.getRow(1).getPhysicalNumberOfCells()); // still save b2 - assertEquals("cell B2 (ref)", sheet.getRow(11).getCell((short)3).getRichStringCellValue().toString()); + assertEquals("cell B2 (ref)", sheet.getRow(11).getCell(3).getRichStringCellValue().toString()); // but points to b12 - assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell((short)3).getCellFormula()); + assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell(3).getCellFormula()); - assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula()); + assertEquals("cell B3 (ref)", sheet.getRow(2).getCell(3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell(3).getCellFormula()); // one on a non-shifted row also updated - assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString()); - assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula()); + assertEquals("cell B2 (ref)", sheet.getRow(6).getCell(1).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell(1).getCellFormula()); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java index d67c3f4693..2a92152857 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnicodeWorkbook.java @@ -57,14 +57,14 @@ public class TestUnicodeWorkbook extends TestCase { f.setRight("\u20ac"); HSSFRow r = s.createRow(0); - HSSFCell c = r.createCell((short)1); + HSSFCell c = r.createCell(1); c.setCellValue(12.34); c.getCellStyle().setDataFormat(fmt); - HSSFCell c2 = r.createCell((short)2); + HSSFCell c2 = r.createCell(2); c.setCellValue(new HSSFRichTextString("\u20ac")); - HSSFCell c3 = r.createCell((short)3); + HSSFCell c3 = r.createCell(3); String formulaString = "TEXT(12.34,\"\u20ac###,##\")"; c3.setCellFormula(formulaString); @@ -95,16 +95,16 @@ public class TestUnicodeWorkbook extends TestCase { //Test the dataformat r = s.getRow(0); - c = r.getCell((short)1); + c = r.getCell(1); df = wb.createDataFormat(); assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat())); //Test the cell string value - c2 = r.getCell((short)2); + c2 = r.getCell(2); assertEquals(c.getRichStringCellValue().getString(), "\u20ac"); //Test the cell formula - c3 = r.getCell((short)3); + c3 = r.getCell(3); assertEquals(c3.getCellFormula(), formulaString); } @@ -122,7 +122,7 @@ public class TestUnicodeWorkbook extends TestCase { HSSFSheet s = wb.createSheet("test"); HSSFRow r = s.createRow(0); - HSSFCell c = r.createCell((short)1); + HSSFCell c = r.createCell(1); c.setCellValue(new HSSFRichTextString("\u00e4")); //Confirm that the sring will be compressed @@ -140,7 +140,7 @@ public class TestUnicodeWorkbook extends TestCase { s = wb.getSheet("test"); assertNotNull(s); - c = r.getCell((short)1); + c = r.getCell(1); assertEquals(c.getRichStringCellValue().getString(), "\u00e4"); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java index c0231cdfea..c6fa2ee0d9 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java @@ -96,7 +96,7 @@ public final class TestWorkbook extends TestCase { c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); - c = r.createCell(( short ) (cellnum + 1)); + c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); } } @@ -142,7 +142,7 @@ public final class TestWorkbook extends TestCase { c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); - c = r.createCell(( short ) (cellnum + 1)); + c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); } } @@ -226,8 +226,8 @@ public final class TestWorkbook extends TestCase { short df = format.getFormat("0.0"); cs.setDataFormat(df); - r = s.createRow((short)0); - c = r.createCell((short)0); + r = s.createRow(0); + c = r.createCell(0); c.setCellStyle(cs); c.setCellValue(1.25); @@ -239,7 +239,7 @@ public final class TestWorkbook extends TestCase { HSSFWorkbook workbook = new HSSFWorkbook(fs); HSSFSheet sheet = workbook.getSheetAt(0); HSSFCell cell = - sheet.getRow(( short ) 0).getCell(( short ) 0); + sheet.getRow(0).getCell(0); format = workbook.createDataFormat(); assertEquals(1.25,cell.getNumericCellValue(), 1e-10); @@ -350,7 +350,7 @@ public final class TestWorkbook extends TestCase { for (int k = 0; k < 4; k++) { - HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0); + HSSFCell cell = sheet.getRow(k).getCell(0); cell.setCellValue(new HSSFRichTextString(REPLACED)); } @@ -360,7 +360,7 @@ public final class TestWorkbook extends TestCase { sheet = workbook.getSheetAt(0); for (int k = 0; k < 4; k++) { - HSSFCell cell = sheet.getRow(( short ) k).getCell(( short ) 0); + HSSFCell cell = sheet.getRow(k).getCell(0); assertEquals(REPLACED, cell.getRichStringCellValue().getString()); } @@ -439,7 +439,7 @@ public final class TestWorkbook extends TestCase { c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); - c = r.createCell(( short ) (cellnum + 1)); + c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); } } @@ -530,7 +530,7 @@ public final class TestWorkbook extends TestCase { for ( i = 0, j = 32771; j > 0; i++, j-- ) { row = sheet.createRow(i); - cell = row.createCell((short) 0); + cell = row.createCell(0); cell.setCellValue(i); } sanityChecker.checkHSSFWorkbook(workbook); @@ -556,7 +556,7 @@ public final class TestWorkbook extends TestCase { HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell((short)1); + HSSFCell cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString("hi")); |