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());
}
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());
}
}
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);
}
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);
}
}
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;
}
Aggregations