Package org.odftoolkit.odfdom.dom.element.table

Examples of org.odftoolkit.odfdom.dom.element.table.TableTableRowElement


    //1. remove row
    OdfTableRow firstRow = getRowByIndex(startIndex);
    for (int i = startIndex; i < startIndex + deleteRowCount; i++) {
      int repeatedAttr = firstRow.getRowsRepeatedNumber();
      if (repeatedAttr == 1) {
        TableTableRowElement rowEle = OdfElement.findNextChildNode(TableTableRowElement.class, firstRow.getOdfElement());
        firstRow.removeAllCellsRelationship();
        firstRow.getOdfElement().getParentNode().removeChild(firstRow.getOdfElement());
        updateRowRepository(firstRow.getOdfElement(), firstRow.mnRepeatedIndex, null, 0);
        if (i < (startIndex + deleteRowCount - 1)) {
          firstRow = this.getRowInstance(rowEle, 0);
View Full Code Here


    if (sampleTable != null) {
      DataObjectFactory df = new TgacDataObjectFactory();
      for (OdfTableRow row : sampleTable.getRowList()) {
        if (row.getRowIndex() != 0) {
          TableTableRowElement ttre = row.getOdfElement();

          Sample s = df.getSample();

          Node n1 = ttre.getChildNodes().item(0);
          if (n1.getFirstChild() != null) {
            s.setAlias(n1.getFirstChild().getTextContent());
          }

          Node n2 = ttre.getChildNodes().item(1);
          if (n2.getFirstChild() != null) {
            s.setScientificName(n2.getFirstChild().getTextContent());
          }

          Node n3 = ttre.getChildNodes().item(2);
          if (n3.getFirstChild() != null) {
            s.setIdentificationBarcode(n3.getFirstChild().getTextContent());
          }

          /*
          OdfTableCell cell3 = row.getCellByIndex(3);
          if (cell3.getStringValue() != null) {
            s.setSampleType(cell3.getStringValue().toUpperCase());
          }
          else {
            s.setSampleType("OTHER");
          }
          */

          Node n4 = ttre.getChildNodes().item(4);
          if (n4.getFirstChild() != null) {
            s.setDescription(n4.getFirstChild().getTextContent());
          }

          Node n9 = ttre.getChildNodes().item(9);
          if (n9.getFirstChild() != null) {
            if (!"".equals(n9.getFirstChild().getTextContent())) {
              Note n = new Note();
              n.setText(n9.getFirstChild().getTextContent());
              s.addNote(n);
View Full Code Here

    }

    // create table rows
    Double[][] cellValues = dataset.getLocalTableData();
    for (int i = 0; i < numRows; i++) {
      TableTableRowElement row = rows.newTableTableRowElement();
      TableTableCellElement nameCell = row.newTableTableCellElement(0.0, "string");
      nameCell.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.STRING.toString());
      OdfTextParagraph paragraph = (OdfTextParagraph) nameCell.newTextPElement();
      String[] cellContents = dataset.getLocalTableFirstColumn();
      if (cellContents[i] != null) {
        if (isFirstColumnAsLabel) {
          if (isRowAsSeries) {
            paragraph.setTextIdAttribute((String) labelCellRange[i]);
          }
          if (!isRowAsSeries && i == 0) {
            paragraph.setTextIdAttribute(getTableCellRange());
          }
        }
        paragraph.setTextContent(cellContents[i]);
      } else {
        paragraph.setTextContent("");
      }
      for (int j = 0; j < numColumns; j++) {
        TableTableCellElement cell = row.newTableTableCellElement(0.0, "string");
        cell.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.FLOAT.toString());
        if (cellValues[i][j] != null) {
          cell.setOfficeValueAttribute(cellValues[i][j]);
          OdfTextParagraph paragraph1 = (OdfTextParagraph) cell.newTextPElement();
          paragraph1.setTextContent(cellValues[i][j].toString());
View Full Code Here

  }

  private void updateTableCells(Document odfdoc, String tablename,
      double[] values, String[] labels) {
    int i = 0, j = 0;
    TableTableRowElement td;
    TableTableCellElement cell;
    OdfFileDom dom;
    NodeList tableList;
    TableTableElement myTable;
    NodeList lst;
    OdfTextParagraph p;
    OfficeSpreadsheetElement spreadsheet = null;

    try {
      dom = odfdoc.getContentDom();
      tableList = dom.getElementsByTagNameNS(
          OdfDocumentNamespace.TABLE.getUri(), "table");
      spreadsheet = (OfficeSpreadsheetElement) dom.getElementsByTagNameNS(
          OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);

      i = 0;
      if (tableList.getLength() > 0) {
        for (; i < tableList.getLength(); i++) {
          String currentname = ((TableTableElement) tableList.item(i)).getTableNameAttribute();
          if (currentname == null) {
            currentname = "";
          }
          if (currentname.equalsIgnoreCase(tablename)) {
            break;
          }
        }
      }
      if (i < tableList.getLength()) //table with the specific table name is found
      {
        myTable = (TableTableElement) tableList.item(i);
      } else { //table with the specific table name is not found. Create table
        myTable = dom.newOdfElement(TableTableElement.class);
        myTable.setTableNameAttribute(tablename);
        spreadsheet.appendChild(myTable);
      }

      lst = myTable.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-row");
      if (lst.getLength() == 0) { //the first table row is not existed. Create table row
        td = dom.newOdfElement(TableTableRowElement.class);
        cell = dom.newOdfElement(TableTableCellElement.class);
        p = dom.newOdfElement(OdfTextParagraph.class);
        if (tablename.startsWith("Memory")) {
          p.setTextContent("memory(b)");
        } else {
          p.setTextContent("time(ms)");
        }
        td.appendChild(cell);
        cell.appendChild(p);
        myTable.appendChild(td);
      } else {
        td = (TableTableRowElement) lst.item(0); //the first table row is existed.
      }
      cell = dom.newOdfElement(TableTableCellElement.class);
      td.appendChild(cell);
      p = dom.newOdfElement(OdfTextParagraph.class);
      p.setTextContent(testTag);
      cell.appendChild(p);


      for (i = 1; i < values.length + 1; i++) {
        if (i < lst.getLength()) { //table row is existed
          td = (TableTableRowElement) lst.item(i);
        } else { //table row is not existed.
          td = dom.newOdfElement(TableTableRowElement.class);
          myTable.appendChild(td);
          //append first cell with labels
          cell = dom.newOdfElement(TableTableCellElement.class);
          td.appendChild(cell);
          p = dom.newOdfElement(OdfTextParagraph.class);
          p.setTextContent(labels[j]);
          cell.appendChild(p);
        }
        cell = dom.newOdfElement(TableTableCellElement.class);
        cell.setOfficeValueTypeAttribute("float");
        cell.setOfficeValueAttribute(new Double(values[j]));
        p = dom.newOdfElement(OdfTextParagraph.class);
        p.setTextContent(values[j] + "");
        cell.appendChild(p);
        td.appendChild(cell);
        j++;
      }
    } catch (Exception e) {
      LOG.log(Level.SEVERE, null, e);
    }
View Full Code Here

    Vector<String> columnLabels = new Vector<String>();

    try {
      int i = 0, rowindex, columnindex;
      char ch;
      TableTableRowElement td;
      TableTableCellElement cell;
      OdfFileDom sheetContent;
      NodeList tableList, rowList, cellList;
      TableTableElement table;
      Vector<Double> series;
      double value;

      // get table
      sheetContent = spreadsheet.getContentDom();
      tableList = sheetContent.getElementsByTagNameNS(OdfNamespace.newNamespace(OdfDocumentNamespace.TABLE)
          .toString(), "table");
      while (!sheettable.equals(((TableTableElement) tableList.item(i)).getTableNameAttribute()))
        i++;
      table = (TableTableElement) tableList.item(i);
      rowList = table.getElementsByTagNameNS(OdfNamespace.newNamespace(OdfDocumentNamespace.TABLE).toString(),
          "table-row");

      // get data, begin for(beginRow,endRow)
      for (i = beginRow; i <= endRow; i++) {
        rowindex = bFirstRowAsLabel ? (i - beginRow - 1) : (i - beginRow);
        td = (TableTableRowElement) rowList.item(i - 1);
        cellList = td.getElementsByTagNameNS(OdfNamespace.newNamespace(OdfDocumentNamespace.TABLE).toString(),
            "table-cell");
        Map<Integer, TableTableCellElement> cellIndexMap = new HashMap<Integer, TableTableCellElement>();
        for (int index = 0, cellNum = 0; (cellNum < cellList.getLength()) && (index <= (endColumn - 'A')); cellNum++) {
          TableTableCellElement item = (TableTableCellElement) cellList.item(cellNum);
          int repeatedCount = item.getTableNumberColumnsRepeatedAttribute()
View Full Code Here

    }

    for (Node m : new DomNodeList(group.getChildNodes())) {
      if (m instanceof TableTableHeaderRowsElement) {
        TableTableHeaderRowsElement headers = (TableTableHeaderRowsElement) m;
        TableTableRowElement returnEle = findRowInTableHeaderRows(headers, tr, resultIndexs);
        result += resultIndexs[0];
        if (returnEle != null) {// find
          indexs[0] = result;
          return returnEle;
        }
      } else if (m instanceof TableTableRowGroupElement) {
        TableTableRowGroupElement aGroup = (TableTableRowGroupElement) m;
        TableTableRowElement returnEle = findRowInTableRowGroup(aGroup, tr, resultIndexs);
        result += resultIndexs[0];
        if (returnEle != null) {// find
          indexs[0] = result;
          return returnEle;
        }
      } else if (m instanceof TableTableRowsElement) {
        TableTableRowsElement rows = (TableTableRowsElement) m;
        TableTableRowElement returnEle = findRowInTableRows(rows, tr, resultIndexs);
        result += resultIndexs[0];
        if (returnEle != null) {// find
          indexs[0] = result;
          return returnEle;
        }
View Full Code Here

   *
   * @return the index of the row containing this cell
   */
  public int getRowIndex() {
    TableTableElement table = getTableElement();
    TableTableRowElement tr = getTableRowElement();
    int[] indexs = new int[1];

    TableTableRowElement returnEle = findRowInTableRowGroup(table, tr, indexs);
    if (returnEle != null) {
      return (indexs[0] + mnRepeatedRowIndex);
    } else {
      return -1;
    }
View Full Code Here

   * Get the index of the table column which contains this cell.
   *
   * @return the index of the column containing this cell
   */
  public int getColumnIndex() {
    TableTableRowElement tr = (TableTableRowElement) mCellElement.getParentNode();
    int result = 0;
    for (Node n : new DomNodeList(tr.getChildNodes())) {
      if (n == mCellElement) {
        return result + mnRepeatedColIndex;
      }
      if (n instanceof TableTableCellElementBase) {
        result += ((TableTableCellElementBase) n).getTableNumberColumnsRepeatedAttribute().intValue();
View Full Code Here

  // splitRepeatedCells must be called first in order to
  // 1. update parent row if the row is the repeated rows.
  // 2. update the cell itself if the cell is the column repeated cells.
  void splitRepeatedCells() {
    Table table = getTable();
    TableTableRowElement ownerRowElement = getTableRowElement();
    // 1.if the parent row is the repeated row
    // the repeated row has to be separated
    // after this the cell element and repeated index will be updated
    // according to the new parent row
    Row ownerRow = table.getRowInstance(ownerRowElement, mnRepeatedRowIndex);
    if (ownerRow.getRowsRepeatedNumber() > 1) {
      ownerRow.splitRepeatedRows();
      // update row element, new row element maybe created.
      ownerRowElement = ownerRow.maRowElement;
      mnRepeatedRowIndex = 0;
    }
    // 2.if the cell is the column repeated cell
    // this repeated cell has to be separated
    int repeateNum = getColumnsRepeatedNumber();
    if (repeateNum > 1) {
      // change this repeated cell to three parts: repeated cell before,
      // new single cell and repeated cell after.
      Map<TableTableCellElementBase, Vector<Cell>> cellRepository = table.mCellRepository;
      String tableNamespaceURI = OdfDocumentNamespace.TABLE.getUri();
      Vector<Cell> oldList = null;
      if (cellRepository.containsKey(mCellElement)) {
        oldList = cellRepository.remove(mCellElement);
      }
      int offetAfterCurrentCell = repeateNum - mnRepeatedColIndex - 1;
      TableTableCellElementBase currentCellElement = mCellElement;
      TableTableCellElementBase newBeforeCellElement = null;
      TableTableCellElementBase newAfterCellElement = null;
      if (mnRepeatedColIndex > 0) {
        newBeforeCellElement = (TableTableCellElementBase) mCellElement.cloneNode(true);
        if (mnRepeatedColIndex > 1) {
          newBeforeCellElement.setTableNumberColumnsRepeatedAttribute(mnRepeatedColIndex);
        } else {
          newBeforeCellElement.removeAttributeNS(tableNamespaceURI, "number-columns-repeated");
        }
        // insert new before repeated cell
        ownerRowElement.insertBefore(newBeforeCellElement, currentCellElement);
        // update cell cache
        if (oldList != null) {
          Vector<Cell> newBeforeList = new Vector<Cell>(mnRepeatedColIndex);
          for (int i = 0; i < mnRepeatedColIndex && i < oldList.size(); i++) {
            Cell beforeCell = oldList.get(i);
            if (beforeCell != null) {
              beforeCell.mCellElement = newBeforeCellElement;
              newBeforeList.add(i, beforeCell);
            }
          }
          cellRepository.put(newBeforeCellElement, newBeforeList);
        }
      }
      currentCellElement.removeAttributeNS(tableNamespaceURI, "number-columns-repeated");
      if (offetAfterCurrentCell > 0) {
        newAfterCellElement = (TableTableCellElementBase) currentCellElement.cloneNode(true);
        ownerRowElement.insertBefore(newAfterCellElement, currentCellElement);
        currentCellElement = newAfterCellElement;
        newAfterCellElement = (TableTableCellElementBase) currentCellElement.getNextSibling();
        if (offetAfterCurrentCell > 1) {
          newAfterCellElement.setTableNumberColumnsRepeatedAttribute(offetAfterCurrentCell);
        }
View Full Code Here

              TableTableCellElement cell = (TableTableCellElement) cellBase.getOdfElement();
              TableCoveredTableCellElement coveredCell = (TableCoveredTableCellElement) OdfXMLFactory.newOdfElement(
                  (OdfFileDom) cell.getOwnerDocument(),
                  OdfName.newName(OdfDocumentNamespace.TABLE, "covered-table-cell"));

              TableTableRowElement parentRowEle = cellBase.getTableRow().getOdfElement();
              parentRowEle.insertBefore(coveredCell, cell);
              //copy the content of this cell to the first cell
              firstCell.appendContentFrom(cellBase);
              cellBase.removeContent();
              //set the table column repeated attribute
              int repeatedNum = cell.getTableNumberColumnsRepeatedAttribute();
              int num = (mnEndColumn - j + 1) - repeatedNum;
              if (num >= 0) {
                if(repeatedNum > 1){
                  coveredCell.setTableNumberColumnsRepeatedAttribute(repeatedNum);
                }
                parentRowEle.removeChild(cell);
              } else {
                int tableNumberColumnsRepeatedValue = mnEndColumn - j + 1;
                if(tableNumberColumnsRepeatedValue > 1){
                  coveredCell.setTableNumberColumnsRepeatedAttribute(tableNumberColumnsRepeatedValue);
                }
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.element.table.TableTableRowElement

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.