Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.SpreadsheetDocument


  private static final String CHART_FILE_ODP = "TestODPChart.odp";

  @Test
  public void testEquals() {
    try {
      SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      String title = "Main";
      String[] lables = new String[]{"Anna","Daisy","Tony","MingFei"};
      String[] legends = new String[]{"Day1","Day2","Day3"};
      double[][] data = new double[][]{{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
      DataSet dataset = new DataSet(lables,legends,data);
      Rectangle rect = new Rectangle();
      rect.x = 67;
      rect.y = 89;
      rect.width = 379;
      rect.height = 424;
      Chart chart = new Chart(doc.getContentDom().getRootElement().newOfficeBodyElement().newOfficeChartElement().newChartChartElement(null), null);
      chart.setChartTitle(title);
      chart.setChartType(ChartType.AREA);
      chart.setUseLegend(true);
      chart.setChartData(dataset);
      Assert.assertEquals(dataset, chart.getChartData());
View Full Code Here


    }
  }

  @Test
  public void testCreateChartWithLocalData() {
    SpreadsheetDocument doc;
    try {
      doc = SpreadsheetDocument.newSpreadsheetDocument();
      String title = "LocalData";
      // double[][] data = new double[3][3];
      String[] lables = new String[] { "Anna", "Daisy", "Tony", "MingFei" };
      String[] legends = new String[] { "Day1", "Day2", "Day3" };
      double[][] data = new double[][] { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, { 3, 4, 5, 6 } };
      Rectangle rect = new Rectangle();
      rect.x = 2000;
      rect.y = 2700;
      rect.width = 10000;
      rect.height = 12000;
      Chart newChart = doc.createChart(title, lables, legends, data, rect);
      Chart chart = doc.getChartById(newChart.getChartID());
      DataSet ds = chart.getChartData();
      Assert.assertEquals(title, chart.getChartTitle());
      Assert.assertEquals(ChartType.BAR, chart.getChartType());
      Assert.assertArrayEquals(lables, ds.getLabels());
      Assert.assertArrayEquals(legends, ds.getLegends());
      Assert.assertTrue(legends.length == ds.getDataSeriesCount());
      Assert.assertNotNull(doc.getChartByTitle("LocalData"));
      Assert.assertTrue(chart.isUseLegend() == false);
      chart.setChartTitle("Chart with local-data");
      chart.setUseLegend(false);
      Assert.assertEquals(chart.getChartTitle(), "Chart with local-data");
      Assert.assertFalse(chart.isUseLegend() == true);
      doc.save(ResourceUtilities.newTestOutputFile(CHART_FILE1));

      Document doc1 = Document.loadDocument(ResourceUtilities.getTestResourceAsStream(CHART_FILE1));
      Assert.assertEquals(doc1.getMediaTypeString(), Document.OdfMediaType.SPREADSHEET.getMediaTypeString());
      doc = (SpreadsheetDocument) doc1;

      Assert.assertNotNull(doc.getChartByTitle("Chart with local-data"));
      Assert.assertNotNull(doc.getChartByTitle("LocalData"));

      newChart = doc.getChartByTitle("Chart with local-data").get(0);
      Assert.assertArrayEquals(newChart.getChartData().getLabels(), ds.getLabels());
      Assert.assertEquals(ChartType.BAR, newChart.getChartType());
      Assert.assertEquals(newChart.getChartData().getLegendByIndex(1), legends[1]);
      Assert.assertTrue(legends.length == newChart.getChartData().getDataSeriesCount());
View Full Code Here

  }

  @Test
  public void testCreateChartWithCellRange() {
    try {
      SpreadsheetDocument doc = (SpreadsheetDocument) Document.loadDocument(ResourceUtilities
          .getTestResourceAsStream(TEST_FILE));
      String barTitle = "Bar Chart with CellRange ";
      String areaTitle = "AREA Chart with CellRange";
      Rectangle rect = new Rectangle();
      rect.x = 2000;
      rect.y = 2700;
      rect.width = 10000;
      rect.height = 12000;
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.A1:A.E21"), true, true, true, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.A1:A.E21"), true, true, false, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.B1:A.E21"), true, false, true, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.B1:A.E21"), true, false, false, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.A2:A.E21"), false, true, true, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.A2:A.E21"), false, true, false, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.B2:A.E21"), false, false, true, rect);
      doc.createChart(barTitle, doc, CellRangeAddressList.valueOf("A.B2:A.E21"), false, false, false, rect);
      Chart chartID8 = doc.createChart(areaTitle, doc, CellRangeAddressList.valueOf("A.B2:A.E21"), false, false,
          false, rect);
      Chart chart8 = doc.getChartById(chartID8.getChartID());
      chart8.setChartType(ChartType.AREA);
      Assert.assertEquals(ChartType.AREA, chart8.getChartType());
      //Assert.assertEquals(8, doc.getChartByTitle(barTitle).size());
      Assert.assertNotNull(doc.getChartByTitle(areaTitle));
      doc.save(ResourceUtilities.newTestOutputFile(CHART_FILE2));
     
    } catch (Exception e) {
      Logger.getLogger(DataSetTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
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

  }

  @Test
  public void testGetColumnCountWithColumnsInDocument() {
    try {
      SpreadsheetDocument sDoc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("Spreadsheet with Embeded Chart.ods"));
      List<Document> charts = sDoc.getEmbeddedDocuments(OdfMediaType.CHART);
      for (Document chart : charts) {
        // "local-table" is the inner table name of chart document with
        // 2 columns
        Table localTable = chart.getTableByName("local-table");
        int columnCount = localTable.getColumnCount();
View Full Code Here

    Assert.assertEquals("stringM15", cell.getStringValue());
  }

  @Test
  public void testGetCellWithAutoExtend() {
    SpreadsheetDocument ods;
    try {
      ods = SpreadsheetDocument.newSpreadsheetDocument();
      Table tbl = ods.getTableByName("Sheet1");
      tbl.setTableName("Tests");
      Cell cell = tbl.getCellByPosition(5, 5);
      Assert.assertNotNull(cell);
      Assert.assertEquals(6, tbl.getRowCount());
      Assert.assertEquals(6, tbl.getColumnCount());
View Full Code Here

  @Test
  public void testAppendRow() {
    OdfFileDom dom;
    try {
      SpreadsheetDocument odsDoc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODSAppendRow.ods"));
      dom = odsDoc.getContentDom();
      NodeList tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdsTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdsTable);
      }
      odsDoc.save(ResourceUtilities.newTestOutputFile("TestODSAppendRowOutput.ods"));

      TextDocument odtDoc = TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODTAppendRow.odt"));
      dom = odtDoc.getContentDom();
      tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
View Full Code Here

  @Test
  public void testRemoveChart() {

    try {
      SpreadsheetDocument doc = (SpreadsheetDocument) Document.loadDocument(ResourceUtilities
          .getTestResourceAsStream(CHART_FILE2));
      doc.deleteChartById("Object 1");
      //Assert.assertEquals(9, doc.getChartCount());
      String barTitle = "Bar Chart with CellRange ";
      String areaTitle = "AREA Chart with CellRange";
      doc.deleteChartByTitle(barTitle);
      Assert.assertNotNull(doc.getChartByTitle(areaTitle));
      Assert.assertEquals(1, doc.getChartCount());
      doc.save(ResourceUtilities.newTestOutputFile(CHART_FILE3));

    } catch (Exception e) {
      Logger.getLogger(DataSetTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'");
    }
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.