From: Avik Sengupta Date: Thu, 1 Jan 2004 19:08:43 +0000 (+0000) Subject: fix for bug 25695 X-Git-Tag: REL_2_5_1~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0cbd3ec4876f7904c7508ca1dd44c4a99249bbe;p=poi.git fix for bug 25695 git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353479 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/StringRecord.java b/src/java/org/apache/poi/hssf/record/StringRecord.java index 914a92d8e3..cea9d0585c 100644 --- a/src/java/org/apache/poi/hssf/record/StringRecord.java +++ b/src/java/org/apache/poi/hssf/record/StringRecord.java @@ -130,7 +130,7 @@ public class StringRecord field_2_unicode_flag = data[ 2 + offset ]; if (isUnCompressedUnicode()) { - field_3_string = StringUtil.getFromUnicode(data, 3 + offset, field_1_string_length ); + field_3_string = StringUtil.getFromUnicodeHigh(data, 3 + offset, field_1_string_length ); } else { diff --git a/src/testcases/org/apache/poi/hssf/data/25695.xls b/src/testcases/org/apache/poi/hssf/data/25695.xls new file mode 100644 index 0000000000..08b5035664 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/25695.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index b211f05f9f..87af335784 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -438,6 +438,62 @@ extends TestCase { //make sure we dont exception } + + /*Tests read and write of Unicode strings in formula results + * bug and testcase submitted by Sompop Kumnoonsate + * The file contains THAI unicode characters. + */ + public void testUnicodeStringFormulaRead() throws Exception { + + String filename = System.getProperty("HSSF.testdata.path"); + filename=filename+"/25695.xls"; + FileInputStream in = new FileInputStream(filename); + HSSFWorkbook w; + w = new HSSFWorkbook(in); + in.close(); + + HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell((short) 0); + HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell((short) 1); + HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell((short) 0); + HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell((short) 1); + HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell((short) 0); + HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell((short) 1); + HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell((short) 0); + HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell((short) 1); + + assertEquals("String Cell value", a1.getStringCellValue(), a2.getStringCellValue()); + assertEquals("String Cell value", b1.getStringCellValue(), b2.getStringCellValue()); + assertEquals("String Cell value", c1.getStringCellValue(), c2.getStringCellValue()); + assertEquals("String Cell value", d1.getStringCellValue(), d2.getStringCellValue()); + + File xls = File.createTempFile("testFormulaUnicode", ".xls"); + FileOutputStream out = new FileOutputStream(xls); + w.write(out); + out.close(); + in = new FileInputStream(xls); + + HSSFWorkbook rw = new HSSFWorkbook(in); + in.close(); + + HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell((short) 0); + HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell((short) 1); + HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell((short) 0); + HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell((short) 1); + HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell((short) 0); + HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell((short) 1); + HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell((short) 0); + HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell((short) 1); + + assertEquals("Re-Written String Cell value", a1.getStringCellValue(), ra1.getStringCellValue()); + assertEquals("Re-Written String Cell value", b1.getStringCellValue(), rb1.getStringCellValue()); + assertEquals("Re-Written String Cell value", c1.getStringCellValue(), rc1.getStringCellValue()); + assertEquals("Re-Written String Cell value", d1.getStringCellValue(), rd1.getStringCellValue()); + assertEquals("Re-Written Formula String Cell value", a1.getStringCellValue(), ra2.getStringCellValue()); + assertEquals("Re-Written Formula String Cell value", b1.getStringCellValue(), rb2.getStringCellValue()); + assertEquals("Re-Written Formula String Cell value", c1.getStringCellValue(), rc2.getStringCellValue()); + assertEquals("Re-Written Formula String Cell value", d1.getStringCellValue(), rd2.getStringCellValue()); + + } }