Package org.apache.poi.hssf.usermodel

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


        // Write a text at A1.
        HSSFCell cell = getCell(sheet, 0, 0);
        setText(cell, "Spring Excel View Via Strecks");

        // Write the current date at A2.
        HSSFCellStyle dateStyle = workbook.createCellStyle();
        dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
        cell = getCell(sheet, 1, 0);
        cell.setCellValue(new Date());
        cell.setCellStyle(dateStyle);
      }
    };
View Full Code Here


                         Iterator it2 = row2.cellIterator();
                         while(it1.hasNext() && it2.hasNext()) {
                             HSSFCell cell1 = (HSSFCell) it1.next();
                             HSSFCell cell2 = (HSSFCell) it2.next();
                             if(cell1 != null && cell2 != null) {
                               HSSFCellStyle cell1Style = cell1.getCellStyle();
                               HSSFCellStyle cell2Style = cell2.getCellStyle();
                               if(cell1Style != null && cell2Style != null) {
                                 short cell1BorderBottom = cell1Style.getBorderBottom();
                                 short cell1Alignment = cell1Style.getAlignment();
                                 short cell1BorderLeft = cell1Style.getBorderLeft();
                                 short cell1BorderRight = cell1Style.getBorderRight();
                                 short cell1BorderTop = cell1Style.getBorderTop();
                                 short cell1BorderColor = cell1Style.getBottomBorderColor();
                                 short cell1DataFormat = cell1Style.getDataFormat();
                                 short cell1BackgroundColor = cell1Style.getFillBackgroundColor();
                                 short cell1FillForegroundColor = cell1Style.getFillForegroundColor();
                                 short cell1FillPattern = cell1Style.getFillPattern();
                                 short cell1LeftBorderColor = cell1Style.getLeftBorderColor();
                                 short cell1RightBorderColor = cell1Style.getRightBorderColor();
                                 short cell1VerticalAlignment = cell1Style.getVerticalAlignment();
                                 boolean cell1WrapText = cell1Style.getWrapText();
                                 short cell1Rotation = cell1Style.getRotation();
                                
                                 short cell2BorderBottom = cell2Style.getBorderBottom();
                                 short cell2Alignment = cell2Style.getAlignment();
                                 short cell2BorderLeft = cell2Style.getBorderLeft();
                                 short cell2BorderRight = cell2Style.getBorderRight();
                                 short cell2BorderTop = cell2Style.getBorderTop();
                                 short cell2BorderColor = cell2Style.getBottomBorderColor();
                                 short cell2DataFormat = cell2Style.getDataFormat();
                                 short cell2BackgroundColor = cell2Style.getFillBackgroundColor();
                                 short cell2FillForegroundColor = cell2Style.getFillForegroundColor();
                                 short cell2FillPattern = cell2Style.getFillPattern();
                                 short cell2LeftBorderColor = cell2Style.getLeftBorderColor();
                                 short cell2RightBorderColor = cell2Style.getRightBorderColor();
                                 short cell2VerticalAlignment = cell2Style.getVerticalAlignment();
                                 boolean cell2WrapText = cell2Style.getWrapText();
                                 short cell2Rotation = cell2Style.getRotation();
                                 if(cell1BorderBottom != cell2BorderBottom) {
                                     equal = false;
                                     String dataToWrite = "Sheet # " + i + "Row # " + j + "Cell # " + cell1.getCellNum() + "has a different Bottom Border" + "\n";   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                                     outputStream.write(dataToWrite.getBytes());
                                 }
View Full Code Here

          String dataToWrite = "Sheet # " + sheetNumber + "Row # " + j + "Cell # " + cell1.getCellNum() + "has a different data.. File 1 Cell has " + cell1 + "Whereas File2 has " + cell2 + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
          outputStream.write(dataToWrite.getBytes());
          return false;
        }

        HSSFCellStyle cell1Style = cell1.getCellStyle();
        HSSFCellStyle cell2Style = cell2.getCellStyle();
        if (cell1Style == null || cell2Style == null)
        {
          String dataToWrite = "Sheet # " + sheetNumber + "Row # " + j + "Cell # " + cell1.getCellNum() + "has a no cell style.. File 1 Cell has " + cell1 + "Whereas File2 has " + cell2 + "\n";
          outputStream.write(dataToWrite.getBytes());
          return false;
        }
        else
        {
          short cell1BorderBottom = cell1Style.getBorderBottom();
          short cell1Alignment = cell1Style.getAlignment();
          short cell1BorderLeft = cell1Style.getBorderLeft();
          short cell1BorderRight = cell1Style.getBorderRight();
          short cell1BorderTop = cell1Style.getBorderTop();
          short cell1BorderColor = cell1Style.getBottomBorderColor();
          short cell1DataFormat = cell1Style.getDataFormat();
          short cell1BackgroundColor = cell1Style.getFillBackgroundColor();
          short cell1FillForegroundColor = cell1Style.getFillForegroundColor();
          short cell1FillPattern = cell1Style.getFillPattern();
          short cell1LeftBorderColor = cell1Style.getLeftBorderColor();
          short cell1RightBorderColor = cell1Style.getRightBorderColor();
          short cell1VerticalAlignment = cell1Style.getVerticalAlignment();
          boolean cell1WrapText = cell1Style.getWrapText();
          short cell1Rotation = cell1Style.getRotation();

          short cell2BorderBottom = cell2Style.getBorderBottom();
          short cell2Alignment = cell2Style.getAlignment();
          short cell2BorderLeft = cell2Style.getBorderLeft();
          short cell2BorderRight = cell2Style.getBorderRight();
          short cell2BorderTop = cell2Style.getBorderTop();
          short cell2BorderColor = cell2Style.getBottomBorderColor();
          short cell2DataFormat = cell2Style.getDataFormat();
          short cell2BackgroundColor = cell2Style.getFillBackgroundColor();
          short cell2FillForegroundColor = cell2Style.getFillForegroundColor();
          short cell2FillPattern = cell2Style.getFillPattern();
          short cell2LeftBorderColor = cell2Style.getLeftBorderColor();
          short cell2RightBorderColor = cell2Style.getRightBorderColor();
          short cell2VerticalAlignment = cell2Style.getVerticalAlignment();
          boolean cell2WrapText = cell2Style.getWrapText();
          short cell2Rotation = cell2Style.getRotation();
          if (cell1BorderBottom != cell2BorderBottom)
          {
            equal = false;
            String dataToWrite = "Sheet # " + sheetNumber + "Row # " + j + "Cell # " + cell1.getCellNum() + "has a different Bottom Border" + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
            outputStream.write(dataToWrite.getBytes());
View Full Code Here

    }
    title = data;
    index = 0;
    writeItem(data);
    HSSFRow titleRow = sheet.getRow(index);
    HSSFCellStyle titleStyle = getTitleStyle();
    for (int i = 0; i < titleRow.getLastCellNum(); i++) {
      titleRow.getCell(i).setCellStyle(titleStyle);
    }
    index++;
  }
View Full Code Here

  protected String getDateTimeFormat() {
    return "YYYY-MM-DD HH:MM:SS";
  }

  protected HSSFCellStyle getTitleStyle() {
    HSSFCellStyle style = workbook.createCellStyle();
    // HSSFFont f = workbook.createFont();
    // f.setFontHeightInPoints((short ) 10 ); //字号
    // f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗
    // style.setFont(f);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
    style.setFillPattern(HSSFCellStyle.FINE_DOTS);
    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillBackgroundColor(HSSFColor.LIGHT_BLUE.index);
    return style;
  }
View Full Code Here

    // 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.
    HSSFCellStyle cellStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    // cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
    cellStyle.setDataFormat(df.getFormat("YYYY-MM-DD HH:MM:SS"));
    cell = row.createCell(1);
    cell.setCellValue(new Date());
    cell.setCellStyle(cellStyle);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("src/test/resources/workbook.xls");
View Full Code Here

  }


  protected HSSFCellStyle initCreateCell(JRExporterGridCell gridCell, int colIndex, int rowIndex, StyleInfo baseStyle)
  {
    HSSFCellStyle cellStyle = getLoadedCellStyle(baseStyle);
    createMergeRegion(gridCell, colIndex, rowIndex, cellStyle);
    cell = row.createCell(colIndex);
    return cellStyle;
  }
View Full Code Here

  }


  protected HSSFCellStyle getLoadedCellStyle(StyleInfo style)
  {
    HSSFCellStyle cellStyle = (HSSFCellStyle) loadedCellStyles.get(style);
    if (cellStyle == null)
    {
      cellStyle = workbook.createCellStyle();

      cellStyle.setFillForegroundColor(style.backcolor);
      cellStyle.setFillPattern(style.mode);
      cellStyle.setAlignment(style.horizontalAlignment);
      cellStyle.setVerticalAlignment(style.verticalAlignment);
      cellStyle.setRotation(style.rotation);
      cellStyle.setFont(style.font);
      cellStyle.setWrapText(style.wrapText);
      cellStyle.setLocked(style.cellLocked);
      cellStyle.setHidden(style.cellHidden);

      if (style.hasDataFormat())
      {
        cellStyle.setDataFormat(style.getDataFormat());
      }

      if (!isIgnoreCellBorder)
      {
        BoxStyle box = style.box;
        cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]);
        cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]);
        cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]);
        cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]);
        cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]);
        cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]);
        cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]);
        cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]);
      }

      loadedCellStyles.put(style, cellStyle);
    }
    return cellStyle;
View Full Code Here

        if(element.getModeValue() == ModeEnum.OPAQUE )
        {
          backcolor = getWorkbookColor(element.getBackcolor()).getIndex();
        }

        HSSFCellStyle cellStyle =
          getLoadedCellStyle(
            mode,
            backcolor,
            HSSFCellStyle.ALIGN_LEFT,
            HSSFCellStyle.VERTICAL_TOP,
View Full Code Here

      backcolor = getWorkbookColor(frame.getBackcolor()).getIndex();
    }

    short forecolor = getWorkbookColor(frame.getForecolor()).getIndex();

    HSSFCellStyle cellStyle =
      getLoadedCellStyle(
        mode,
        backcolor,
        HSSFCellStyle.ALIGN_LEFT,
        HSSFCellStyle.VERTICAL_TOP,
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.