Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.SpreadsheetDocument


  }

  @Test
  public void testMergeExpandCellRange() {
    try {
      SpreadsheetDocument ods = SpreadsheetDocument.newSpreadsheetDocument();
      // the doc contain the table which only have one column and one row
      // element
      Table table = ods.getTableByName("Sheet1");
      int nCols = table.getColumnCount();
      int nRows = table.getRowCount();
      Assert.assertTrue(nCols == 1);
      Assert.assertTrue(nRows == 1);
      CellRange cellRange = table.getCellRangeByPosition("A1", "E1");
      Cell cell = table.getCellByPosition("A1");
      cell.setStringValue("Merge A1:E1");
      cellRange.merge();
      Table table2 = Table.newTable(ods, 1, 1);
      table2.setTableName("Sheet2");
      CellRange cellRange2 = table2.getCellRangeByPosition("A1", "F3");
      Cell cell2 = table2.getCellByPosition("A1");
      cell2.setStringValue("Merge A1:F3");
      cellRange2.merge();
      ods.save(ResourceUtilities.newTestOutputFile(filename + "MergeExpandCell.ods"));
      table = ods.getTableByName("Sheet1");
      Assert.assertTrue(table.getColumnCount() == 5);
      Assert.assertTrue(table.getRowCount() == 1);
      table = ods.getTableByName("Sheet2");
      Assert.assertTrue(table.getColumnCount() == 6);
      Assert.assertTrue(table.getRowCount() == 3);
      TextDocument odt = TextDocument.newTextDocument();
      Table swTable = Table.newTable(odt, 1, 5);
      CellRange swCellRange = swTable.getCellRangeByPosition("A1", "E2");
View Full Code Here


    // get type
    align = fcell.getHorizontalAlignmentType();
    Assert.assertEquals(HorizontalAlignmentType.RIGHT, align);
    saveods();

    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell = tbl.getCellByPosition(0, 0);
      HorizontalAlignmentType horizonAlignment = cell.getHorizontalAlignmentType();
      Assert.assertEquals(HorizontalAlignmentType.DEFAULT, horizonAlignment);

      table = ods.getTableByName("Sheet2");
      if (table != null) {
        table.remove();
      }
      table = Table.newTable(ods);
      table.setTableName("Sheet2");
View Full Code Here

    fcell.setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType.BOTTOM);
    align = fcell.getVerticalAlignmentType();
    Assert.assertEquals(StyleTypeDefinitions.VerticalAlignmentType.BOTTOM, align);
    saveods();
    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell = tbl.getCellByPosition(0, 0);
      StyleTypeDefinitions.VerticalAlignmentType verticalAlignment = cell.getVerticalAlignmentType();
      Assert.assertEquals(StyleTypeDefinitions.VerticalAlignmentType.DEFAULT, verticalAlignment);

      table = ods.getTableByName("Sheet2");
      if (table != null) {
        table.remove();
      }
      table = Table.newTable(ods);
      table.setTableName("Sheet2");
View Full Code Here

    fcell.setValueType("date");
    String valueType = fcell.getValueType();
    Assert.assertEquals("date", valueType);
    saveods();

    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell = tbl.getCellByPosition(0, 0);
      valueType = cell.getValueType();
      Assert.assertEquals(null, valueType);
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

      Assert.fail(e.getMessage());
    }
    saveods();

    // test value type adapt function.
    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell;
      for (int i = 1; i <= 10; i++) {
        cell = tbl.getCellByPosition("A" + i);
        cell.setDoubleValue(new Double(i));
      }
      cell = tbl.getCellByPosition("A11");
      cell.setFormula("=sum(A1:A10)");
      // contains '#' should be adapted as float.
      cell.setFormatString("#,###");
      Assert.assertEquals("float", cell.getValueType());
      cell = tbl.getCellByPosition("A12");
      cell.setFormula("=sum(A1:A10)");
      // contains '0' should be adapted as float.
      cell.setFormatString("0.00");
      Assert.assertEquals("float", cell.getValueType());
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell;
      for (int i = 1; i <= 10; i++) {
        cell = tbl.getCellByPosition("A" + i);
        cell.setPercentageValue(0.1);
      }
      cell = tbl.getCellByPosition("A11");
      cell.setFormula("=sum(A1:A10)");
      // contains '%'should be adapted as percentage.
      cell.setFormatString("###.0%");
      Assert.assertEquals("percentage", cell.getValueType());
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell;
      for (int i = 1; i <= 10; i++) {
        cell = tbl.getCellByPosition("A" + i);
        cell.setDateValue(Calendar.getInstance());
        cell.setFormatString("yyyy.MM.dd");
      }
      cell = tbl.getCellByPosition("A11");
      cell.setFormula("=max(A1:A10)");
      // contains 'y' 'M' 'd' should be adapted as date.
      cell.setFormatString("yyyy.MM.dd");
      Assert.assertEquals("date", cell.getValueType());
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell;
      for (int i = 1; i <= 10; i++) {
        cell = tbl.getCellByPosition("A" + i);
        cell.setTimeValue(Calendar.getInstance());
        cell.setFormatString("yyyy.MM.dd HH:mm:ss");
View Full Code Here

    loadOutputSpreadsheet();
    table = odsdoc.getTableByName("Sheet1");
    fcell = table.getCellByPosition(columnindex, rowindex);
    Assert.assertEquals(expectedColor.toString(), fcell.getCellBackgroundColor().toString());

    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      Cell cell = tbl.getCellByPosition(0, 0);
      Color actualBackColor = cell.getCellBackgroundColor();
      Assert.assertEquals("#ffffff", actualBackColor.toString());
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

    }
  }

  @Test
  public void testSetDefaultCellStyle() {
    SpreadsheetDocument outputDocument;
    OdfContentDom contentDom; // the document object model for content.xml
    // the office:automatic-styles element in content.xml
    OdfOfficeAutomaticStyles contentAutoStyles;
    OdfStyle style;
    String noaaDateStyleName;
    String noaaTempStyleName;

    try {
      outputDocument = SpreadsheetDocument.newSpreadsheetDocument();
      contentDom = outputDocument.getContentDom();
      contentAutoStyles = contentDom.getOrCreateAutomaticStyles();

      OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom, "yyyy-MM-dd", "numberDateStyle", null);
      OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom, "#0.00", "numberTemperatureStyle");
View Full Code Here

  }

  @Test
  public void testColumnWidthCompareNewTableWithGetCellByPosition() {
    try {
      SpreadsheetDocument odsDoc = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = Table.newTable(odsDoc, 20, 20);
      table.setTableName("Table1");
      double width1 = table.getColumnByIndex(0).getWidth();
      table = Table.newTable(odsDoc);
      table.setTableName("Table2");
View Full Code Here

      for (int i = 0; i < columnCount; i++) {
        columnLabels[i] = "ColumnHeader" + i;
      }
      double[][] doubleArray = null;
      String[][] stringArray = null;
      SpreadsheetDocument spreadsheet = SpreadsheetDocument.newSpreadsheetDocument();
      Table table1 = Table.newTable(spreadsheet, null, null, doubleArray);
      Assert.assertEquals(0, table1.getHeaderColumnCount());
      Assert.assertEquals(0, table1.getHeaderRowCount());
      // row count should be DEFAULT_ROW_COUNT 2
      Assert.assertEquals(2, table1.getRowCount());
View Full Code Here

  @Test
  public void testNewTableWithoutHeaderColumn() {
    try {
      // reproduce bug 145
      SpreadsheetDocument spreadsheet = SpreadsheetDocument.newSpreadsheetDocument();
      Table sheet = Table.newTable(spreadsheet, 3, 5);
      TableTableHeaderColumnsElement headers = OdfElement.findFirstChildNode(
          TableTableHeaderColumnsElement.class, sheet.getOdfElement());
      if (headers != null) {
        for (Node n : new DomNodeList(headers.getChildNodes())) {
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.SpreadsheetDocument

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.