Package org.apache.poi.hssf.usermodel

Examples of org.apache.poi.hssf.usermodel.HSSFCellStyle


    }

    protected boolean processCell( HSSFCell cell, Element tableCellElement,
            int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt )
    {
        final HSSFCellStyle cellStyle = cell.getCellStyle();

        String value;
        switch ( cell.getCellType() )
        {
        case HSSFCell.CELL_TYPE_STRING:
            // XXX: enrich
            value = cell.getRichStringCellValue().getString();
            break;
        case HSSFCell.CELL_TYPE_FORMULA:
            switch ( cell.getCachedFormulaResultType() )
            {
            case HSSFCell.CELL_TYPE_STRING:
                HSSFRichTextString str = cell.getRichStringCellValue();
                if ( str != null && str.length() > 0 )
                {
                    value = ( str.toString() );
                }
                else
                {
                    value = ExcelToHtmlUtils.EMPTY;
                }
                break;
            case HSSFCell.CELL_TYPE_NUMERIC:
                HSSFCellStyle style = cellStyle;
                if ( style == null )
                {
                    value = String.valueOf( cell.getNumericCellValue() );
                }
                else
                {
                    value = ( _formatter.formatRawCellContents(
                            cell.getNumericCellValue(), style.getDataFormat(),
                            style.getDataFormatString() ) );
                }
                break;
            case HSSFCell.CELL_TYPE_BOOLEAN:
                value = String.valueOf( cell.getBooleanCellValue() );
                break;
View Full Code Here


      FileInputStream fileIS = new FileInputStream(new File(fileName));

      HSSFWorkbook workbook = new HSSFWorkbook(fileIS);
      HSSFSheet sheet = workbook.getSheetAt(0);
      HSSFCell resultCell = null;
      HSSFCellStyle passedStyle = workbook.createCellStyle();
      passedStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
      passedStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      HSSFCellStyle failedStyle = workbook.createCellStyle();
      failedStyle.setFillForegroundColor(HSSFColor.RED.index);
      failedStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      HSSFCellStyle notExecStyle = workbook.createCellStyle();
      notExecStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
      notExecStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      Iterator rowIter = sheet.rowIterator();
      while (rowIter.hasNext()) {
        HSSFRow myRow = (HSSFRow) rowIter.next();
        if (resultMap.get(myRow.getCell(0).toString()) != null
            && resultMap.get(myRow.getCell(0).toString()).get(
View Full Code Here

            rowCount = rowList.size();
           
           
            HSSFFont boldFont = wb.createFont();
            boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            HSSFCellStyle boldStyle = wb.createCellStyle();
            boldStyle.setFont(boldFont);
            boldStyle.setWrapText(true);
           
            //Loop through excel 'Rows'
            for ( int i = 0; i < rowList.size(); i++ ) {
                HSSFRow row;
                String htmlRow = rowList.elementAt(i).toHtml().trim();
View Full Code Here

    return aSB.toString();
  }

  public HSSFCell toXLS(HSSFCell theCell, HSSFWorkbook theWorkbook) {
    // TODO, recycle styles via cache? research how much extra time and space is used in both cases
    HSSFCellStyle aStyle = theWorkbook.createCellStyle();

    // align
    if (itsAlign == ALIGN_LEFT || itsAlign == ALIGN_NONE) {
      aStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    } else if (itsAlign == ALIGN_CENTER) {
      aStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    } else if (itsAlign == ALIGN_RIGHT) {
      aStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    } else {
      //TODO warning?
    }
    if (isHeader) {
      aStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    }
    //TODO bold, italics, underline
    if (itsForegroundColor != null) {
      aStyle
          .setFillForegroundColor(getHSSFColorIndex(itsForegroundColor));
    }
    if (itsBackgroundColor != null) {
      aStyle
          .setFillBackgroundColor(getHSSFColorIndex(itsBackgroundColor));
    }
    theCell.setCellStyle(aStyle);
    theCell.setCellValue(itsValue);
View Full Code Here

        EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
        if ((pstyle != null) && pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle(); //oops
                                                                       // a
                                                                       // little
                                                                       // confusing
            //below is the style attribute
            //this is an HSSFCellStyle
            //associated with EPStyle
            style.setBorderLeft((short)getStyle());

            ColorCode colorCode = getColor();
            if (colorCode != null) {
                color = (HSSFColor)colorhash.get(colorCode.toString());
            }
            if (color == null)
                color = new HSSFColor.BLACK();

            style.setLeftBorderColor(color.getIndex());
        }

    }
View Full Code Here

        EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
        if (pstyle != null && pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle(); //oops
                                                                       // a
                                                                       // little
                                                                       // confusing
            //below is the style attribute
            //this is an HSSFCellStyle
            //associated with EPStyle
            style.setBorderRight((short)getStyle());

            ColorCode colorCode = getColor();
            if (colorCode != null) {
                color = (HSSFColor)colorhash.get(colorCode.toString());
            }
            if (color == null) {
                color = new HSSFColor.BLACK();
            }
            style.setRightBorderColor(color.getIndex());
        }

    }
View Full Code Here

     * create a cell style in the underlying HSSF model and return the
     * reference this should match reasonably close to what is in the
     * StyleRegion element in the gnumeric ss.
     */
    HSSFCellStyle createStyle() {
        HSSFCellStyle style = _workbook.createCellStyle();
        return style;
    }
View Full Code Here

        EPStyle pstyle = (EPStyle)parent;
        if (pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle();
            //style.setFillForegroundColor(
            Workbook workbook = getWorkbook();
            HSSFFont font = workbook.createFont();
            style.setFont(font);
            font.setFontHeightInPoints((short)getUnit());
            //font.setFontName(getFont());
            font.setItalic(getItalic());
            if (getBold()) {
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
View Full Code Here

        EPStyle pstyle = (EPStyle)getAncestor(EPStyle.class);
        if (pstyle != null && pstyle.isValid()) {
            Hashtable colorhash = pstyle.getColorHash();
            HSSFColor color = null;

            HSSFCellStyle style = pstyle.getStyle(); //oops
                                                                       // a
                                                                       // little
                                                                       // confusing
            //below is the style attribute
            //this is an HSSFCellStyle
            //associated with EPStyle
            style.setBorderTop((short)getStyle());

            ColorCode colorCode = getColor();
            if (colorCode != null) {
                color = (HSSFColor)colorhash.get(colorCode.toString());
            }
            if (color == null)
                color = new HSSFColor.BLACK();

            style.setTopBorderColor(color.getIndex());
        }

    }
View Full Code Here

        EPStyleRegion sregion = (EPStyleRegion)parent;

        if (sregion.isValid()) {
            Hashtable colorhash = sregion.getColorHash();

            HSSFCellStyle style = sregion.getStyle();
            short cnvhalign =
                convertAlignment(getHorizontalAlignment().getCode());
            style.setAlignment(cnvhalign);
            short cnvvalign =
                convertVAlignment(getVerticalAlignment().getCode());
            style.setVerticalAlignment(cnvvalign);
            style.setFillPattern((short)getShade());

            Workbook workbook = getWorkbook();
            HSSFDataFormat dataformat = workbook.createDataFormat();
            if (getShade() == 1) {
                // TODO: change to constant when upgrade to new HSSF
                // solid w/foreground, bg doesn't matter
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("shade = 1");
                }
                HSSFColor color =
                    (HSSFColor)colorhash.get(getBackgroundColor().toString());
                if (color == null) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("s1 BG couldn't find color for "
                                + getBackgroundColor().toString());
                    }
                    color = new HSSFColor.WHITE();
                }
                style.setFillForegroundColor(color.getIndex());
                color = (HSSFColor)colorhash.get(getPatternColor().toString());
                if (color == null) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("s1 PC couldn't find color for "
                                + getPatternColor().toString());
                    }
                    color = new HSSFColor.BLACK();
                }
                style.setFillBackgroundColor(color.getIndex());
            } else {
                HSSFColor color =
                    (HSSFColor)colorhash.get(getBackgroundColor().toString());
                if (color == null) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(
                            "BG couldn't find color for "
                                + getBackgroundColor().toString());
                    }
                    color = new HSSFColor.BLACK();
                }
                style.setFillBackgroundColor(color.getIndex());
                color = (HSSFColor)colorhash.get(getPatternColor().toString());
                if (color == null) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("PC couldn't find color for "
                                + getPatternColor().toString());
                    }
                    color = new HSSFColor.WHITE();
                }
                style.setFillForegroundColor(color.getIndex());
            }
            style.setWrapText(getWrapText());
            style.setLocked(true);

            String format = null;
            try {
                format = getFormat();
            } catch (NullPointerException e) {
                format = _general_format;
            }

            if (!format.equals(_general_format)) {
                short valuenumber;
                format = kludgeForGnumericMisformats(format);
                format = kludgeForGnumericDateDivergence(format);
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("setting format to " + format);
                }
                Object o =
                    workbook.getValidate(format, dataformat.getFormat(format));
                Short sh = null;
                sh = (Short)o;
                valuenumber = sh.shortValue();
                style.setDataFormat(valuenumber);
            }
        } else {
            invalid = true;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFCellStyle

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.