Java源码示例:org.odftoolkit.simple.table.Cell

示例1
private void validateMerge(final String documentName) throws Exception {
    final SpreadsheetDocument document =
            SpreadsheetDocument.loadDocument(new File(GENERATED_FILES, documentName));
    Assert.assertEquals(1, document.getSheetCount());
    final org.odftoolkit.simple.table.Table sheet = document.getSheetByName("test");
    Assert.assertNotNull(sheet);
    Assert.assertEquals(14, sheet.getRowCount());
    final Cell cell1 = sheet.getCellByPosition(0, 0);
    Assert.assertEquals(5, cell1.getColumnSpannedNumber());
    Assert.assertEquals(1, cell1.getRowSpannedNumber());

    final Cell cell2 = sheet.getCellByPosition(0, 1);
    Assert.assertEquals(1, cell2.getColumnSpannedNumber());
    Assert.assertEquals(2, cell2.getRowSpannedNumber());

    final Cell cell3 = sheet.getCellByPosition(1, 1);
    Assert.assertEquals(4, cell3.getColumnSpannedNumber());
    Assert.assertEquals(2, cell3.getRowSpannedNumber());

    final Cell cell4 = sheet.getCellByPosition(0, 4);
    Assert.assertEquals(1, cell4.getColumnSpannedNumber());
    Assert.assertEquals(10, cell4.getRowSpannedNumber());

    for (int c = 0; c < 5; c++) {
        for (int r = 0; r < 3; r++) {
            if (c == 0 && r == 0 || c <= 1 && r == 1) {
                continue;
            }

            final Cell cell = sheet.getCellByPosition(c, r);
            Assert.assertTrue(cell.getOdfElement() instanceof TableCoveredTableCellElement);
        }
    }
}
 
示例2
private void validateReadme(final String documentName) throws Exception {
    final SpreadsheetDocument document =
            SpreadsheetDocument.loadDocument(new File(GENERATED_FILES, documentName));
    Assert.assertEquals(1, document.getSheetCount());
    final org.odftoolkit.simple.table.Table sheet = document.getSheetByName("test");
    Assert.assertNotNull(sheet);
    Assert.assertEquals(51, sheet.getRowCount());
    final OdfStyle gcs = OdfToolkitUtil
            .getDocumentStyle(document, GREEN_CELL_STYLE, OdfStyleFamily.TableCell);
    Assert.assertEquals("Default", gcs.getStyleParentStyleNameAttribute());
    final Node properties = OdfToolkitUtil.getFirstElement(gcs, "style:table-cell-properties");
    Assert.assertEquals(GREEN_COLOR.getValue(),
            OdfToolkitUtil.getAttribute(properties, "fo:background-color"));
    for (int y = 0; y < 50; y++) {
        for (int x = 0; x < 5; x++) {
            final Cell cell = sheet.getCellByPosition(x, y);
            Assert.assertEquals(Double.valueOf(x * y), cell.getDoubleValue());
            Assert.assertEquals("float", cell.getValueType());

            final TableTableCellElementBase element = cell.getOdfElement();
            Assert.assertEquals(GREEN_CELL_STYLE + "-_-float-data",
                    OdfToolkitUtil.getStyleName(cell));
            Assert.assertEquals("table-cell", OdfToolkitUtil.getStyleFamilyName(cell));
            Assert.assertEquals(GREEN_CELL_STYLE, OdfToolkitUtil.getParentStyleName(cell));
        }
    }
}
 
示例3
public static String getText(SpreadsheetDocument spreadsheetDocument) {
    try {
        StringBuilder stringBuilder = new StringBuilder("");
        int sheetCount = spreadsheetDocument.getSheetCount();
        for(int i=0; i<sheetCount; i++) {
            Table sheet = spreadsheetDocument.getSheetByIndex(i);
            int rowCount = sheet.getRowCount();
            for(int y=0; y<rowCount; y++) {
                Row row = sheet.getRowByIndex(y);
                int cellCount = row.getCellCount();
                for(int x=0; x<cellCount; x++) {
                    Cell cell = row.getCellByIndex(x);
                    String value = cell.getStringValue();
                    stringBuilder.append(value);
                    stringBuilder.append("\t");
                }
                stringBuilder.append("\n");
            }
            stringBuilder.append("\n\n");
        }
        return stringBuilder.toString();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
示例4
private static void addTitlePage(TextDocument outputDocument) throws Exception {

        addLines(outputDocument, 2);

        Paragraph para = outputDocument.addParagraph(null);

        // add company logo
        addImage(para, extension.getParams().getLogoFileName(), 0);

        addLines(outputDocument, 4);
        // Lets write a big header
        para = outputDocument.addParagraph(null);

        para.setTextContent(extension.getParams().getTitleReport());
        para.setHorizontalAlignment(HorizontalAlignmentType.CENTER);
        para.setFont(fontTitleTextReport);

        addLines(outputDocument, 4);
        para = outputDocument.addParagraph(null);
        para.setTextContent(extension.getParams().getCustomerName());
        para.setHorizontalAlignment(HorizontalAlignmentType.CENTER);
        para.setFont(fontTitleTextReport);

        addLines(outputDocument, 15);

        Table table = outputDocument.addTable(2, 1);

        Cell cell = table.getCellByPosition(0, 0);
        cell.setStringValue(
                extension
                        .getMessages()
                        .getString("alertreport.export.message.export.pdf.confidential"));
        cell.setFont(fontSmallBold);
        String color = Color.toSixDigitHexRGB("#87cefa");
        cell.setCellBackgroundColor(Color.valueOf(color));
        Cell cell1 = table.getCellByPosition(0, 1);
        cell1.setStringValue(extension.getParams().getConfidentialText());
        cell1.setHorizontalAlignment(HorizontalAlignmentType.JUSTIFY);
        cell1.setFont(fontSmall);

        // outputDocument.addPageBreak();

    }
 
示例5
/**
 * @param cell the cell
 * @return the value of the cell as a string
 */
public static String getStringValue(final Cell cell) {
    return cell.getOdfElement().getOfficeStringValueAttribute();
}
 
示例6
/**
 * @param cell the cell
 * @return the parent style name
 */
public static String getParentStyleName(final Cell cell) {
    return cell.getOdfElement().getAutomaticStyle().getStyleParentStyleNameAttribute();
}
 
示例7
/**
 * @param cell the cell
 * @return the cell style name
 */
public static String getStyleName(final Cell cell) {
    return cell.getOdfElement().getStyleName();
}
 
示例8
/**
 * @param cell the cell
 * @return the name of the style family of the cell
 */
public static String getStyleFamilyName(final Cell cell) {
    return cell.getOdfElement().getStyleFamily().getName();
}