Search in sources :

Example 11 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class TestTextObjectRecord method testWriteEmpty.

/**
     * Zero {@link ContinueRecord}s follow a {@link TextObjectRecord} if the text is empty
     */
public void testWriteEmpty() {
    HSSFRichTextString str = new HSSFRichTextString("");
    TextObjectRecord record = new TextObjectRecord();
    record.setStr(str);
    byte[] ser = record.serialize();
    int formatDataLen = LittleEndian.getUShort(ser, 16);
    assertEquals("formatDataLength", 0, formatDataLen);
    // just the TXO record
    assertEquals(22, ser.length);
    //read again
    RecordInputStream is = TestcaseRecordInputStream.create(ser);
    record = new TextObjectRecord(is);
    assertEquals(0, record.getStr().length());
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 12 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class TestTextObjectRecord method testLongRecords.

/**
     * Test that TextObjectRecord serializes logs records properly.
     */
public void testLongRecords() {
    //test against strings of different length
    int[] lengths = { 1024, 2048, 4096, 8192, 16384 };
    for (int length : lengths) {
        StringBuffer buff = new StringBuffer(length);
        for (int j = 0; j < length; j++) {
            buff.append("x");
        }
        HSSFRichTextString str = new HSSFRichTextString(buff.toString());
        TextObjectRecord obj = new TextObjectRecord();
        obj.setStr(str);
        byte[] data = obj.serialize();
        RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
        is.nextRecord();
        TextObjectRecord record = new TextObjectRecord(is);
        str = record.getStr();
        assertEquals(buff.length(), str.length());
        assertEquals(buff.toString(), str.getString());
    }
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project processdash by dtuma.

the class WBSExcelWriter method copyCellData.

private void copyCellData(HSSFCell cell, TableCellRenderer rend, Component comp, Object value) {
    StyleKey style = new StyleKey();
    String text = null;
    if (comp instanceof JLabel) {
        JLabel label = (JLabel) comp;
        text = label.getText();
        text = stripHtml(text);
    }
    Object unwrapped = WrappedValue.unwrap(value);
    if (unwrapped instanceof Date) {
        // POI-exported dates seem to freak Excel out for some reason.
        // to workaround, we export a string.
        Date date = (Date) unwrapped;
        text = DATE_FORMATTER.format(date);
        cell.setCellValue(new HSSFRichTextString(text));
    } else if (unwrapped instanceof NumericDataValue) {
        NumericDataValue ndv = (NumericDataValue) unwrapped;
        cell.setCellValue(ndv.value);
        if (text == null || text.trim().length() == 0) {
            style.setColor(Color.WHITE);
        } else if (text.indexOf('%') != -1) {
            style.format = PERCENT_FORMAT;
        }
    } else if (text == null || text.trim().length() == 0) {
        return;
    } else {
        cell.setCellValue(new HSSFRichTextString(text));
    }
    style.loadFrom(comp);
    styleCache.applyStyle(cell, style);
}
Also used : NumericDataValue(teamdash.wbs.NumericDataValue) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) JLabel(javax.swing.JLabel) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) Date(java.util.Date)

Example 14 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project processdash by dtuma.

the class WBSExcelWriter method createHeaderRow.

private void createHeaderRow(HSSFSheet sheet, TableColumnModel columns) {
    HSSFRow row = sheet.createRow(0);
    StyleKey style = new StyleKey();
    style.bold = true;
    for (int i = 0; i < columns.getColumnCount(); i++) {
        TableColumn col = columns.getColumn(i);
        String columnName = data.getColumnName(col.getModelIndex());
        HSSFCell cell = row.createCell(s(i + 1));
        cell.setCellValue(new HSSFRichTextString(columnName));
        styleCache.applyStyle(cell, style);
    }
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) TableColumn(javax.swing.table.TableColumn)

Example 15 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project head by mifos.

the class XlsLoansAccountImporter method getCellDecimalValue.

private BigDecimal getCellDecimalValue(HSSFRow row, XlsLoansImportTemplateConstants currentCell) throws XlsParsingException {
    final HSSFCell cell = row.getCell(currentCell.getValue(), HSSFRow.RETURN_BLANK_AS_NULL);
    BigDecimal result = null;
    if (cell != null) {
        switch(cell.getCellType()) {
            case HSSFCell.CELL_TYPE_STRING:
                HSSFRichTextString richText = cell.getRichStringCellValue();
                try {
                    result = new BigDecimal(richText.getString());
                } catch (NumberFormatException ex) {
                    throw new XlsParsingException(getCellError(XlsMessageConstants.NOT_A_NUMBER, row, currentCell.getValue(), null));
                }
                break;
            case HSSFCell.CELL_TYPE_NUMERIC:
                double val = cell.getNumericCellValue();
                result = new BigDecimal(val);
                break;
            default:
                return null;
        }
    }
    return result;
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) BigDecimal(java.math.BigDecimal)

Aggregations

HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)38 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)17 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)16 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)9 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)5 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)5 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)5 Test (org.junit.Test)5 HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)3 FileOutputStream (java.io.FileOutputStream)2 BigDecimal (java.math.BigDecimal)2 HSSFComment (org.apache.poi.hssf.usermodel.HSSFComment)2 Region (org.apache.poi.hssf.util.Region)2 Element (org.w3c.dom.Element)2 Text (org.w3c.dom.Text)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1