Examples of CreationHelper


Examples of org.apache.poi.ss.usermodel.CreationHelper

        File.separator + "WithMoreVariousData.xlsx"
    );
    assertTrue(xml.exists());
     
    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    CreationHelper createHelper = workbook.getCreationHelper();
    assertEquals(3, workbook.getNumberOfSheets());
    XSSFSheet sheet = (XSSFSheet)workbook.getSheetAt(0);

    // Check hyperlinks
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);
   
   
    // Write out, and check
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   
    // Load up again, check all links still there
    XSSFWorkbook wb2 = new XSSFWorkbook(Package.open(bais));
    assertEquals(3, wb2.getNumberOfSheets());
    assertNotNull(wb2.getSheetAt(0));
    assertNotNull(wb2.getSheetAt(1));
    assertNotNull(wb2.getSheetAt(2));
   
    sheet = (XSSFSheet)wb2.getSheetAt(0);

   
    // Check hyperlinks again
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);
   
   
    // Add one more, and re-check
    Row r17 = sheet.createRow(17);
    Cell r17c = r17.createCell(2);
   
    Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
    hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
    hyperlink.setLabel("POI SS Link");
    r17c.setHyperlink(hyperlink);
   
    assertEquals(5, sheet.getNumHyperlinks());
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

        new HSSFWorkbook(), new XSSFWorkbook()
    };
   
    for (int i = 0; i < wbs.length; i++) {
      Workbook wb = wbs[i];
        CreationHelper createHelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet("new sheet");

        // Create a row and put some cells in it. Rows are 0 based.
        Row row = sheet.createRow((short)0);
        // Create a cell and put a value in it.
        Cell cell = row.createCell((short)0);
        cell.setCellValue(1);

        // Or do it on one line.
        row.createCell((short)1).setCellValue(1.2);
        row.createCell((short)2).setCellValue(
            createHelper.createRichTextString("This is a string"));
        row.createCell((short)3).setCellValue(true);

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

  }
 
  public static void newDateCells() throws IOException {
      Workbook wb = new HSSFWorkbook();
      //Workbook wb = new XSSFWorkbook();
      CreationHelper createHelper = wb.getCreationHelper();
      Sheet sheet = wb.createSheet("new sheet");

      // Create a row and put some cells in it. Rows are 0 based.
      Row row = sheet.createRow((short)0);
   
      // Create a cell and put a date value in it.  The first cell is not styled
      // as a date.
      Cell cell = row.createCell((short)0);
      cell.setCellValue(new Date());

      // we style the second cell as a date (and time).  It is important to
      // create a new cell style from the workbook otherwise you can end up
      // modifying the built in style and effecting not only this cell but other cells.
      CellStyle cellStyle = wb.createCellStyle();
      cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
      cell = row.createCell((short)1);
      cell.setCellValue(new Date());
      cell.setCellStyle(cellStyle);

      // Write the output to a file
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

     * Tests that cell formatting stuff works as expected
     */
    public void testCellFormatting() throws Exception {
      Workbook workbook = new XSSFWorkbook();
      Sheet sheet = workbook.createSheet();
      CreationHelper creationHelper = workbook.getCreationHelper();
     
      CellStyle cs = workbook.createCellStyle();
      assertNotNull(cs);
     
      assertNotNull(creationHelper);
      assertNotNull(creationHelper.createDataFormat());
     
      cs.setDataFormat(
          creationHelper.createDataFormat().getFormat("yyyy/mm/dd")
      );
      Cell cell = sheet.createRow(0).createCell((short)0);
      cell.setCellValue(new Date(654321));
     
      assertNull(cell.getCellStyle());
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

        final CellMarshaller cellMarshaller = new CellMarshaller(bookmarkService, dateCellStyle);
        return cellMarshaller;
    }
   
    protected CellStyle createDateFormatCellStyle(final Workbook wb) {
        final CreationHelper createHelper = wb.getCreationHelper();
        final SimpleDateFormat dateInstance = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM);
        final String pattern = dateInstance.toPattern();
        short dateFormat = createHelper.createDataFormat().getFormat(pattern);
        final CellStyle dateCellStyle = wb.createCellStyle();
        dateCellStyle.setDataFormat(dateFormat);
        return dateCellStyle;
    }
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

    private static void setCellComment(final Cell cell, final String commentText) {
        Sheet sheet = cell.getSheet();
        Row row = cell.getRow();
        Workbook workbook = sheet.getWorkbook();
        CreationHelper creationHelper = workbook.getCreationHelper();
        ClientAnchor anchor = creationHelper.createClientAnchor();
        anchor.setCol1(cell.getColumnIndex());
        anchor.setCol2(cell.getColumnIndex()+1);
        anchor.setRow1(row.getRowNum());
        anchor.setRow2(row.getRowNum()+3);
       
        Drawing drawing = sheet.createDrawingPatriarch();
        Comment comment1 = drawing.createCellComment(anchor);
       
        RichTextString commentRtf = creationHelper.createRichTextString(commentText);
       
        comment1.setString(commentRtf);
        Comment comment = comment1;
        cell.setCellComment(comment);
    }
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

        }
    }

    public void testLoadSave() {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
    CreationHelper createHelper = workbook.getCreationHelper();
    assertEquals(3, workbook.getNumberOfSheets());
    XSSFSheet sheet = workbook.getSheetAt(0);

    // Check hyperlinks
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);


    // Write out, and check

    // Load up again, check all links still there
    XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
    assertEquals(3, wb2.getNumberOfSheets());
    assertNotNull(wb2.getSheetAt(0));
    assertNotNull(wb2.getSheetAt(1));
    assertNotNull(wb2.getSheetAt(2));

    sheet = wb2.getSheetAt(0);


    // Check hyperlinks again
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);


    // Add one more, and re-check
    Row r17 = sheet.createRow(17);
    Cell r17c = r17.createCell(2);

    Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
    hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
    hyperlink.setLabel("POI SS Link");
    r17c.setHyperlink(hyperlink);

    assertEquals(5, sheet.getNumHyperlinks());
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

      
       // Sheet 1 doesn't (yet)
       assertNull(sh1.getCommentsTable(false));
      
       // Try to add comments to Sheet 1
       CreationHelper factory = wb.getCreationHelper();
       Drawing drawing = sh1.createDrawingPatriarch();

       ClientAnchor anchor = factory.createClientAnchor();
       anchor.setCol1(0);
       anchor.setCol2(4);
       anchor.setRow1(0);
       anchor.setRow2(1);

       Comment comment1 = drawing.createCellComment(anchor);
       comment1.setString(
             factory.createRichTextString("I like this cell. It's my favourite."));
       comment1.setAuthor("Bob T. Fish");
      
       Comment comment2 = drawing.createCellComment(anchor);
       comment2.setString(
             factory.createRichTextString("This is much less fun..."));
       comment2.setAuthor("Bob T. Fish");

       Cell c1 = sh1.getRow(0).createCell(4);
       c1.setCellValue(2.3);
       c1.setCellComment(comment1);
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

          row.removeCell(cell);
      }
      cell = row.createCell(columnNumber);
      if(style != null) cell.setCellStyle(style);
     
        CreationHelper createHelper = workbook.getCreationHelper();
        boolean isFormula=style != null && style.getDataFormatString().equals("@");
       
       
        if(!isFormula && Decision.isNumeric(value)) {
      cell.setCellType(Cell.CELL_TYPE_NUMERIC);
      double dbl = Caster.toDoubleValue(value);
            cell.setCellValue(dbl);
            _expandColumnWidth(sheet,Caster.toString(dbl),columnNumber);
    }
        else if(StringUtil.isEmpty("")) {
            cell.setCellType(Cell.CELL_TYPE_BLANK);
            cell.setCellValue(createHelper.createRichTextString(""));
        }
        else {
            cell.setCellType(Cell.CELL_TYPE_STRING);
            cell.setCellValue(createHelper.createRichTextString(value));
            _expandColumnWidth(sheet,value,columnNumber);
        }
         
         
  }
View Full Code Here

Examples of org.apache.poi.ss.usermodel.CreationHelper

    doTestHyperlinkContents(sheet);
  }

  public void testLoadSave() {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
    CreationHelper createHelper = workbook.getCreationHelper();
    assertEquals(3, workbook.getNumberOfSheets());
    XSSFSheet sheet = workbook.getSheetAt(0);

    // Check hyperlinks
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);


    // Write out, and check

    // Load up again, check all links still there
    XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
    assertEquals(3, wb2.getNumberOfSheets());
    assertNotNull(wb2.getSheetAt(0));
    assertNotNull(wb2.getSheetAt(1));
    assertNotNull(wb2.getSheetAt(2));

    sheet = wb2.getSheetAt(0);


    // Check hyperlinks again
    assertEquals(4, sheet.getNumHyperlinks());
    doTestHyperlinkContents(sheet);


    // Add one more, and re-check
    Row r17 = sheet.createRow(17);
    Cell r17c = r17.createCell(2);

    Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_URL);
    hyperlink.setAddress("http://poi.apache.org/spreadsheet/");
    hyperlink.setLabel("POI SS Link");
    r17c.setHyperlink(hyperlink);

    assertEquals(5, sheet.getNumHyperlinks());
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.