diff options
author | Avik Sengupta <avik@apache.org> | 2005-05-20 09:13:14 +0000 |
---|---|---|
committer | Avik Sengupta <avik@apache.org> | 2005-05-20 09:13:14 +0000 |
commit | faf02ec8d9b30e215f943a905b1530e4202ffab0 (patch) | |
tree | 04577b59265e6961cb8c22494e2f298329d6672f /src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java | |
parent | 7ba496912f5e55b35dac31bbc3217c29d1c810a2 (diff) | |
download | poi-faf02ec8d9b30e215f943a905b1530e4202ffab0.tar.gz poi-faf02ec8d9b30e215f943a905b1530e4202ffab0.zip |
toString() method for HSSFCell to return
a simple string representation of the cell,
irrespective of its type.
Originally submitted by Wes Gilster as bug 19294
made some modifications, added testcase.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353693 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index 03e2ddc5b1..e7cbb1558b 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -244,6 +244,42 @@ extends TestCase { in.close(); } + /*tests the toString() method of HSSFCell*/ + public void testToString() throws Exception { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet("Sheet1"); + HSSFRow r = s.createRow(0); + HSSFCell c; + c=r.createCell((short) 0); c.setCellValue(true); + assertEquals("Boolean", "TRUE", c.toString()); + c=r.createCell((short) 1); c.setCellValue(1.5); + assertEquals("Numeric", "1.5", c.toString()); + c=r.createCell((short)(2)); c.setCellValue("Astring"); + assertEquals("String", "Astring", c.toString()); + c=r.createCell((short) 3); c.setCellErrorValue((byte) 7); + assertEquals("Error", "#ERR7", c.toString()); + c=r.createCell((short)4); c.setCellFormula("A1+B1"); + assertEquals("Formula", "A1+B1", c.toString()); + + //Write out the file, read it in, and then check cell values + File f = File.createTempFile("testCellToString",".xls"); + wb.write(new FileOutputStream(f)); + wb = new HSSFWorkbook(new FileInputStream(f)); + assertTrue("File exists and can be read", f.canRead()); + + s = wb.getSheetAt(0);r=s.getRow(0); + c=r.getCell((short) 0); + assertEquals("Boolean", "TRUE", c.toString()); + c=r.getCell((short) 1); + assertEquals("Numeric", "1.5", c.toString()); + c=r.getCell((short)(2)); + assertEquals("String", "Astring", c.toString()); + c=r.getCell((short) 3); + assertEquals("Error", "#ERR7", c.toString()); + c=r.getCell((short)4); + assertEquals("Formula", "A1+B1", c.toString()); + } + public static void main(String [] args) { System.out .println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell"); |