我需要使用 Apache ODF Toolking 创建一个 ods 文档并格式化其单元格的内容。
我能够为日期和简单数字设置格式,但由于某种原因,当我尝试使用科学记数法进行格式化时,它不起作用。它无法解析字符串或将 E00 包装成“E00”
SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
document.removeSheet(0);
document.setLocale(Locale.US);
Table sheet = document.appendSheet("My chart");
List<Row> rows = sheet.appendRows(10);
sheet.getColumnByIndex(0).setWidth(27.06);
Row headerRow = rows.get(0);
headerRow.getCellByIndex(0).setStringValue("This is a string");
Row dateRow = rows.get(1);
Calendar date = GregorianCalendar.getInstance();
dateRow.getCellByIndex(0).setDateValue(date);
dateRow.getCellByIndex(0).setFormatString("yyyy-MM-dd");
Row numRow = rows.get(1);
numRow.getCellByIndex(0).setDoubleValue(9.12345678);
//numRow.getCellByIndex(0).setFormatString("0.000"); // works
//numRow.getCellByIndex(0).setFormatString("0.00E+00"); // crashes
numRow.getCellByIndex(0).setFormatString("0.00E00"); // does not work, it becomes 0.00"E00"
document.save(new File("c:\\Users\\enrico\\Desktop\\openoffice.ods"));
如果有人可以提供帮助,我将不胜感激,谢谢。
完整代码在这里https://gist.github.com/EnricoScantamburlo/b06d3a9e52682276b8ca4f6bf51e6f6a