Package org.apache.poi.hssf.usermodel

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


     * Obtain the style used to render a header or footer.
     * @return The style used to render a header or footer.
     */
    private HSSFCellStyle getHeaderFooterStyle()
    {
        HSSFCellStyle style = this.wb.createCellStyle();
        // style.setFillPattern(HSSFCellStyle.FINE_DOTS);
        // style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
        HSSFFont bold = this.wb.createFont();
        bold.setBoldweight(Font.BOLDWEIGHT_BOLD);
        // bold.setColor(HSSFColor.WHITE.index);
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());

        style.setFont(bold);
        return style;
    }
View Full Code Here


        // a copy of the default
        colors = wb.getCustomPalette();
    }

    public void colorStyles(CellStyle style, Formatter out) {
        HSSFCellStyle cs = (HSSFCellStyle) style;
        out.format("  /* fill pattern = %d */%n", cs.getFillPattern());
        styleColor(out, "background-color", cs.getFillForegroundColor());
        styleColor(out, "color", cs.getFont(wb).getColor());
        styleColor(out, "border-left-color", cs.getLeftBorderColor());
        styleColor(out, "border-right-color", cs.getRightBorderColor());
        styleColor(out, "border-top-color", cs.getTopBorderColor());
        styleColor(out, "border-bottom-color", cs.getBottomBorderColor());
    }
View Full Code Here

        // a copy of the default
        colors = wb.getCustomPalette();
    }

    public void colorStyles(CellStyle style, Formatter out) {
        HSSFCellStyle cs = (HSSFCellStyle) style;
        out.format("  /* fill pattern = %d */%n", cs.getFillPattern());
        styleColor(out, "background-color", cs.getFillForegroundColor());
        styleColor(out, "color", cs.getFont(wb).getColor());
        styleColor(out, "border-left-color", cs.getLeftBorderColor());
        styleColor(out, "border-right-color", cs.getRightBorderColor());
        styleColor(out, "border-top-color", cs.getTopBorderColor());
        styleColor(out, "border-bottom-color", cs.getBottomBorderColor());
    }
View Full Code Here

                    String strValue = null;
                    if(cell instanceof HSSFCell){
                      HSSFCell hssfCell = (HSSFCell)cell;
                      if(HSSFDateUtil.isCellDateFormatted(hssfCell)){
//                        Date date = HSSFDateUtil.getJavaDate(dv);
                        HSSFCellStyle cellStyle = hssfCell.getCellStyle();
                        if(cellStyle!=null && cellStyle.getDataFormatString()!=null){
                           String dateFmt = cell.getCellStyle().getDataFormatString();
                              /* strValue = new SimpleDateFormat(dateFmt).format(date); - won't work as
                              Java fmt differs from Excel fmt. If Excel date format is mm/dd/yyyy, Java
                              will always be 00 for date since "m" is minutes of the hour.*/
                           strValue = new CellDateFormatter(dateFmt).format(hssfCell.getDateCellValue());
                        }else{
                            strValue = WebVariable.sdf.format(hssfCell.getDateCellValue());
                        }
//                        td.text(strValue);
                      }else{
                        HSSFCellStyle cellStyle = hssfCell.getCellStyle();
                        if(cellStyle!=null && cellStyle.getDataFormatString()!=null){
//                          String dataFmt = cellStyle.getDataFormatString();
                          strValue = new HSSFDataFormatter().formatRawCellContents(hssfCell.getNumericCellValue(), cellStyle.getDataFormat(), cellStyle.getDataFormatString());
                        }else{
                          strValue = String.valueOf(hssfCell.getNumericCellValue());
                        }
                      }
                    }else{
                      XSSFCell xssfCell = (XSSFCell)cell;
                      if(HSSFDateUtil.isCellDateFormatted(cell)){
                          String dateFmt = cell.getCellStyle().getDataFormatString();
                          /* strValue = new SimpleDateFormat(dateFmt).format(date); - won't work as
                          Java fmt differs from Excel fmt. If Excel date format is mm/dd/yyyy, Java
                          will always be 00 for date since "m" is minutes of the hour.*/
                          strValue = new CellDateFormatter(dateFmt).format(cell.getDateCellValue());
//                        td.text(strValue);
                      }else{
                        XSSFCellStyle cellStyle = xssfCell.getCellStyle();
                        if(cellStyle!=null && cellStyle.getDataFormatString()!=null){
//                           String dateFmt = cell.getCellStyle().getDataFormatString();
                              /* strValue = new SimpleDateFormat(dateFmt).format(date); - won't work as
                              Java fmt differs from Excel fmt. If Excel date format is mm/dd/yyyy, Java
                              will always be 00 for date since "m" is minutes of the hour.*/
                           strValue = new HSSFDataFormatter().formatRawCellContents(cell.getNumericCellValue(), cellStyle.getDataFormat(), cellStyle.getDataFormatString());
                        }else{
                            strValue = String.valueOf(xssfCell.getNumericCellValue());
                        }
//                        xssfCell.getCellStyle().getDataFormatString();
//                        td.text(String.valueOf(cell.getNumericCellValue()));
                      }
                    }
                    td.text(strValue);
                  }else if(cell.getCellType()==Cell.CELL_TYPE_STRING){
                    td.text(cell.getStringCellValue());
                  }
                  if(sheet instanceof HSSFSheet){
                    HSSFSheet hssfSheet = (HSSFSheet)sheet;
                    HSSFCell hssfCell = (HSSFCell)cell;
                    HSSFCellStyle style = hssfCell.getCellStyle();
//                    判断一下如果式样中有斜杠,那么写一个斜杠
                   
                    HSSFPalette palette = hssfSheet.getWorkbook().getCustomPalette();
                    styleApplier4XLS(td,style,hssfSheet.getWorkbook(),palette);
                  }else{
View Full Code Here

                  cell.setCellValue(value);
                }
              }
            }
            String styleKey = WorkbookStyleContainer.makeCellStyleHash(td);
            HSSFCellStyle style = styleContainer.cellStyleMap.get(styleKey);
            if(style!=null){
              cell.setCellStyle(style);
            }else{
                style = sheet.getWorkbook()
                    .createCellStyle();
View Full Code Here

     
      OutputStream out = new FileOutputStream(sourcePath);
     
      HSSFWorkbook workbook = new HSSFWorkbook();
     
      HSSFCellStyle style = workbook.createCellStyle();
      // 设置这些样式
      style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
      style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
      style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
      // 生成一个字体
      HSSFFont font = workbook.createFont();
      font.setFontHeightInPoints((short) 12);
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      // 把字体应用到当前的样式
      style.setFont(font);
     
      HSSFCellStyle styledata = workbook.createCellStyle();
      // 设置这些样式
      styledata.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderRight(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderTop(HSSFCellStyle.BORDER_THIN);
//      styledata.setAlignment(HSSFCellStyle.ALIGN_CENTER);
     
      for(int t = 1 ; t <= total ; t ++)
      {
        HSSFSheet sheet = workbook.createSheet("第"+t+"页");
View Full Code Here

      OutputStream out = new FileOutputStream(new File(sourcePath));

      HSSFWorkbook workbook = new HSSFWorkbook();

      HSSFCellStyle style = workbook.createCellStyle();
      // 设置这些样式
      style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
      style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
      style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
      // 生成一个字体
      HSSFFont font = workbook.createFont();
      font.setFontHeightInPoints((short) 12);
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      // 把字体应用到当前的样式
      style.setFont(font);

      HSSFCellStyle styledata = workbook.createCellStyle();
      // 设置这些样式
      styledata.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderRight(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderTop(HSSFCellStyle.BORDER_THIN);
      // styledata.setAlignment(HSSFCellStyle.ALIGN_CENTER);

      HSSFSheet sheet = workbook.createSheet( year + "年"+month+"月");
      sheet.setDefaultColumnWidth(15);
      sheet.createFreezePane(1, 1);
View Full Code Here

     
      OutputStream out = new FileOutputStream(sourcePath);
     
      HSSFWorkbook workbook = new HSSFWorkbook();
     
      HSSFCellStyle style = workbook.createCellStyle();
      // 设置这些样式
      style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
      style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
      style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      style.setBorderRight(HSSFCellStyle.BORDER_THIN);
      style.setBorderTop(HSSFCellStyle.BORDER_THIN);
      style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
      // 生成一个字体
      HSSFFont font = workbook.createFont();
      font.setFontHeightInPoints((short) 12);
      font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      // 把字体应用到当前的样式
      style.setFont(font);
     
      HSSFCellStyle styledata = workbook.createCellStyle();
      // 设置这些样式
      styledata.setBorderBottom(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderLeft(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderRight(HSSFCellStyle.BORDER_THIN);
      styledata.setBorderTop(HSSFCellStyle.BORDER_THIN);
//      styledata.setAlignment(HSSFCellStyle.ALIGN_CENTER);
     
      for(int t = 1 ; t <= total ; t ++)
      {
        HSSFSheet sheet = workbook.createSheet("第"+t+"页");
View Full Code Here

   *@exception  NestableException  Thrown if an error happens.
   */
  private static void setCellStyleProperty( HSSFCell cell, HSSFWorkbook workbook, String propertyName, Object propertyValue )
    throws NestableException {
    try {
      HSSFCellStyle style = cell.getCellStyle();
      HSSFCellStyle style2 = null;
      Map values = PropertyUtils.describe( style );
      values.put( propertyName, propertyValue );
      values.remove( "index" );
      // index seems like what  index the cellstyle is in the list of styles for a workbook.
      // not good to compare on!

      short numberCellStyles = workbook.getNumCellStyles();

      for ( short i = 0; i < numberCellStyles; i++ ) {
        HSSFCellStyle wbStyle = workbook.getCellStyleAt( i );
        Map wbStyleMap = PropertyUtils.describe( wbStyle );
        wbStyleMap.remove( "index" );

        if ( wbStyleMap.equals( values ) ) {
          style2 = wbStyle;
View Full Code Here

      }
    }
    final List<String> attributeIds = new ArrayList<String>(attributeIdSet);

    HSSFWorkbook wb = new HSSFWorkbook();
    final HSSFCellStyle localeCellStyle = wb.createCellStyle();
    localeCellStyle.setLocked(false);
    final HSSFSheet sheet = wb.createSheet("translation");
    createHeaderRow(sheet.createRow(0), locales, attributeIds);

    Exporter.export(ls, locales, new Callback<LocaleItem>() {
      int i = 0;
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.