use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.
the class TestSheet method testCreateAggregate.
@Test
public void testCreateAggregate() {
String msoDrawingRecord1 = "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" + "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" + "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" + "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" + "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" + "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" + "05 00 94 00 00 00 11 F0 00 00 00 00";
String msoDrawingRecord2 = "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " + "0B 00 0C 00 00 00 11 F0 00 00 00 00";
DrawingRecord d1 = new DrawingRecord();
d1.setData(HexRead.readFromString(msoDrawingRecord1));
ObjRecord r1 = new ObjRecord();
DrawingRecord d2 = new DrawingRecord();
d2.setData(HexRead.readFromString(msoDrawingRecord2));
TextObjectRecord r2 = new TextObjectRecord();
r2.setStr(new HSSFRichTextString("Aggregated"));
NoteRecord n2 = new NoteRecord();
List<Record> recordStream = new ArrayList<Record>();
recordStream.add(InternalSheet.createBOF());
recordStream.add(d1);
recordStream.add(r1);
recordStream.add(createWindow2Record());
recordStream.add(EOFRecord.instance);
confirmAggregatedRecords(recordStream);
recordStream = new ArrayList<Record>();
recordStream.add(InternalSheet.createBOF());
recordStream.add(d1);
recordStream.add(r1);
recordStream.add(d2);
recordStream.add(r2);
recordStream.add(createWindow2Record());
recordStream.add(EOFRecord.instance);
confirmAggregatedRecords(recordStream);
recordStream = new ArrayList<Record>();
recordStream.add(InternalSheet.createBOF());
recordStream.add(d1);
recordStream.add(r1);
recordStream.add(d2);
recordStream.add(r2);
recordStream.add(n2);
recordStream.add(createWindow2Record());
recordStream.add(EOFRecord.instance);
confirmAggregatedRecords(recordStream);
}
use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.
the class NumberComparingSpreadsheetGenerator method writeHeaderCell.
private static void writeHeaderCell(HSSFRow row, int i, String text, HSSFCellStyle style) {
HSSFCell cell = row.createCell(i);
cell.setCellValue(new HSSFRichTextString(text));
cell.setCellStyle(style);
}
use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.
the class ExcelToFoConverter method processCell.
protected boolean processCell(HSSFWorkbook workbook, HSSFCell cell, Element tableCellElement, int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt) {
final HSSFCellStyle cellStyle = cell.getCellStyle();
String value;
switch(cell.getCellTypeEnum()) {
case STRING:
// XXX: enrich
value = cell.getRichStringCellValue().getString();
break;
case FORMULA:
switch(cell.getCachedFormulaResultTypeEnum()) {
case STRING:
HSSFRichTextString str = cell.getRichStringCellValue();
if (str != null && str.length() > 0) {
value = (str.toString());
} else {
value = ExcelToHtmlUtils.EMPTY;
}
break;
case NUMERIC:
double nValue = cell.getNumericCellValue();
short df = cellStyle.getDataFormat();
String dfs = cellStyle.getDataFormatString();
value = _formatter.formatRawCellContents(nValue, df, dfs);
break;
case BOOLEAN:
value = Boolean.toString(cell.getBooleanCellValue());
break;
case ERROR:
value = ErrorEval.getText(cell.getErrorCellValue());
break;
default:
logger.log(POILogger.WARN, "Unexpected cell cachedFormulaResultType (" + cell.getCachedFormulaResultTypeEnum() + ")");
value = ExcelToHtmlUtils.EMPTY;
break;
}
break;
case BLANK:
value = ExcelToHtmlUtils.EMPTY;
break;
case NUMERIC:
value = _formatter.formatCellValue(cell);
break;
case BOOLEAN:
value = Boolean.toString(cell.getBooleanCellValue());
break;
case ERROR:
value = ErrorEval.getText(cell.getErrorCellValue());
break;
default:
logger.log(POILogger.WARN, "Unexpected cell type (" + cell.getCellTypeEnum() + ")");
return true;
}
final boolean noText = ExcelToHtmlUtils.isEmpty(value);
final boolean wrapInDivs = !noText && !cellStyle.getWrapText();
final boolean emptyStyle = isEmptyStyle(cellStyle);
if (!emptyStyle && noText) {
/*
* if cell style is defined (like borders, etc.) but cell text
* is empty, add " " to output, so browser won't collapse
* and ignore cell
*/
value = " ";
}
if (isOutputLeadingSpacesAsNonBreaking() && value.startsWith(" ")) {
StringBuilder builder = new StringBuilder();
for (int c = 0; c < value.length(); c++) {
if (value.charAt(c) != ' ') {
break;
}
builder.append(' ');
}
if (value.length() != builder.length()) {
builder.append(value.substring(builder.length()));
}
value = builder.toString();
}
Text text = foDocumentFacade.createText(value);
Element block = foDocumentFacade.createBlock();
if (wrapInDivs) {
block.setAttribute("absolute-position", "fixed");
block.setAttribute("left", "0px");
block.setAttribute("top", "0px");
block.setAttribute("bottom", "0px");
block.setAttribute("min-width", normalWidthPx + "px");
if (maxSpannedWidthPx != Integer.MAX_VALUE) {
block.setAttribute("max-width", maxSpannedWidthPx + "px");
}
block.setAttribute("overflow", "hidden");
block.setAttribute("height", normalHeightPt + "pt");
block.setAttribute("keep-together.within-line", "always");
block.setAttribute("wrap-option", "no-wrap");
}
processCellStyle(workbook, cell.getCellStyle(), tableCellElement, block);
block.appendChild(text);
tableCellElement.appendChild(block);
return ExcelToHtmlUtils.isEmpty(value) && emptyStyle;
}
use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.
the class TestDrawingShapes method testTextForSimpleShape.
@Test
public void testTextForSimpleShape() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sheet = wb1.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFSimpleShape shape = patriarch.createSimpleShape(new HSSFClientAnchor());
shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
assertEquals(agg.getShapeToObjMapping().size(), 2);
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sheet = wb2.getSheetAt(0);
patriarch = sheet.getDrawingPatriarch();
shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
agg = HSSFTestHelper.getEscherAggregate(patriarch);
assertEquals(agg.getShapeToObjMapping().size(), 2);
shape.setString(new HSSFRichTextString("string1"));
assertEquals(shape.getString().getString(), "string1");
assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
assertEquals(agg.getShapeToObjMapping().size(), 2);
HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
wb2.close();
HSSFWorkbook wb4 = HSSFTestDataSamples.writeOutAndReadBack(wb3);
wb3.close();
sheet = wb4.getSheetAt(0);
patriarch = sheet.getDrawingPatriarch();
shape = (HSSFSimpleShape) patriarch.getChildren().get(0);
assertNotNull(HSSFTestHelper.getTextObjRecord(shape));
assertEquals(shape.getString().getString(), "string1");
assertNotNull(HSSFTestHelper.getEscherContainer(shape).getChildById(EscherTextboxRecord.RECORD_ID));
assertEquals(agg.getShapeToObjMapping().size(), 2);
wb4.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.
the class TestTextObjectRecord method testClone.
/**
* Test cloning
*/
public void testClone() {
String text = "Hello, World";
HSSFRichTextString str = new HSSFRichTextString(text);
TextObjectRecord obj = new TextObjectRecord();
obj.setStr(str);
TextObjectRecord cloned = (TextObjectRecord) obj.clone();
assertEquals(obj.getRecordSize(), cloned.getRecordSize());
assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());
assertEquals(obj.getStr().getString(), cloned.getStr().getString());
//finally check that the serialized data is the same
byte[] src = obj.serialize();
byte[] cln = cloned.serialize();
assertArrayEquals(src, cln);
}
Aggregations