TestUnicodeWorkbookpublic class TestUnicodeWorkbook extends TestCase
Constructors Summary |
---|
public TestUnicodeWorkbook(String s)
super(s);
|
Methods Summary |
---|
public void | testUmlatReadWrite()Tests Bug38230
That a Umlat is written and then read back.
It should have been written as a compressed unicode.
HSSFWorkbook wb = new HSSFWorkbook();
//Create a unicode sheet name (euro symbol)
HSSFSheet s = wb.createSheet("test");
HSSFRow r = s.createRow(0);
HSSFCell c = r.createCell((short)1);
c.setCellValue(new HSSFRichTextString("\u00e4"));
//Confirm that the sring will be compressed
assertEquals(c.getRichStringCellValue().getUnicodeString().getOptionFlags(), 0);
File tempFile = TempFile.createTempFile("umlat", "test.xls");
FileOutputStream stream = new FileOutputStream(tempFile);
wb.write(stream);
wb = null;
FileInputStream in = new FileInputStream(tempFile);
wb = new HSSFWorkbook(in);
//Test the sheetname
s = wb.getSheet("test");
assertNotNull(s);
c = r.getCell((short)1);
assertEquals(c.getRichStringCellValue().getString(), "\u00e4");
| public void | testUnicodeInAll()Tests that all of the unicode capable string fields can be set, written and then read back
HSSFWorkbook wb = new HSSFWorkbook();
//Create a unicode dataformat (contains euro symbol)
HSSFDataFormat df = wb.createDataFormat();
final String formatStr = "_([$\u20ac-2]\\\\\\ * #,##0.00_);_([$\u20ac-2]\\\\\\ * \\\\\\(#,##0.00\\\\\\);_([$\u20ac-2]\\\\\\ *\\\"\\-\\\\\"??_);_(@_)";
short fmt = df.getFormat(formatStr);
//Create a unicode sheet name (euro symbol)
HSSFSheet s = wb.createSheet("\u20ac");
//Set a unicode header (you guessed it the euro symbol)
HSSFHeader h = s.getHeader();
h.setCenter("\u20ac");
h.setLeft("\u20ac");
h.setRight("\u20ac");
//Set a unicode footer
HSSFFooter f = s.getFooter();
f.setCenter("\u20ac");
f.setLeft("\u20ac");
f.setRight("\u20ac");
HSSFRow r = s.createRow(0);
HSSFCell c = r.createCell((short)1);
c.setCellValue(12.34);
c.getCellStyle().setDataFormat(fmt);
HSSFCell c2 = r.createCell((short)2);
c.setCellValue(new HSSFRichTextString("\u20ac"));
HSSFCell c3 = r.createCell((short)3);
String formulaString = "TEXT(12.34,\"\u20ac###,##\")";
c3.setCellFormula(formulaString);
File tempFile = TempFile.createTempFile("unicode", "test.xls");
FileOutputStream stream = new FileOutputStream(tempFile);
wb.write(stream);
wb = null;
FileInputStream in = new FileInputStream(tempFile);
wb = new HSSFWorkbook(in);
//Test the sheetname
s = wb.getSheet("\u20ac");
assertNotNull(s);
//Test the header
h = s.getHeader();
assertEquals(h.getCenter(), "\u20ac");
assertEquals(h.getLeft(), "\u20ac");
assertEquals(h.getRight(), "\u20ac");
//Test the footer
f = s.getFooter();
assertEquals(f.getCenter(), "\u20ac");
assertEquals(f.getLeft(), "\u20ac");
assertEquals(f.getRight(), "\u20ac");
//Test the dataformat
r = s.getRow(0);
c = r.getCell((short)1);
df = wb.createDataFormat();
assertEquals(formatStr, df.getFormat(c.getCellStyle().getDataFormat()));
//Test the cell string value
c2 = r.getCell((short)2);
assertEquals(c.getRichStringCellValue().getString(), "\u20ac");
//Test the cell formula
c3 = r.getCell((short)3);
assertEquals(c3.getCellFormula(), formulaString);
|
|