Package org.odftoolkit.simple.table

Examples of org.odftoolkit.simple.table.TableTemplate


    if (table.getRowCount() < 5 || table.getColumnCount() < 5)
      throw new IllegalStateException(
          "The template cannot be loaded. It should be at least a 5*5 table.");

    TableTemplate template = new TableTemplate(getStylesDom()
        .newOdfElement(TableTableTemplateElement.class));

    // first-row-start-column
    Cell cell = table.getCellByPosition(0, 0);
    cell.getParagraphIterator().hasNext();
    cell.getParagraphIterator().next().getStyleName();
    Paragraph para = cell.getParagraphByIndex(0, false);
    String paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.FIRSTROWSTARTCOLUM, cell
            .getStyleName(), paraStyle);
    TableTableCellElementBase oldCellEle = cell.getOdfElement();
    TableTableCellElementBase newCellEle = (TableTableCellElementBase) oldCellEle
        .cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first-row-end-column
    cell = table.getCellByPosition(4, 0);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.FIRSTROWENDCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last-row-start-column
    cell = table.getCellByPosition(0, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.LASTROWSTARTCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last-row-end-column
    cell = table.getCellByPosition(4, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setExtendedStyleByType(
        TableTemplate.ExtendedStyleType.LASTROWENDCOLUMN, cell
            .getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first column
    cell = table.getCellByPosition(0, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableFirstColumnStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last column
    cell = table.getCellByPosition(4, 2);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableLastColumnStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // first row
    cell = table.getCellByPosition(1, 0);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableFirstRowStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // last row
    cell = table.getCellByPosition(1, 4);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableLastRowStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // body (=odd row/column)
    cell = table.getCellByPosition(1, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableBodyStyle(cell.getStyleName(), paraStyle);
    template.setTableOddRowsStyle(cell.getStyleName(), paraStyle);
    template.setTableOddColumnsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // even row
    cell = table.getCellByPosition(1, 2);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableEvenRowsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    // even row
    cell = table.getCellByPosition(2, 1);
    para = cell.getParagraphByIndex(0, false);
    paraStyle = (para != null ? para.getStyleName() : null);
    template.setTableEvenColumnsStyle(cell.getStyleName(), paraStyle);
    oldCellEle = cell.getOdfElement();
    newCellEle = (TableTableCellElementBase) oldCellEle.cloneNode(true);
    copyForeignStyleRef(newCellEle, cell.getOwnerDocument());

    return template;
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.table.TableTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.