Package org.apache.poi.ss.usermodel

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


  public void setHeader(HSSFSheet sheet, JSONObject header,
      CreationHelper createHelper, HSSFWorkbook wb, HSSFPatriarch patriarch) throws JSONException, IOException {
    String title = header.getString(TITLE);
    String imgName = header.getString(IMG);
    String imagePosition = header.getString(POSITION);
    CellStyle cellStyle = buildHeaderTitleCellStyle(sheet);
   
    if(title!=null && !title.equals("")){     
      Row row = sheet.getRow(1);
      Cell cell = row.createCell(6);
      cell.setCellValue(createHelper.createRichTextString(title));
View Full Code Here


  public void setFooter(HSSFSheet sheet, JSONObject footer,
      CreationHelper createHelper, HSSFWorkbook wb, int rowStart, HSSFPatriarch patriarch) throws JSONException, IOException {
    String title = footer.getString(TITLE);
    String imgName = footer.getString(IMG);
    String imagePosition = footer.getString(POSITION);
    CellStyle cellStyle = buildHeaderTitleCellStyle(sheet);
   
    if(title!=null && !title.equals("")){   
      Row row = sheet.getRow(rowStart + 4);
      Cell cell = row.createCell(6);
      cell.setCellValue(createHelper.createRichTextString(title));
View Full Code Here

    }
    return impgType;
  }
 
  public CellStyle buildHeaderTitleCellStyle(Sheet sheet){
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
        cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
        cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER)
        Font font = sheet.getWorkbook().createFont();
        font.setFontHeightInPoints((short)16);
        font.setFontName("Arial");
        font.setColor(IndexedColors.DARK_BLUE.getIndex());
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        return cellStyle;
  }
View Full Code Here

        }
  }
 
  public CellStyle[] fillSheetHeader(Sheet sheet,Workbook wb, CreationHelper createHelper, int beginRowHeaderData, int beginColumnHeaderData) { 
    CrosstabXLSExporter xlsExp = new CrosstabXLSExporter();
    CellStyle hCellStyle = xlsExp.buildHeaderCellStyle(sheet);
    IDataStoreMetaData d = dataStore.getMetaData()
      int colnum = d.getFieldCount();
      Row row = sheet.getRow(beginRowHeaderData);
      CellStyle[] cellTypes = new CellStyle[colnum]; // array for numbers patterns storage
      for(int j = 0; j < colnum; j++){
        Cell cell = row.createCell(j + beginColumnHeaderData);
          cell.setCellType(HSSFCell.CELL_TYPE_STRING);
          String fieldName = d.getFieldName(j);
          IFieldMetaData fieldMetaData = d.getFieldMeta(j);
          String format = (String) fieldMetaData.getProperty("format");
          String alias = (String) fieldMetaData.getAlias();
          Boolean visible = (Boolean) fieldMetaData.getProperty("visible");
            if (extractedFields != null && extractedFields.get(j) != null) {
            Field field = (Field) extractedFields.get(j);
            fieldName = field.getAlias();
            if (field.getPattern() != null) {
              format = field.getPattern();
            }
          }
            CellStyle aCellStyle = wb.createCellStyle();
            if (format != null) {
          short formatInt = HSSFDataFormat.getBuiltinFormat(format);       
          aCellStyle.setDataFormat(formatInt);
          cellTypes[j] = aCellStyle;
            }
            if (visible != null && visible.booleanValue() == true) {
              if(alias!=null && !alias.equals("")){
                cell.setCellValue(createHelper.createRichTextString(alias));
View Full Code Here

      return cellTypes;
  }
 
  public void fillSheetData(Sheet sheet,Workbook wb, CreationHelper createHelper,CellStyle[] cellTypes, int beginRowData, int beginColumnData) { 
    CrosstabXLSExporter xlsExp = new CrosstabXLSExporter();
    CellStyle dCellStyle = xlsExp.buildDataCellStyle(sheet);
 
    Iterator it = dataStore.iterator();
      int rownum = beginRowData;
      short formatIndexInt = HSSFDataFormat.getBuiltinFormat("#,##0");
      CellStyle cellStyleInt = wb.createCellStyle(); // cellStyleInt is the default cell style for integers
      cellStyleInt.cloneStyleFrom(dCellStyle);
      cellStyleInt.setDataFormat(formatIndexInt);
     
      short formatIndexDoub = HSSFDataFormat.getBuiltinFormat("#,##0.00");
      CellStyle cellStyleDoub = wb.createCellStyle(); // cellStyleDoub is the default cell style for doubles
      cellStyleDoub.cloneStyleFrom(dCellStyle);
      cellStyleDoub.setDataFormat(formatIndexDoub);
     
    CellStyle cellStyleDate = wb.createCellStyle(); // cellStyleDate is the default cell style for dates
    cellStyleDate.cloneStyleFrom(dCellStyle);
    cellStyleDate.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy"));
   
    IDataStoreMetaData d = dataStore.getMetaData()
   
    while(it.hasNext()){
      Row rowVal = sheet.getRow(rownum);
View Full Code Here

     */
    protected void processarXLS(Object document, String sheetName) {
        HSSFWorkbook wb = (HSSFWorkbook) document;
        wb.setSheetName(0, sheetName);
        HSSFSheet sheet = wb.getSheetAt(0);
        CellStyle style = wb.createCellStyle();
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
        for (Cell cell : sheet.getRow(0))
            cell.setCellStyle(style);

        int lastCol = sheet.rowIterator().next().getLastCellNum() - 1;

View Full Code Here

       // Check all the colours
       for(int sn=0; sn<wb.getNumberOfSheets(); sn++) {
          Sheet s = wb.getSheetAt(sn);
          for(Row r : s) {
             for(Cell c : r) {
                CellStyle cs = c.getCellStyle();
                if(cs != null) {
                   cs.getFillForegroundColor();
                }
             }
          }
       }
      
View Full Code Here

       richTextString.applyFont(font3);
       richTextString.applyFont(0, 3, font1);
       cell.setCellValue(richTextString);

       // To enable newlines you need set a cell styles with wrap=true
       CellStyle cs = wb.createCellStyle();
       cs.setWrapText(true);
       cell.setCellStyle(cs);

       // Check the text has the
       assertEquals(text, cell.getStringCellValue());
      
View Full Code Here

     */
    public void test51037() throws Exception {
       XSSFWorkbook wb = new XSSFWorkbook();
       XSSFSheet s = wb.createSheet();
      
       CellStyle defaultStyle = wb.getCellStyleAt((short)0);
       assertEquals(0, defaultStyle.getIndex());
      
       CellStyle blueStyle = wb.createCellStyle();
       blueStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
       blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
       assertEquals(1, blueStyle.getIndex());

       CellStyle pinkStyle = wb.createCellStyle();
       pinkStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
       pinkStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
       assertEquals(2, pinkStyle.getIndex());

       // Starts empty
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       CTCols cols = s.getCTWorksheet().getColsArray(0);
       assertEquals(0, cols.sizeOfColArray());
      
       // Add some rows and columns
       XSSFRow r1 = s.createRow(0);
       XSSFRow r2 = s.createRow(1);
       r1.createCell(0);
       r1.createCell(2);
       r2.createCell(0);
       r2.createCell(3);
      
       // Check no style is there
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       assertEquals(0, cols.sizeOfColArray());
      
       assertEquals(defaultStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(defaultStyle, s.getColumnStyle(3));
      
      
       // Apply the styles
       s.setDefaultColumnStyle(0, pinkStyle);
       s.setDefaultColumnStyle(3, blueStyle);
      
       // Check
       assertEquals(pinkStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(blueStyle, s.getColumnStyle(3));
      
       assertEquals(1, s.getCTWorksheet().sizeOfColsArray());
       assertEquals(2, cols.sizeOfColArray());
      
       assertEquals(1, cols.getColArray(0).getMin());
       assertEquals(1, cols.getColArray(0).getMax());
       assertEquals(pinkStyle.getIndex(), cols.getColArray(0).getStyle());
      
       assertEquals(4, cols.getColArray(1).getMin());
       assertEquals(4, cols.getColArray(1).getMax());
       assertEquals(blueStyle.getIndex(), cols.getColArray(1).getStyle());
      
      
       // Save, re-load and re-check
       wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
       s = wb.getSheetAt(0);
       defaultStyle = wb.getCellStyleAt(defaultStyle.getIndex());
       blueStyle = wb.getCellStyleAt(blueStyle.getIndex());
       pinkStyle = wb.getCellStyleAt(pinkStyle.getIndex());
      
       assertEquals(pinkStyle, s.getColumnStyle(0));
       assertEquals(defaultStyle, s.getColumnStyle(2));
       assertEquals(blueStyle, s.getColumnStyle(3));
    }
View Full Code Here

    public void applyTo(Cell cell, Workbook workbook) {
        updateDataFormat(cell, workbook);
    }

    private void updateDataFormat(Cell cell, Workbook workbook) {
        CellStyle style = newStyleBasedOn(cell).create(workbook);
        style.setDataFormat(workbook.createDataFormat().getFormat(value()));
        cell.setCellStyle(style);
    }
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.