Search in sources :

Example 36 with HSSFRichTextString

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

the class NumberRenderingSpreadsheetGenerator method writeDataRow.

static void writeDataRow(HSSFSheet sheet, int rowIx, long rawLongBits, String expectedExcelRendering) {
    double d = Double.longBitsToDouble(rawLongBits);
    HSSFRow row = sheet.createRow(rowIx);
    int rowNum = rowIx + 1;
    String cel0ref = "A" + rowNum;
    String rawBitsText = formatLongAsHex(rawLongBits);
    String jmExpr = "'ec(" + rawBitsText + ", ''\" & C" + rowNum + " & \"'', ''\" & D" + rowNum + " & \"''),'";
    // The 'Match' column will contain 'OK' if the metadata (from NumberToTextConversionExamples)
    // matches Excel's rendering.
    String matchExpr = "if(D" + rowNum + "=E" + rowNum + ", \"OK\", \"ERROR\")";
    row.createCell(0).setCellValue(d);
    row.createCell(1).setCellValue(new HSSFRichTextString(rawBitsText));
    row.createCell(2).setCellValue(new HSSFRichTextString(Double.toString(d)));
    row.createCell(3).setCellFormula("\"\" & " + cel0ref);
    row.createCell(4).setCellValue(new HSSFRichTextString(expectedExcelRendering));
    row.createCell(5).setCellFormula(matchExpr);
    row.createCell(6).setCellFormula(jmExpr.replaceAll("'", "\""));
//		if (false) {
//			// for observing arithmetic near numeric range boundaries
//			row.createCell(7).setCellFormula(cel0ref + " * 1.0001");
//			row.createCell(8).setCellFormula(cel0ref + " / 1.0001");
//		}
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 37 with HSSFRichTextString

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

the class TestDrawingShapes method testRotation.

@Test
public void testRotation() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor(0, 0, 100, 100, (short) 0, 0, (short) 5, 5));
    rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
    assertEquals(rectangle.getRotationDegree(), 0);
    rectangle.setRotationDegree((short) 45);
    assertEquals(rectangle.getRotationDegree(), 45);
    rectangle.setFlipHorizontal(true);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheetAt(0);
    patriarch = sheet.getDrawingPatriarch();
    rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0);
    assertEquals(rectangle.getRotationDegree(), 45);
    rectangle.setRotationDegree((short) 30);
    assertEquals(rectangle.getRotationDegree(), 30);
    patriarch.setCoordinates(0, 0, 10, 10);
    rectangle.setString(new HSSFRichTextString("1234"));
    wb2.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFSimpleShape(org.apache.poi.hssf.usermodel.HSSFSimpleShape) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 38 with HSSFRichTextString

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

the class WBSExcelWriter method writeCellForNodeName.

private void writeCellForNodeName(WBSNode node, HSSFRow row) {
    HSSFCell cell = row.createCell(s(0));
    String name = node.getName();
    if (name == null || name.trim().length() == 0)
        name = "(empty)";
    cell.setCellValue(new HSSFRichTextString(name));
    StyleKey style = new StyleKey();
    style.indent = s(node.getIndentLevel());
    if (WBSModelValidator.hasNodeError(node)) {
        style.setColor(Color.RED);
        style.bold = true;
    }
    styleCache.applyStyle(cell, style);
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

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