Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.SpreadsheetDocument


  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

 
 
  @Test
  public void testNewFont4() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Color.GREEN, 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());
View Full Code Here

 
 
  @Test
  public void testNewFont5() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Color.GREEN, StyleTypeDefinitions.TextLinePosition.REGULAR, 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());
View Full Code Here

 
 
  @Test
  public void testEquals() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Color.GREEN, StyleTypeDefinitions.TextLinePosition.REGULAR, 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.assertTrue(font.equals(font1));
     
View Full Code Here

  private static final String TEST_FILE = "ChartTest.ods";

  @Test
  public void testSetValuesFromSpreadsheet() {
    try {
      SpreadsheetDocument sheet = (SpreadsheetDocument) Document.loadDocument(ResourceUtilities.getTestResourceAsStream(TEST_FILE));
      DataSet data = new DataSet();
      data.setValues(CellRangeAddressList.valueOf("A.A1:A.C4"), sheet, true, true, true);
      Assert.assertEquals("A.A1:A.C4", data.getCellRangeAddress().toString());
      printDataset(data);
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.