Package org.odftoolkit.simple

Examples of org.odftoolkit.simple.SpreadsheetDocument


            Assert.assertEquals(Color.WHITE, newCell.getCellBackgroundColor());
        }
       
        @Test
        public void testSettingBlackBackgroundOnProperties() throws Exception {
            SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
            Table table = doc.getTableByName("Sheet1");
            Cell cell = table.getCellByPosition(1, 1);
            cell.setCellBackgroundColor(Color.BLUE);
            cell.getStyleHandler().getTableCellPropertiesForWrite().setBackgroundColor(Color.BLACK);
            Assert.assertEquals(Color.BLACK, cell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
            Assert.assertEquals(Color.BLACK, cell.getCellBackgroundColor());
View Full Code Here


            Assert.assertEquals(Color.BLACK, newCell.getStyleHandler().getBackgroundColor());
        }
       
        @Test
        public void testSettingNullBackgroundOnCell() throws Exception {
            SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
            Table table = doc.getTableByName("Sheet1");
            Cell cell = table.getCellByPosition(1, 1);
            cell.setCellBackgroundColor((Color) null);
            Assert.assertNull(cell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
            Assert.assertEquals(Color.WHITE, cell.getCellBackgroundColor());
        }
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

  }

  @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

    Font font2Base = new Font("'Times New Roman'", FontStyle.REGULAR, (float) 13.95, new Color("#ff3333"),
        TextLinePosition.THROUGHUNDER);
    Font font3Base = new Font("SimSun", FontStyle.BOLD, 8, Color.BLACK, TextLinePosition.REGULAR);
    Font font4Base = new Font("Arial", FontStyle.REGULAR, 10, Color.BLACK, TextLinePosition.UNDER);
    try {
      SpreadsheetDocument doc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream(filename));
      Table table = doc.getTableByName("A");
      Cell cell1 = table.getCellByPosition("A2");
      CellStyleHandler handler1 = cell1.getStyleHandler();
      Font font1 = handler1.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font1Base, font1);

      Cell cell2 = table.getCellByPosition("A3");
      CellStyleHandler handler2 = cell2.getStyleHandler();
      Font font2 = handler2.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font2Base, font2);

      Cell cell3 = table.getCellByPosition("A4");
      CellStyleHandler handler3 = cell3.getStyleHandler();
      Font font3 = handler3.getFont(Document.ScriptType.CJK);
      Assert.assertEquals(font3Base, font3);
      Font font4 = handler3.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(font4Base, font4);

      Cell cell5 = table.getCellByPosition("B2");
      cell5.getStyleHandler().setFont(font1Base);
      cell5.setStringValue("Arial Italic black 10");
      Assert.assertEquals(font1Base, cell5.getStyleHandler().getFont(Document.ScriptType.WESTERN));

      Cell cell6 = table.getCellByPosition("B3");
      // font2Base.setLocale();
      cell6.getStyleHandler()
          .setFont(font2Base, new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
      cell6.setStringValue("Times New Roman, Regular, 13.9, Red");
      Assert.assertEquals(font2Base, cell6.getStyleHandler().getFont(Document.ScriptType.WESTERN));

      Cell cell7 = table.getCellByPosition("B4");
      cell7.getStyleHandler().setFont(font3Base,
          new Locale(Locale.CHINESE.getLanguage(), Locale.CHINA.getCountry()));
      cell7.getStyleHandler()
          .setFont(font4Base, new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry()));
      cell7.setStringValue("SimSun BOLD 8 BLACK");
      Assert.assertEquals(font3Base, cell7.getStyleHandler().getFont(Document.ScriptType.CJK));
      Assert.assertEquals(font4Base, cell7.getStyleHandler().getFont(Document.ScriptType.WESTERN));

      doc.save(ResourceUtilities.newTestOutputFile("testFontOutput.ods"));

    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
    }
View Full Code Here

  // public String getFontFamilyName(Document.ScriptType type);
 
  @Test
  public void testNewFont1() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5);
      Cell cell = table.getCellByPosition("A1");
      cell.setFont(font);
      cell.setStringValue("Hello 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 testNewFont2() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, Color.BLUE);
      Cell cell = table.getCellByPosition("A1");
      cell.setFont(font);
      cell.setStringValue("Hello 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 testNewFont3() {
    try {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 17.5, 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

  private static final Logger LOGGER =  Logger.getLogger(TextPropertiesTest.class.getName());
 
  @Test
  public void testGetFontSizeInPoint() {
    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("testGetFontStyle.");
     
      TextProperties textProperties = cell.getStyleHandler().getTextPropertiesForWrite();
      textProperties.setFontSizeInPoint(3.32);
     
      //validate
      Double fontInPoint = textProperties.getFontSizeInPoint();
      Assert.assertEquals(3.32, fontInPoint);
     
      //save
      document.save(ResourceUtilities.newTestOutputFile("testFontOutput89.ods"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

 
 
  @Test
  public void testGetFontStyle() {
    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("testGetFontStyle.");
     
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.