diff options
author | Nick Burch <nick@apache.org> | 2008-05-20 16:30:19 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2008-05-20 16:30:19 +0000 |
commit | 2e8acca69befd81380acb352335cf545bb6effc6 (patch) | |
tree | 3661e99ee6f20144c63f5e8cfed11e0a3e9531f5 /src/testcases | |
parent | 40bb917404193b6a9bdda09e1b3ebb09fe01867a (diff) | |
download | poi-2e8acca69befd81380acb352335cf545bb6effc6.tar.gz poi-2e8acca69befd81380acb352335cf545bb6effc6.zip |
Support for specifying a policy to HSSF on missing / blank cells when fetching
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@658308 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java index 7611abb51c..d307a0e251 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java @@ -204,4 +204,64 @@ public final class TestHSSFRow extends TestCase { row.createCell((short) 255); assertEquals(256, row.getLastCellNum()); } + + /** + * Tests for the missing/blank cell policy stuff + */ + public void testGetCellPolicy() throws Exception { + HSSFWorkbook book = new HSSFWorkbook(); + HSSFSheet sheet = book.createSheet("test"); + HSSFRow row = sheet.createRow(0); + + // 0 -> string + // 1 -> num + // 2 missing + // 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); + + // First up, no policy + assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); + assertEquals(null, row.getCell(2)); + assertEquals(null, row.getCell(3)); + assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType()); + + // RETURN_NULL_AND_BLANK - same as default + assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); + assertEquals(null, row.getCell(2, HSSFRow.RETURN_NULL_AND_BLANK)); + assertEquals(null, row.getCell(3, HSSFRow.RETURN_NULL_AND_BLANK)); + assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); + + // RETURN_BLANK_AS_NULL - nearly the same + assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); + assertEquals(null, row.getCell(2, HSSFRow.RETURN_BLANK_AS_NULL)); + assertEquals(null, row.getCell(3, HSSFRow.RETURN_BLANK_AS_NULL)); + assertEquals(null, row.getCell(4, HSSFRow.RETURN_BLANK_AS_NULL)); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); + + // CREATE_NULL_AS_BLANK - creates as needed + assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); + + // Check created ones get the right column + assertEquals((short)0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + assertEquals((short)1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + assertEquals((short)2, row.getCell(2, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + assertEquals((short)3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + assertEquals((short)4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + assertEquals((short)5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellNum()); + } } |