Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.SpreadsheetDocument


    }
  }

  @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 testSetGetFont() {
    try {
      SpreadsheetDocument document;
      document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table1 = document.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      cell1.setStringValue("abcdefg");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      cell1.setFont(font1);
      Font font11 = cell1.getFont();
      System.out.println(font11);
      if (!font11.equals(font1))
        Assert.fail();

      Cell cell2 = table1.getCellByPosition("A2");
      cell2.setStringValue("redstring");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      cell2.setFont(font2);
      Font font22 = cell2.getFont();
      System.out.println(font22);
      if (!font22.equals(font2))
        Assert.fail();
      document.save(ResourceUtilities.newTestOutputFile("TestSetGetFont.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
    }
  }
View Full Code Here

  }

  @Test
  public void testSetGetBorder() {
    try {
      SpreadsheetDocument document;
      document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table1 = document.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      cell1.setStringValue("four border");
      Border border = new Border(Color.RED, 1, StyleTypeDefinitions.SupportedLinearMeasure.PT);
      cell1.setBorders(CellBordersType.ALL_FOUR, border);
      Border bottomBorder = cell1.getStyleHandler().getBorder(CellBordersType.BOTTOM);
      Assert.assertEquals(border, bottomBorder);

      Cell cell2 = table1.getCellByPosition("C2");
      cell2.setStringValue("top bottom");
      Border border2 = new Border(Color.BLUE, 5, 1, 2, StyleTypeDefinitions.SupportedLinearMeasure.PT);
      cell2.setBorders(CellBordersType.TOP_BOTTOM, border2);
      Border bottomBorder2 = cell2.getStyleHandler().getBorder(CellBordersType.BOTTOM);
      Assert.assertEquals(border2, bottomBorder2);
      Border bottomBorder22 = cell2.getStyleHandler().getBorder(CellBordersType.LEFT);
      Assert.assertEquals(Border.NONE, bottomBorder22);
      document.save(ResourceUtilities.newTestOutputFile("TestSetGetBorder.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
    }
  }
View Full Code Here

  public void testCellSizeOptimal() {
    Font font1Base = new Font("Arial", FontStyle.REGULAR, 6, Color.GREEN, TextLinePosition.REGULAR);
    Font font2Base = new Font("Times New Roman", FontStyle.REGULAR, 13, Color.RED, TextLinePosition.REGULAR);
    Font font3Base = new Font("SimSun", FontStyle.REGULAR, 17, Color.BLUE, TextLinePosition.REGULAR);
    try {
      final SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      final Table table = doc.addTable();
      final String contentStr = "This is a long text content.";
     
      // basically the default font is of Arial type, so assume the default family
      final String nfFamilyName = "Arial";
     
      if (isFontAvailable(nfFamilyName)) {
        checkCellWidth(table.getCellByPosition(0, 0), null, 44.0977, contentStr);
      }
      if (isFontAvailable(font1Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(1, 1), font1Base, 24.3424, contentStr);
      }
      if (isFontAvailable(font2Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(2, 2), font2Base, 49.7414, contentStr);
      }
      if (isFontAvailable(font3Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(3, 3), font3Base, 88.899, contentStr);
      }
      doc.save(ResourceUtilities.newTestOutputFile("testCellSizeOptimal.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

  @Test
  public void testGetCountry() {
    try {
      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);

      CellStyleHandler cellHandler = cell.getStyleHandler();
      cellHandler.setCountry("English", Document.ScriptType.CJK);
      //validate
      String country = cellHandler.getCountry(Document.ScriptType.CJK);
      Assert.assertEquals("English", country);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
   
View Full Code Here

  @Test
  public void testGetLanguage() {
    try {
      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);

      CellStyleHandler cellHandler = cell.getStyleHandler();
      cellHandler.setLanguage("English", Document.ScriptType.WESTERN);
      //validate
      String language = cellHandler.getLanguage(Document.ScriptType.WESTERN);
      System.out.println(language);
      Assert.assertEquals("English", language);
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
   
View Full Code Here

  @Test
  public void testSetColor() {
    try {
      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);

      CellStyleHandler cellHandler = cell.getStyleHandler();
      cellHandler.setBackgroundColor(Color.RED);
      //validate
      Color red = cellHandler.getBackgroundColor();
      Assert.assertEquals(Color.RED.toString(), red.toString());
     
      //save
      doc.save(ResourceUtilities.newTestOutputFile("testSupportedLinearMeasure.ods"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
   
View Full Code Here

 
  @Test
  public void testSetBorder() {
    Border borderbase = new Border(new Color("#00ccff"), 0.0701, 0.0008, 0.0346, SupportedLinearMeasure.IN);
    try {
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(filename));
      Table table = doc.getTableByName("A");
     
      borderbase.setLinearMeasure(StyleTypeDefinitions.SupportedLinearMeasure.CM);
     
      Cell cell = table.getCellByPosition("A14");
      cell.setBorders(CellBordersType.LEFT, borderbase);
View Full Code Here

 
  @Test
  public void testIsTextWrapped() {
    Border borderbase = new Border(new Color("#00ccff"), 0.0701, 0.0008, 0.0346, SupportedLinearMeasure.CM);
    try {
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(filename));
      Table table = doc.getTableByName("A");
      Cell cell = table.getCellByPosition("A14");
      cell.setStringValue("testIsTextWrapped.");
      cell.setBorders(CellBordersType.ALL_FOUR, borderbase);

      CellStyleHandler cellHandler = cell.getStyleHandler();
View Full Code Here

    cellRange1.setCellRangeName("TimeCellRange");
    cellRange1.merge();

    saveods("CellRangeName");
    try {
      SpreadsheetDocument saveddos = (SpreadsheetDocument) SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(filename + "CellRangeName.ods"));
      Table savedSheet = saveddos.getTableByName("Sheet1");
      CellRange namedCellRange = savedSheet.getCellRangeByName("TimeCellRange");
      Cell cell = namedCellRange.getCellByPosition("A1");
      Assert.assertTrue(cell.getRowSpannedNumber() == 6);
    } catch (Exception e) {
      Logger.getLogger(TableCellRangeTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
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.