<changes>
<release version="3.8-beta6" date="2012-??-??">
+ <action dev="poi-developers" type="fix">52784 - replace ISO control characters with question marks in SXSSF to be consistent with XSSF </action>
<action dev="poi-developers" type="add">52057 - updated formula test framework to be aware of recently added Functions </action>
<action dev="poi-developers" type="add">52574 - support setting header / footer page margins in HSSF </action>
<action dev="poi-developers" type="add">52583 - fixed WorkbookUtil#createSafeSheetName to escape colon </action>
break;\r
// Special characters\r
case '\n':\r
+ case '\r':\r
if (counter > last) {\r
_out.write(chars, last, counter - last);\r
}\r
_out.write("	");\r
last = counter + 1;\r
break;\r
- case '\r':\r
- if (counter > last) {\r
- _out.write(chars, last, counter - last);\r
- }\r
- _out.write("
");\r
- last = counter + 1;\r
- break;\r
case 0xa0:\r
if (counter > last) {\r
_out.write(chars, last, counter - last);\r
last = counter + 1;\r
break;\r
default:\r
- if (c < ' ' || c > 127) {\r
+ // YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks.\r
+ // the same rule applies to unicode surrogates and "not a character" symbols.\r
+ if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) ||\r
+ ('\uFFFE' <= c && c <= '\uFFFF')) {\r
+ _out.write('?');\r
+ last = counter + 1;\r
+ }\r
+ else if (c > 127) {\r
if (counter > last) {\r
_out.write(chars, last, counter - last);\r
}\r
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
Sheet sh = wb.createSheet();
Row row = sh.createRow(0);
Cell cell = row.createCell(0);
- String sval = "<>\t\r\n\u00a0 &\"POI\'\u2122";
+ String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI\'\u2122";
cell.setCellValue(sval);
wb = _testDataProvider.writeOutAndReadBack(wb);
- assertEquals(sval, wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+ // invalid characters are replaced with question marks
+ assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+
+ }
+
+ public void testEncodingbeloAscii(){
+ Workbook xwb = new XSSFWorkbook();
+ Cell xCell = xwb.createSheet().createRow(0).createCell(0);
+
+ Workbook swb = new SXSSFWorkbook();
+ Cell sCell = swb.createSheet().createRow(0).createCell(0);
+
+ StringBuffer sb = new StringBuffer();
+ // test all possible characters
+ for(int i = 0; i < Character.MAX_VALUE; i++) sb.append((char)i) ;
+
+ String str = sb.toString();
+
+ xCell.setCellValue(str);
+ assertEquals(str, xCell.getStringCellValue());
+ sCell.setCellValue(str);
+ assertEquals(str, sCell.getStringCellValue());
+
+ xwb = XSSFITestDataProvider.instance.writeOutAndReadBack(xwb);
+ swb = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
+ xCell = xwb.getSheetAt(0).createRow(0).createCell(0);
+ sCell = swb.getSheetAt(0).createRow(0).createCell(0);
+
+ assertEquals(xCell.getStringCellValue(), sCell.getStringCellValue());
}
}