Package org.odftoolkit.simple.table

Examples of org.odftoolkit.simple.table.Table


  public void testGetTableList() {
    try {
      //TextDocument doc = TextDocument.loadDocument(ResourceUtilities.getTestResourceAsStream("headerFooterHidden.odt"));
      TextDocument doc = TextDocument.newTextDocument();
      Footer footer = doc.getFooter();
      Table tab = footer.addTable();
     
      List<Table> tabList = footer.getTableList();
      Assert.assertEquals(tab, tabList.get(0));
     
      //save
View Full Code Here


      TextDocument doc = TextDocument.newTextDocument();
      Footer footer = doc.getFooter();
      //Table tab = footer.addTable();
     
      TableBuilder tb = footer.getTableBuilder();
      Table tab = tb.newTable();
     
      Assert.assertNotNull(tab);
      Assert.assertTrue(2 == tab.getRowCount());
      Assert.assertTrue(5 == tab.getColumnCount());
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("footerOutput.odt"));
    } catch (Exception e) {
      Logger.getLogger(FooterTest.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

      TextDocument doc = TextDocument.newTextDocument();
      Footer footer = doc.getFooter();
      OdfElement odfEle = footer.getVariableContainerElement();
     
      TableBuilder tb = footer.getTableBuilder();
      Table tab = tb.newTable();
     
      Assert.assertNotNull(tab);
      Assert.assertTrue(2 == tab.getRowCount());
      Assert.assertTrue(5 == tab.getColumnCount());
     
      Node nod = odfEle.getFirstChild();
      Assert.assertEquals("table:table", nod.getNodeName());
     
      //save
View Full Code Here

        Assert.assertTrue(subList.getLevel() == 2);
      } else {
        Assert.fail("list iterate fail.");
      }
      // list in cell
      Table table = Table.newTable(odtdoc);
      Cell cell = table.getCellByPosition(0, 0);
      List cellList = cell.addList();
      Assert.assertTrue(cellList.getLevel() == 1);
    } catch (Exception e) {
      Logger.getLogger(ListTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
View Full Code Here

    Font font3Base = new Font("SimSun", FontStyle.BOLD, 8, Color.BLACK, TextLinePosition.REGULAR);
    Font font4Base = new Font("Arial", FontStyle.REGULAR, 10, Color.BLACK, TextLinePosition.UNDER);
    try {
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(filename));
      Table table = doc.getTableByName("A");
      Cell cell1 = table.getCellByPosition("A2");
      CellStyleHandler handler1 = cell1.getStyleHandler();
      Font font1 = handler1.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font1Base, font1);

      Cell cell2 = table.getCellByPosition("A3");
      CellStyleHandler handler2 = cell2.getStyleHandler();
      Font font2 = handler2.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font2Base, font2);

      Cell cell3 = table.getCellByPosition("A4");
      CellStyleHandler handler3 = cell3.getStyleHandler();
      Font font3 = handler3.getFont(Document.ScriptType.CJK);
      Assert.assertEquals(font3Base, font3);
      Font font4 = handler3.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font4Base, font4);

      Cell cell5 = table.getCellByPosition("B2");
      cell5.getStyleHandler().setFont(font1Base);
      cell5.setStringValue("Arial Italic black 10");
      Assert.assertEquals(font1Base, cell5.getStyleHandler().getFont(Document.ScriptType.WESTERN));

      Cell cell6 = table.getCellByPosition("B3");
      // font2Base.setLocale();
      cell6.getStyleHandler()
          .setFont(font2Base, new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
      cell6.setStringValue("Times New Roman, Regular, 13.9, Red");
      Assert.assertEquals(font2Base, cell6.getStyleHandler().getFont(Document.ScriptType.WESTERN));

      Cell cell7 = table.getCellByPosition("B4");
      cell7.getStyleHandler().setFont(font3Base,
          new Locale(Locale.CHINESE.getLanguage(), Locale.CHINA.getCountry()));
      cell7.getStyleHandler()
          .setFont(font4Base, new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
      cell7.setStringValue("SimSun BOLD 8 BLACK");
View Full Code Here

   
    String[] columnlabels = new String[columncount];
    for (int i = 0; i < columncount; i++) {
      columnlabels[i] = "ColumnHeader" + i;
    }
    Table table = Table.newTable(sourcedoc, rowlabels, columnlabels, data);
    table.setTableName(tablename);
   
    String tablename2 = "Table2";
    int rowcount2 = 10, columncount2 = 4;
    double[][] data2 = new double[rowcount2][columncount2];
    for (int i = 0; i < rowcount2; i++) {
      for (int j = 0; j < columncount2; j++) {
        data2[i][j] = Math.random();
      }
    }
   
    String[] rowlabels2 = new String[rowcount2];
    for (int i = 0; i < rowcount2; i++) {
      rowlabels2[i] = "RowHeader" + i;
    }
   
    String[] columnlabels2 = new String[columncount2];
    for (int i = 0; i < columncount2; i++) {
      columnlabels2[i] = "ColumnHeader" + i;
    }
   
    Table table2 = Table.newTable(sourcedoc, rowlabels2, columnlabels2, data2);
    table2.setTableName(tablename2);
    String tablename3 = "Table3";
    int rownumber3 = 5;
    int clmnumber3 = 3;
    Table table1 = Table.newTable(sourcedoc, rownumber3, clmnumber3);
    table1.setTableName(tablename3);
    search = null;
    // 6 Simple, at the middle of original Paragraph, split original
    // Paragraph, insert before the second Paragraph.
    search = new TextNavigation("SIMPLE", doc);
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      table = sourcedoc.getTableByName("Table1");
      Cell cell = table.getCellByPosition(0, 0);
      cell.setStringValue("SIMPLE");
      Table newtable = item.replaceWith(table);
      Assert.assertNotNull(newtable);
      Assert.assertEquals(1, newtable.getHeaderColumnCount());
      Assert.assertEquals(1, newtable.getHeaderRowCount());
      Assert.assertEquals(7 + 1, newtable.getRowCount());
      Assert.assertEquals(5 + 1, newtable.getColumnCount());
      cell = newtable.getCellByPosition(1, 1);
      Assert.assertEquals("string", cell.getValueType());
    }
    // 2 Task1, #1 at the start of original Paragraph, #2 replace original
    // Paragraph
    search = new TextNavigation("Task1", doc);
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      table = sourcedoc.getTableByName("Table2");
      Table newtable = item.replaceWith(table);
      Cell cell = newtable.getCellByPosition(0, 0);
      cell.setStringValue("From Source Table2");
      Assert.assertNotNull(newtable);
      Assert.assertEquals(1, newtable.getHeaderColumnCount());
      Assert.assertEquals(1, newtable.getHeaderRowCount());
      Assert.assertEquals(10 + 1, newtable.getRowCount());
      Assert.assertEquals(4 + 1, newtable.getColumnCount());
     
      cell = newtable.getCellByPosition(1, 1);
      Assert.assertEquals("float", cell.getValueType());
    }
    // 1 RESS%>, #1 at the end of original Paragraph,
    search = new TextNavigation("RESS%>", doc);
   
    while (search.hasNext()) {
      TextSelection item = (TextSelection) search.nextSelection();
      table = sourcedoc.getTableByName("Table3");
      Table newtable = item.replaceWith(table);
      Cell cell = newtable.getCellByPosition(0, 0);
      cell.setStringValue("From Source Table3");
      Assert.assertNotNull(newtable);
      Assert.assertEquals(5, newtable.getRowCount());
      Assert.assertEquals(3, newtable.getColumnCount());
    }
    try {
      doc.save(ResourceUtilities.newTestOutputFile("TextSelectionReplacewithTableResult.odt"));
    } catch (Exception e) {
      Logger.getLogger(TextSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
    doc = (TextDocument) Document.loadDocument(ResourceUtilities
        .getAbsolutePath(TEST_FILE));
    search = new TextNavigation("<<target>>", doc);
    int i = 0;
    try {
      while (search.hasNext()) {
        i++;
        TextSelection item = (TextSelection) search.nextSelection();
        table = sourcedoc.getTableByName("Table1");
        Table newtable = item.replaceWith(table);
        Assert.assertNotNull(newtable);
        Assert.assertEquals(1, newtable.getHeaderColumnCount());
        Assert.assertEquals(1, newtable.getHeaderRowCount());
        Assert.assertEquals(7 + 1, newtable.getRowCount());
        Assert.assertEquals(5 + 1, newtable.getColumnCount());
        Cell cell = newtable.getCellByPosition(1, 1);
        Assert.assertEquals("string", cell.getValueType());
      }
      doc.save(ResourceUtilities
          .newTestOutputFile("TextSelectionReplacewithTableResult-BasicCases.odt"));
      verifyReplaceWithTableByBasicCases("TextSelectionReplacewithTableResult-BasicCases.odt");
View Full Code Here

  }

  @Test
  public void testGetSetFontInODT() throws Exception {
    TextDocument doc = TextDocument.newTextDocument();
    Table table = Table.newTable(doc);
    Font font = table.getCellByPosition(0, 0).getFont();
    Assert.assertNotNull(font);
  }
View Full Code Here

 
  @Test
  public void testNewFont1() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5);
      Cell cell = table.getCellByPosition("A1");
      cell.setFont(font);
      cell.setStringValue("Hello world .");
     
      //save
      document.save(ResourceUtilities.newTestOutputFile("testFontOutput1.ods"));
     
      //validate
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("testFontOutput1.ods"));
      Table table1 = doc.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      Font font1 = cell1.getFont();
      Assert.assertEquals(font.getFamilyName(), font1.getFamilyName());
      Assert.assertEquals(font.getSize(), font1.getSize());
      Assert.assertEquals(font.getFontStyle(), font1.getFontStyle());
     
View Full Code Here

 
  @Test
  public void testNewFont2() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Color.BLUE);
      Cell cell = table.getCellByPosition("A1");
      cell.setFont(font);
      cell.setStringValue("Hello world .");
     
      //save
      document.save(ResourceUtilities.newTestOutputFile("testFontOutput1.ods"));
     
      //validate
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("testFontOutput1.ods"));
      Table table1 = doc.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      Font font1 = cell1.getFont();
      Assert.assertEquals(font.getFamilyName(), font1.getFamilyName());
      Assert.assertEquals(font.getSize(), font1.getSize());
      Assert.assertEquals(font.getFontStyle(), font1.getFontStyle());
      Assert.assertEquals(font.getColor().toString(), font1.getColor().toString());
View Full Code Here

 
  @Test
  public void testNewFont3() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Locale.ENGLISH);
      Cell cell = table.getCellByPosition("A1");
      cell.setFont(font);
      cell.setStringValue("Hi World.");
     
      //save
      document.save(ResourceUtilities.newTestOutputFile("testFontOutput1.ods"));
     
      //validate
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("testFontOutput1.ods"));
      Table table1 = doc.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      Font font1 = cell1.getFont();
      Assert.assertEquals(font.getFamilyName(), font1.getFamilyName());
      Assert.assertEquals(font.getSize(), font1.getSize());
      Assert.assertEquals(font.getFontStyle(), font1.getFontStyle());
      Assert.assertEquals(font.getTextLinePosition(), font1.getTextLinePosition());
View Full Code Here

TOP

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

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.