From 2e8acca69befd81380acb352335cf545bb6effc6 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 20 May 2008 16:30:19 +0000 Subject: 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 --- .../org/apache/poi/hssf/usermodel/TestHSSFRow.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java') 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()); + } } -- cgit v1.2.3