Package org.odftoolkit.simple.table

Examples of org.odftoolkit.simple.table.Cell


    }

    private static String parseTableRow(Row row) {
        String line = "|";
        for (int i = 0; i < row.getCellCount(); i++) {
            Cell cell = row.getCellByIndex(i);
            line += cell.getDisplayText() + "|";
        }
        return line;
    }
View Full Code Here


        Border borderbase = new Border(Color.LIME, 1.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM);
      borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE);
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = doc.getTableByName("Sheet1");
     
      Cell cell = table.getCellByPosition(2, 2);
      cell.setBorders(CellBordersType.BOTTOM, borderbase);
      cell.setBorders(CellBordersType.RIGHT, borderbase);
      cell.setBorders(CellBordersType.DIAGONALTLBR, borderbase);

      //verification
      Border base = cell.getBorder(CellBordersType.BOTTOM);
      base = cell.getBorder(CellBordersType.RIGHT);
      base = cell.getBorder(CellBordersType.DIAGONALTLBR);
      Assert.assertEquals(borderbase, base);
      Assert.assertEquals(StyleTypeDefinitions.LineType.SINGLE, borderbase.getLineStyle());
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
View Full Code Here

        Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM);
      borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE);
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = doc.getTableByName("Sheet1");
     
      Cell cell = table.getCellByPosition(0, 0);
      //cell.setBorders(CellBordersType.DIAGONAL_LINES, borderbase);
      cell.setBorders(CellBordersType.RIGHT, borderbase);

      //validate
      TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite();
      NamedNodeMap attr = styleCell.mElement.getAttributes();
      Node nod = attr.getNamedItem(FoBorderRightAttribute.ATTRIBUTE_NAME.getQName());
      Assert.assertEquals("3.0701cm solid #00ff00", nod.getNodeValue());
     
      cell.setBorders(CellBordersType.NONE, borderbase);
     
      TableCellProperties styleCell1 = cell.getStyleHandler().getTableCellPropertiesForWrite();
      NamedNodeMap attr1 = styleCell1.mElement.getAttributes();
      Node nod1 = attr1.getNamedItem(FoBorderRightAttribute.ATTRIBUTE_NAME.getQName());
      Assert.assertNull(nod1);
     
      //save
View Full Code Here

        Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM);
      borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE);
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = doc.getTableByName("Sheet1");
     
      Cell cell = table.getCellByPosition(0, 0);
      cell.setBorders(CellBordersType.DIAGONAL_LINES, borderbase);

      //validate
      TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite();
      NamedNodeMap attr = styleCell.mElement.getAttributes();
     
      Node nod = attr.getNamedItem("style:diagonal-bl-tr");
      Assert.assertEquals("3.0701cm solid #00ff00", nod.getNodeValue());
     
View Full Code Here

      Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM);
      borderbase.setLineStyle(StyleTypeDefinitions.LineType.SINGLE);
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = doc.getTableByName("Sheet1");
     
      Cell cell = table.getCellByPosition(2, 2);
      cell.setBorders(CellBordersType.ALL_FOUR, borderbase);

      //validate
      TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite();
      Border bor = styleCell.getBorder();
      Assert.assertEquals(borderbase, bor);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
View Full Code Here

      Border borderbase = new Border(Color.LIME, 3.0701, 0.0208, 0.0346, SupportedLinearMeasure.CM);
      borderbase.setLineStyle(StyleTypeDefinitions.LineType.DOUBLE);
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = doc.getTableByName("Sheet1");
     
      Cell cell = table.getCellByPosition(2, 2);
      cell.setBorders(CellBordersType.RIGHT, borderbase);

      //validate
      TableCellProperties styleCell = cell.getStyleHandler().getTableCellPropertiesForWrite();
      Border bor = styleCell.getRightBorder();
      Assert.assertEquals(borderbase, bor);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
View Full Code Here

    TextSelection item = null;
    Node parent = containerElement.getParentNode();
    while (parent != null) {
      if (TableTableCellElementBase.class.isInstance(parent)) {
        TableTableCellElementBase cellElement = (TableTableCellElementBase) parent;
        Cell cell = Cell.getInstance(cellElement);
        item = new CellSelection(mNextText, containerElement, nextIndex, cell);
        break;
      } else {
        OdfName odfName = ((OdfElement) parent).getOdfName();
        String ns = odfName.getPrefix();
View Full Code Here

      table.setTableName("headerTable");
      int rowCount = table.getRowCount();
      int columnCount = table.getColumnCount();
      String expectedCellValue = "header table cell";
      table.getCellByPosition(1, 1).setStringValue(expectedCellValue);
      Cell cell = table.getCellByPosition(4, 0);
      cell.setImage(ResourceUtilities.getURI("image_list_item.png"));
      // first page
      header = doc.getHeader(true);
      Assert.assertNotNull(header);

      table = header.addTable();
      table.setTableName("headerHTable");
      doc.save(ResourceUtilities.newTestOutputFile(headerDocumentPath));
     
      // load the document again.
      doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream(headerDocumentPath));
      header = doc.getHeader();
      table = header.getTableByName("headerTable");
      Assert.assertEquals(rowCount, table.getRowCount());
      Assert.assertEquals(columnCount, table.getColumnCount());
      Assert.assertEquals(expectedCellValue, table.getCellByPosition(1, 1).getStringValue());
      cell = table.getCellByPosition(4, 0);
      Assert.assertEquals(34, cell.getBufferedImage().getHeight(null));
      table.getColumnByIndex(4).setWidth(15);
     
      header = doc.getHeader(true);
      table = header.getTableByName("headerHTable");
      Assert.assertNotNull(table);
View Full Code Here

      Table table = footer.addTable(1, 1);
      table.setTableName("footerTable");
      int rowCount = table.getRowCount();
      int columnCount = table.getColumnCount();
      String expectedCellValue = "footer table cell";
      Cell cellByPosition = table.getCellByPosition(0, 0);
      cellByPosition.setStringValue(expectedCellValue);
      cellByPosition.setHorizontalAlignment(HorizontalAlignmentType.CENTER);
      cellByPosition.setCellBackgroundColor(Color.GREEN);
     
      //first page
      footer = doc.getFooter(true);
      Assert.assertNotNull(footer);
      table = footer.addTable(1, 2);
      table.setTableName("footerFTable");
      doc.save(ResourceUtilities.newTestOutputFile(footerDocumentPath));

      // load the document again.
      doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream(footerDocumentPath));
      footer = doc.getFooter();
      table = footer.getTableByName("footerTable");
      Assert.assertEquals(rowCount, table.getRowCount());
      Assert.assertEquals(columnCount, table.getColumnCount());
      Assert.assertEquals(expectedCellValue, cellByPosition.getStringValue());

      footer = doc.getFooter(true);
      table = footer.getTableByName("footerFTable");
      Assert.assertNotNull(table);
    } catch (Exception e) {
View Full Code Here

 

  private void replace(ReplacementAction replacementAction) throws Exception {
    TextDocument docToReplaceIn = TextDocument.newTextDocument();
    Table newTable = docToReplaceIn.getTableBuilder().newTable(2, 2);
    Cell cell = newTable.getCellByPosition(0, 0);
    cell.addParagraph("<<ONE>>");
    cell.addParagraph("<<TWO>>");

    Map<String, String> replacements = new TreeMap<String, String>();
    replacements.put("<<ONE>>", "1");
    replacements.put("<<TWO>>", "2");

    // sanity check
    Assert.assertEquals("<<ONE>>\n<<TWO>>", cell.getDisplayText());
    Assert.assertEquals("<<ONE>>\n<<TWO>>", cell.getStringValue());
   
    for (String toReplace : replacements.keySet()) {
      TextNavigation navigation = new TextNavigation(toReplace, docToReplaceIn);
      while (navigation.hasNext()) {
        TextSelection selection = (TextSelection) navigation.nextSelection();
        Assert.assertEquals(toReplace, selection.getElement().getTextContent());
        replacementAction.replace(selection, replacements.get(toReplace));
      }
    }

    Assert.assertEquals("1\n2", cell.getDisplayText());
    Assert.assertEquals("1\n2", cell.getStringValue());
  }
View Full Code Here

TOP

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

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.