Search in sources :

Example 1 with CellFormatResult

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 = "&nbsp;";
            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 = "&nbsp;";
                    }
                }
            }
            out.format("    <td class=%s %s>%s</td>%n", styleName(style), attrs, content);
        }
        out.format("  </tr>%n");
    }
    out.format("</tbody>%n");
}
Also used : CellFormat(org.apache.poi.ss.format.CellFormat) CellFormatResult(org.apache.poi.ss.format.CellFormatResult) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Cell(org.apache.poi.ss.usermodel.Cell)

Example 2 with CellFormatResult

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);
}
Also used : Locale(java.util.Locale) CellFormat(org.apache.poi.ss.format.CellFormat) CellFormatResult(org.apache.poi.ss.format.CellFormatResult) BeforeClass(org.junit.BeforeClass) SuppressForbidden(org.apache.poi.util.SuppressForbidden)

Aggregations

CellFormat (org.apache.poi.ss.format.CellFormat)2 CellFormatResult (org.apache.poi.ss.format.CellFormatResult)2 Locale (java.util.Locale)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 Row (org.apache.poi.ss.usermodel.Row)1 SuppressForbidden (org.apache.poi.util.SuppressForbidden)1 BeforeClass (org.junit.BeforeClass)1