Package org.apache.poi.ss.usermodel

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


        this.fill = fill;
    }

    @Override
    public void applyTo(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
        CellStyle style = newStyleBasedOn(cell).create(workbook);
        applyBorderTo(style);
        applyFillTo(style);
        applyAlignmentTo(style);
        applyDataFormatTo(style, workbook);
        applyFontTo(style, workbook);
View Full Code Here


        static Cell createCell(int row, int column, Date date) {
        Workbook workbook = new HSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        Cell cell = sheet.createRow(row).createCell(column, CELL_TYPE_NUMERIC);
        cell.setCellValue(date);
        CellStyle style = workbook.createCellStyle();
        style.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm"));
        cell.setCellStyle(style);
        return cell;
    }
View Full Code Here

        return new ClonedStyleFactory(source);
    }

    @Override
    public CellStyle create(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        style.cloneStyleFrom(source.getCellStyle());
        return style;
    }
View Full Code Here

    public void testLoadStyles() throws Exception {
        XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath());
        Sheet sheet = workbook.getSheetAt(0);
        Row row = sheet.getRow(0);
        Cell cell = row.getCell((short) 0);
        CellStyle style = cell.getCellStyle();
        // assertNotNull(style);
    }
View Full Code Here

      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

    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));
     
View Full Code Here

    }

    // //////////////////////////////////////

    protected CellMarshaller newCellMarshaller(final Workbook wb) {
        final CellStyle dateCellStyle = createDateFormatCellStyle(wb);
        final CellMarshaller cellMarshaller = new CellMarshaller(bookmarkService, dateCellStyle);
        return cellMarshaller;
    }
View Full Code Here

    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

        //create data format
        DataFormat df = workbook.createDataFormat();
        short sdf = df.getFormat(formatter.format());
       
        //set format
        CellStyle style = cell.getCellStyle();
        if (style == null) {
          style = workbook.createCellStyle();
        }
        style.setDataFormat(sdf);
       
      }
     
      if (result instanceof Date) {
       
View Full Code Here

     
            // Grab a copy of the old/new cell
            Cell newCell = newRow.createCell(oldCell.getColumnIndex());

            // Copy style from old cell and apply to new cell
            CellStyle newCellStyle = workbook.createCellStyle();
            newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
            newCell.setCellStyle(newCellStyle);

            // If there is a cell comment, copy
            if (oldCell.getCellComment() != null) {
                newCell.setCellComment(oldCell.getCellComment());
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.CellStyle

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.