List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setFillPattern
@Override public void setFillPattern(FillPatternType pattern)
From source file:htmlparser.xls.XLSFile.java
public void createMatchTable(XSSFColor oddrow_color, XSSFColor title_bg_color, XSSFColor title_font_color) { String sheetname = WorkbookUtil.createSafeSheetName(this.parser.getTeamName()); this.matchsheet = this.excelfile.createSheet(sheetname); CreationHelper createHelper = this.excelfile.getCreationHelper(); CellStyle cellStyle = this.excelfile.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); int rows = 0; Row headline = this.matchsheet.createRow(rows); Cell cheadline = headline.createCell(0); cheadline.setCellValue(createHelper.createRichTextString(this.parser.getTeamName())); XSSFCellStyle customstyle = (XSSFCellStyle) this.excelfile.createCellStyle(); customstyle.cloneStyleFrom(cellStyle); XSSFFont fh = (XSSFFont) this.excelfile.createFont(); fh.setFontHeightInPoints((short) 16); fh.setBoldweight(Font.BOLDWEIGHT_BOLD); fh.setColor(title_bg_color);//from ww w.j a v a 2 s .c o m customstyle.setFont(fh); cheadline.setCellStyle(customstyle); int length = this.parser.getMatches().get(0).getData().size(); CellRangeAddress headrow = new CellRangeAddress(rows, rows, 0, length - 1); this.matchsheet.addMergedRegion(headrow); RegionUtil.setBorderBottom(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile); RegionUtil.setBottomBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile); RegionUtil.setBorderLeft(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile); RegionUtil.setLeftBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile); RegionUtil.setBorderRight(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile); RegionUtil.setRightBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile); RegionUtil.setBorderTop(CellStyle.BORDER_THIN, headrow, this.matchsheet, this.excelfile); RegionUtil.setTopBorderColor(IndexedColors.BLACK.getIndex(), headrow, this.matchsheet, this.excelfile); rows++; Row colNms = this.matchsheet.createRow(rows++); customstyle = (XSSFCellStyle) this.excelfile.createCellStyle(); customstyle.cloneStyleFrom(cellStyle); customstyle.setFillForegroundColor(title_bg_color); customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND); XSSFFont f1 = (XSSFFont) this.excelfile.createFont(); f1.setColor(title_font_color); f1.setBoldweight(Font.BOLDWEIGHT_BOLD); customstyle.setFont(f1); int cCN = 0; for (String s : this.mhColNms) { Cell c = colNms.createCell(cCN); c.setCellValue(createHelper.createRichTextString(s)); c.setCellStyle(customstyle); cCN++; } customstyle = (XSSFCellStyle) this.excelfile.createCellStyle(); customstyle.cloneStyleFrom(cellStyle); customstyle.setFillForegroundColor(oddrow_color); customstyle.setFillPattern(CellStyle.SOLID_FOREGROUND); for (Match t : this.parser.getMatches()) { Row r = this.matchsheet.createRow(rows++); int cell = 0; for (String s : t.getData()) { Cell c = r.createCell(cell); c.setCellValue(createHelper.createRichTextString(s)); if (rows % 2 == 0) c.setCellStyle(customstyle); else c.setCellStyle(cellStyle); cell++; } } for (int i = 0; i < length; i++) { this.matchsheet.autoSizeColumn(i); } }
From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java
private static void CreaateHeaderOfErrorList(XSSFWorkbook ErrorWorkbook, Cell column, String text) { XSSFCellStyle headerStyleOfreference = ErrorWorkbook.createCellStyle(); headerStyleOfreference.setAlignment(XSSFCellStyle.ALIGN_CENTER); headerStyleOfreference.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyleOfreference.setFillForegroundColor(new XSSFColor(new java.awt.Color(217, 217, 217))); headerStyleOfreference.setBorderBottom((short) 1); headerStyleOfreference.setBorderTop((short) 1); headerStyleOfreference.setBorderLeft((short) 1); headerStyleOfreference.setBorderRight((short) 1); //create font XSSFFont fontOfCellFirst = ErrorWorkbook.createFont(); fontOfCellFirst.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); fontOfCellFirst.setFontHeightInPoints((short) 12); fontOfCellFirst.setFontName("Calibri"); fontOfCellFirst.setColor(new XSSFColor(new java.awt.Color(0, 0, 0))); headerStyleOfreference.setFont(fontOfCellFirst); column.setCellValue(text);// w ww.ja va 2 s .co m column.setCellStyle(headerStyleOfreference); }
From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java
private static void CreaateStyleOfErrorList(XSSFWorkbook ErrorWorkbook, XSSFRow row, String cell_ref, String sheet_name, String error_desc, String error_level) { XSSFCellStyle StyleOfCell = ErrorWorkbook.createCellStyle(); StyleOfCell.setAlignment(XSSFCellStyle.ALIGN_CENTER); StyleOfCell.setFillPattern(FillPatternType.SOLID_FOREGROUND); if (error_level.equalsIgnoreCase("Warning")) { StyleOfCell.setFillForegroundColor(new XSSFColor(new java.awt.Color(155, 194, 230))); } else {// w ww .ja va 2s. c o m StyleOfCell.setFillForegroundColor(new XSSFColor(new java.awt.Color(225, 171, 171))); } StyleOfCell.setBorderLeft((short) 1); StyleOfCell.setBorderRight((short) 1); StyleOfCell.setBorderTop((short) 1); StyleOfCell.setBorderBottom((short) 1); StyleOfCell.setWrapText(true); //create font XSSFFont fontOfCell = ErrorWorkbook.createFont(); fontOfCell.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); fontOfCell.setFontHeightInPoints((short) 10); fontOfCell.setFontName("Calibri"); fontOfCell.setColor(new XSSFColor(new java.awt.Color(0, 0, 0))); StyleOfCell.setFont(fontOfCell); Cell Rowcell_0 = row.createCell(0); Cell Rowcell_1 = row.createCell(1); Cell Rowcell_2 = row.createCell(2); Cell Rowcell_3 = row.createCell(3); Rowcell_0.setCellValue(cell_ref); Rowcell_1.setCellValue(sheet_name); Rowcell_2.setCellValue(error_desc); Rowcell_3.setCellValue(error_level); Rowcell_0.setCellStyle(StyleOfCell); Rowcell_1.setCellStyle(StyleOfCell); Rowcell_2.setCellStyle(StyleOfCell); Rowcell_3.setCellStyle(StyleOfCell); }
From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java
private static void setColorInfoMetaData(XSSFWorkbook ErrorWorkbook) { //Set Colour used information on first sheet. XSSFSheet setInfoSheet = ErrorWorkbook.getSheetAt(0); XSSFRow colourInfoRow;// www . jav a2 s .com XSSFRow errorColourRow; XSSFRow warningColourRow; if (setInfoSheet.getPhysicalNumberOfRows() > 5) { colourInfoRow = setInfoSheet.getRow(5); } else { colourInfoRow = setInfoSheet.createRow(5); } Cell colorInfoCell = colourInfoRow.createCell(6); Cell RGBCell = colourInfoRow.createCell(7); CreaateHeaderOfErrorList(ErrorWorkbook, colorInfoCell, "Used Color"); CreaateHeaderOfErrorList(ErrorWorkbook, RGBCell, "RGB Value"); setInfoSheet.autoSizeColumn(6); setInfoSheet.autoSizeColumn(7); if (setInfoSheet.getPhysicalNumberOfRows() > 6) { errorColourRow = setInfoSheet.getRow(6); } else { errorColourRow = setInfoSheet.createRow(6); } if (setInfoSheet.getPhysicalNumberOfRows() > 7) { warningColourRow = setInfoSheet.getRow(7); } else { warningColourRow = setInfoSheet.createRow(7); } //error color style XSSFCellStyle errorStyle = ErrorWorkbook.createCellStyle(); errorStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); errorStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(225, 171, 171))); errorColourRow.createCell(6).setCellStyle(errorStyle); errorColourRow.getCell(6).setCellValue("Error"); errorColourRow.createCell(7).setCellValue("225, 171, 171"); //warning color style XSSFCellStyle warningStyle = ErrorWorkbook.createCellStyle(); warningStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); warningStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(155, 194, 230))); warningColourRow.createCell(6).setCellStyle(warningStyle); warningColourRow.getCell(6).setCellValue("Warning"); warningColourRow.createCell(7).setCellValue("155, 194, 230"); }
From source file:jdbreport.model.io.xls.poi.Excel2007Writer.java
License:Apache License
protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) { XSSFCellStyle newStyle = (XSSFCellStyle) wb.createCellStyle(); newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment())); newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment())); Border border = style.getBorders(Border.LINE_BOTTOM); if (border != null) { newStyle.setBorderBottom(getBorder(border)); newStyle.setBottomBorderColor(new XSSFColor(border.getColor())); }/*from w w w . j a va2s .c o m*/ border = style.getBorders(Border.LINE_TOP); if (border != null) { newStyle.setBorderTop(getBorder(border)); newStyle.setTopBorderColor(new XSSFColor(border.getColor())); } border = style.getBorders(Border.LINE_LEFT); if (border != null) { newStyle.setBorderLeft(getBorder(border)); newStyle.setLeftBorderColor(new XSSFColor(border.getColor())); } border = style.getBorders(Border.LINE_RIGHT); if (border != null) { newStyle.setBorderRight(getBorder(border)); newStyle.setRightBorderColor(new XSSFColor(border.getColor())); } Font font = wb.createFont(); font.setFontName(style.getFamily()); if (style.isBold()) { font.setBold(true); } font.setItalic(style.isItalic()); if (style.isUnderline()) { font.setUnderline(Font.U_SINGLE); } if (style.isStrikethrough()) { font.setStrikeout(true); } font.setFontHeightInPoints((short) style.getSize()); if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) { font.setColor(colorToIndex(wb, style.getForegroundColor())); } newStyle.setFont(font); if (style.getBackground() != null && !style.getBackground().equals(Color.white)) { newStyle.setFillForegroundColor(new XSSFColor(style.getBackground())); newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); } if (style.getAngle() != 0) { int angle = style.getAngle(); if (angle > 90 && angle <= 180) { angle = 90; } else if (angle > 180 && angle <= 270) { angle = -90; } else if (angle > 270) { angle = -(360 - angle); } newStyle.setRotation((short) angle); } newStyle.setWrapText(style.isWrapLine()); return newStyle; }
From source file:jpgtoxlsx.JPGtoXLSX.java
/** * @param args the command line arguments *///w w w .j a v a2 s . c o m public static void main(String[] args) throws Exception { XSSFWorkbook myExcel = new XSSFWorkbook(); XSSFSheet sheet = myExcel.createSheet("Image"); BufferedImage image = null; int width, height; int xlrows; //int pixel; File fimg; //open image try { fimg = new File("C:\\excel\\Test.jpg"); image = ImageIO.read(fimg); } catch (IOException e) { System.out.println(e); } width = image.getWidth(); //System.out.println(width); height = image.getHeight(); //System.out.println(height); xlrows = height * 3; //System.out.println(pixel); int r, g, b; int w = image.getWidth(); int h = image.getHeight(); System.out.println("Width: " + w + "Height: " + h); System.out.println("Generating RGB values.."); XSSFCellStyle style1 = myExcel.createCellStyle(); XSSFCellStyle style2 = myExcel.createCellStyle(); XSSFCellStyle style3 = myExcel.createCellStyle(); for (int i = 1; i < ++h; i++) { if (i == image.getHeight()) { break; } XSSFRow row1 = sheet.createRow((i * 3 - 3)); XSSFRow row2 = sheet.createRow((i * 3 - 2)); XSSFRow row3 = sheet.createRow((i * 3 - 1)); for (int j = 0; j < ++w; j++) { if (j == image.getWidth()) { break; } //System.out.println("I: " + i); //System.out.println("J: " + j + "\n"); int x = i; int y = j; //System.out.println("X: " + x + "Y: " + y + "\r"); //System.out.println("Y: " + y); int pixel = image.getRGB(y, x); r = (pixel >> 16) & 0xff; g = (pixel >> 8) & 0xff; b = (pixel) & 0xff; XSSFCell cell1 = row1.createCell(y); XSSFCell cell2 = row2.createCell(y); XSSFCell cell3 = row3.createCell(y); cell1.setCellValue(Integer.toString(r)); cell2.setCellValue(Integer.toString(g)); cell3.setCellValue(Integer.toString(b)); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(r, 0, 0))); ; style1.setFillPattern(CellStyle.SOLID_FOREGROUND); style2.setFillForegroundColor(new XSSFColor(new java.awt.Color(0, g, 0))); style2.setFillPattern(CellStyle.SOLID_FOREGROUND); style3.setFillForegroundColor(new XSSFColor(new java.awt.Color(0, 0, b))); style3.setFillPattern(CellStyle.SOLID_FOREGROUND); cell1.setCellStyle(style1); cell2.setCellStyle(style2); cell3.setCellStyle(style3); //System.out.println("x,y: " + j + ", " + i); //System.out.println("R: " + r + " G: " + g + " B: " + b + "\n"); } } System.out.println("RGB values extracted."); System.out.println("Generating image"); myExcel.write(new FileOutputStream("excel.xlsx")); myExcel.close(); }
From source file:logic.Export.java
public boolean convertXls() throws IOException, FileNotFoundException, IllegalArgumentException, ParseException { FileInputStream tamplateFile = new FileInputStream(templatePath); XSSFWorkbook workbook = new XSSFWorkbook(tamplateFile); CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("#,##")); double hours = 0.0; NumberFormat format = NumberFormat.getInstance(Locale.FRANCE); Number number;/*w ww.j av a 2 s . co m*/ XSSFSheet sheet; XSSFSheet sheet2; Cell cell = null; ConvertData cd = new ConvertData(); for (int i = 0; i < cd.getSheetnames().size(); i++) { sheet2 = workbook.cloneSheet(0, cd.sheetnames.get(i)); sheet = workbook.getSheetAt(i + 1); //formate sheets sheet.getPrintSetup().setLandscape(true); sheet.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); cell = sheet.getRow(0).getCell(1); cell.setCellValue(cd.sheetnames.get(i)); ArrayList<String[]> convert = cd.convert(cd.sheetnames.get(i)); //setPrintArea workbook.setPrintArea(i + 1, //sheet index 0, //start column Spalte 6, //end column 0, //start row zeile convert.size() + 8 //end row ); for (int Row = 0; Row < convert.size(); Row++) { for (int Cell = 0; Cell < convert.get(Row).length; Cell++) { cell = sheet.getRow(9 + Row).getCell(Cell); if (Cell == 3) { if ("true".equals(convert.get(Row)[Cell])) { XSSFCellStyle style1 = workbook.createCellStyle(); style1 = (XSSFCellStyle) cell.getCellStyle(); style1 = (XSSFCellStyle) style1.clone(); style1.setFillBackgroundColor(HSSFColor.RED.index); style1.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); XSSFColor myColor = new XSSFColor(Color.RED); style1.setFillForegroundColor(myColor); sheet.getRow(9 + Row).getCell(6).setCellStyle(style1); } } else { cell.setCellValue(convert.get(Row)[Cell]); } } } } workbook.removeSheetAt(0); tamplateFile.close(); File exportFile = newPath.getSelectedFile(); if (FilenameUtils.getExtension(exportFile.getName()).equalsIgnoreCase("xlsx")) { } else { exportFile = new File(exportFile.getParentFile(), FilenameUtils.getBaseName(exportFile.getName()) + ".xlsx"); } FileOutputStream outFile = new FileOutputStream(exportFile); workbook.write(outFile); outFile.close(); tamplateFile.close(); return true; }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static int generateHeader(XSSFSheet worksheet, XSSFWorkbook workbook, int rowNum) { // Now add/*from www.java 2s . c o m*/ XSSFRow row = worksheet.createRow(rowNum); XSSFCell cell; XSSFCellStyle headerStyle = workbook.createCellStyle(); headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.index); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setBorderBottom(BorderStyle.MEDIUM); headerStyle.setBorderLeft(BorderStyle.MEDIUM); headerStyle.setBorderRight(BorderStyle.MEDIUM); headerStyle.setBorderTop(BorderStyle.MEDIUM); headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFFont txtFont = workbook.createFont(); txtFont.setFontName("calibri"); txtFont.setFontHeightInPoints((short) 9); txtFont.setBold(true); headerStyle.setFont(txtFont); cell = row.createCell(0); cell.setCellValue("Photo"); cell.setCellStyle(headerStyle); worksheet.setColumnWidth(0, ConvertImageUnits.pixel2WidthUnits(COLUMN_WIDTH_PX));//4387 cell = row.createCell(1); cell.setCellValue("Rfrence"); cell.setCellStyle(headerStyle); cell = row.createCell(2); cell.setCellValue("Libell"); cell.setCellStyle(headerStyle); cell = row.createCell(3); cell.setCellValue("Stock\n Appock"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); cell = row.createCell(4); cell.setCellValue("Stock\n rel"); cell.setCellStyle(headerStyle); cell.getCellStyle().setWrapText(true); row.setHeight((short) 600); return rowNum + 1; }
From source file:net.mcnewfamily.rmcnew.model.excel.CellStyleEssence.java
License:Open Source License
public XSSFCellStyle toXSSFCellStyle(XSSFWorkbook workbook) { if (workbook != null) { XSSFCellStyle xssfCellStyle = workbook.createCellStyle(); xssfCellStyle.setBorderTop(topBorder.toPoiCellStyle()); xssfCellStyle.setBorderBottom(bottomBorder.toPoiCellStyle()); xssfCellStyle.setBorderLeft(leftBorder.toPoiCellStyle()); xssfCellStyle.setBorderRight(rightBorder.toPoiCellStyle()); xssfCellStyle.setAlignment(horizontalAlignment.toPoiCellStyle()); xssfCellStyle.setVerticalAlignment(verticalAlignment.toPoiCellStyle()); xssfCellStyle.setFillPattern(fillPattern.toPoiCellStyle()); // foreground color must be set before background color is set xssfCellStyle.setFillForegroundColor(foregroundColor); xssfCellStyle.setFillBackgroundColor(backgroundColor); xssfCellStyle.setWrapText(this.wrappedText); xssfCellStyle.setIndention(this.indentationInSpaces); if (this.fontEssence != null) { XSSFFont font = fontEssence.toXSSFFont(workbook); xssfCellStyle.setFont(font); }/*from ww w . j a v a2s. co m*/ return xssfCellStyle; } else { throw new IllegalArgumentException("Cannot create XSSFCellStyle using a null XSSFWorkbook!"); } }
From source file:net.mcnewfamily.rmcnew.shared.Util.java
License:Open Source License
public static void copyXSSFCellStyle(XSSFCell srcCell, XSSFCell destCell) { XSSFCellStyle srcCellStyle = srcCell.getCellStyle(); XSSFCellStyle destCellStyle = destCell.getCellStyle(); // destCellStyle.cloneStyleFrom(srcCellStyle); destCellStyle.setAlignment(srcCellStyle.getAlignment()); destCellStyle.setVerticalAlignment(srcCellStyle.getVerticalAlignment()); destCellStyle.setFont(srcCellStyle.getFont()); destCellStyle.setBorderBottom(srcCellStyle.getBorderBottom()); destCellStyle.setBorderLeft(srcCellStyle.getBorderLeft()); destCellStyle.setBorderRight(srcCellStyle.getBorderRight()); destCellStyle.setBorderTop(srcCellStyle.getBorderTop()); destCellStyle.setFillPattern(srcCellStyle.getFillPattern()); // foreground color must be set before background color is set destCellStyle.setFillForegroundColor(srcCellStyle.getFillForegroundColor()); destCellStyle.setFillBackgroundColor(srcCellStyle.getFillBackgroundColor()); destCellStyle.setIndention(srcCellStyle.getIndention()); destCellStyle.setWrapText(srcCellStyle.getWrapText()); destCell.setCellStyle(destCellStyle); }