Examples of OdfSpreadsheetDocument


Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

    fcell.setHorizontalAlignment("right");
    align = fcell.getHorizontalAlignment();
    Assert.assertEquals("end", align);
    saveods();

    OdfSpreadsheetDocument ods;
    try {
      ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell cell = tbl.getCellByPosition(0, 0);
      String horizonAlignment = cell.getHorizontalAlignment();
      Assert.assertEquals(null, horizonAlignment);
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

    fcell.setVerticalAlignment("bottom");
    align = fcell.getVerticalAlignment();
    Assert.assertEquals("bottom", align);
    saveods();
    OdfSpreadsheetDocument ods;
    try {
      ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell cell = tbl.getCellByPosition(0, 0);
      String verticalAlignment = cell.getVerticalAlignment();
      Assert.assertEquals(null, verticalAlignment);
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

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

    OdfSpreadsheetDocument ods;
    try {
      ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

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

    //test value type adapt function.
    OdfSpreadsheetDocument ods;
    try {
      ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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 = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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 = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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 = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

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

    OdfSpreadsheetDocument ods;
    try {
      ods = OdfSpreadsheetDocument.newSpreadsheetDocument();
      OdfTable tbl = ods.getTableByName("Sheet1");
      OdfTableCell 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

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

    }
  }

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

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

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

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

    @Override
    public void export(final Project project, Properties params, Engine engine,
            OutputStream outputStream) throws IOException {

        final OdfSpreadsheetDocument odfDoc;
        try {
            odfDoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
        } catch (Exception e) {
            throw new IOException("Failed to create spreadsheet",e);
        }
       
        TabularSerializer serializer = new TabularSerializer() {
            OdfTable table;
            //int rowCount = 0;
           
            @Override
            public void startFile(JSONObject options) {
                table = OdfTable.newTable(odfDoc);
                table.setTableName(ProjectManager.singleton.getProjectMetadata(project.id).getName());
            }

            @Override
            public void endFile() {
            }

            @Override
            public void addRow(List<CellData> cells, boolean isHeader) {
                OdfTableRow r = table.appendRow();
                //rowCount++;
               
                for (int i = 0; i < cells.size(); i++) {
                    OdfTableCell c = r.getCellByIndex(i); // implicitly creates cell
                    CellData cellData = cells.get(i);

                    if (cellData != null && cellData.text != null && cellData.value != null) {
                        Object v = cellData.value;
                        if (v instanceof Number) {
                            c.setDoubleValue(((Number) v).doubleValue());
                        } else if (v instanceof Boolean) {
                            c.setBooleanValue(((Boolean) v).booleanValue());
                        } else if (v instanceof Date) {
                            Calendar cal = Calendar.getInstance();
                            cal.setTime((Date) v);
                            c.setDateValue(cal);
                        } else if (v instanceof Calendar) {
                            c.setDateValue((Calendar) v);
                        } else {
                            c.setStringValue(cellData.text);
                        }

                        if (cellData.link != null) {
                            // TODO: How do we do output hyperlinks?
                        }
                    }
                }
            }
        };
       
        CustomizableTabularExporterUtilities.exportRows(
                project, engine, params, serializer);
       
        try {
            odfDoc.save(outputStream);
        } catch (Exception e) {
            throw new IOException("Error saving spreadsheet",e);
        }
        outputStream.flush();
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

      }
    }
    else if (outpath.getName().endsWith(".ods")) {
      in = FormUtils.class.getResourceAsStream("/forms/ods/bulk_input.ods");
      if (in != null) {
        OdfSpreadsheetDocument oDoc = OdfSpreadsheetDocument.loadDocument(in);
        oDoc.save(outpath);
      }
      else {
        throw new IOException("Could not read from resource.");
      }
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

      }
    }
    else if (outpath.getName().endsWith(".ods")) {
      in = FormUtils.class.getResourceAsStream("/forms/ods/plate_input.ods");
      if (in != null) {
        OdfSpreadsheetDocument oDoc = OdfSpreadsheetDocument.loadDocument(in);
        oDoc.save(outpath);
      }
      else {
        throw new IOException("Could not read from resource.");
      }
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument

    if (inPath.getName().endsWith(".xlsx")) {
      XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(inPath));
      return process384PlateInputXLSX(wb, u, manager, libraryNamingScheme);
    }
    else if (inPath.getName().endsWith(".ods")) {
      OdfSpreadsheetDocument oDoc = (OdfSpreadsheetDocument) OdfDocument.loadDocument(inPath);
      return process384PlateInputODS(oDoc, u, manager, libraryNamingScheme);
    }
    else {
      throw new UnsupportedOperationException("Cannot process bulk input files other than xls, xlsx, and ods.");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.