use of org.apache.poi.ss.format.CellFormatResult in project poi by apache.
the class ToHtml method printSheetContent.
private void printSheetContent(Sheet sheet) {
printColumnHeads();
out.format("<tbody>%n");
Iterator<Row> rows = sheet.rowIterator();
while (rows.hasNext()) {
Row row = rows.next();
out.format(" <tr>%n");
out.format(" <td class=%s>%d</td>%n", ROW_HEAD_CLASS, row.getRowNum() + 1);
for (int i = firstColumn; i < endColumn; i++) {
String content = " ";
String attrs = "";
CellStyle style = null;
if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) {
Cell cell = row.getCell(i);
if (cell != null) {
style = cell.getCellStyle();
attrs = tagStyle(cell, style);
//Set the value that is rendered for the cell
//also applies the format
CellFormat cf = CellFormat.getInstance(style.getDataFormatString());
CellFormatResult result = cf.apply(cell);
content = result.text;
if (content.equals("")) {
content = " ";
}
}
}
out.format(" <td class=%s %s>%s</td>%n", styleName(style), attrs, content);
}
out.format(" </tr>%n");
}
out.format("</tbody>%n");
}
use of org.apache.poi.ss.format.CellFormatResult in project poi by apache.
the class TestDataFormatter method setUpClass.
@BeforeClass
@SuppressForbidden
public static void setUpClass() {
// some pre-checks to hunt for a problem in the Maven build
// these checks ensure that the correct locale is set, so a failure here
// usually indicates an invalid locale during test-execution
assertFalse(DateUtil.isADateFormat(-1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
Locale ul = LocaleUtil.getUserLocale();
assertTrue(Locale.ROOT.equals(ul) || Locale.getDefault().equals(ul));
final String textValue = NumberToTextConverter.toText(1234.56);
assertEquals(-1, textValue.indexOf('E'));
Object cellValueO = Double.valueOf(1234.56);
/*CellFormat cellFormat = new CellFormat("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
CellFormatResult result = cellFormat.apply(cellValueO);
assertEquals(" 1,234.56 ", result.text);*/
CellFormat cfmt = CellFormat.getInstance("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
CellFormatResult result = cfmt.apply(cellValueO);
assertEquals("This failure can indicate that the wrong locale is used during test-execution, ensure you run with english/US via -Duser.language=en -Duser.country=US", " 1,234.56 ", result.text);
}
Aggregations