List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setFont
public void setFont(HSSFFont font)
From source file:de.maklerpoint.office.Schnittstellen.Excel.ExportExcelXLS.java
License:Open Source License
/** * create a library of cell styles//from w w w . j a v a 2 s . c om */ private static Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) { Map<String, HSSFCellStyle> styles = new HashMap<String, HSSFCellStyle>(); HSSFDataFormat df = wb.createDataFormat(); HSSFCellStyle style; HSSFFont headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("header_date", style); HSSFFont font1 = wb.createFont(); font1.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font1); styles.put("cell_b", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_b_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_g", style); HSSFFont font2 = wb.createFont(); font2.setColor(IndexedColors.BLUE.getIndex()); font2.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font2); styles.put("cell_bb", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_bg", style); HSSFFont font3 = wb.createFont(); font3.setFontHeightInPoints((short) 14); font3.setColor(IndexedColors.DARK_BLUE.getIndex()); font3.setBoldweight(Font.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setFont(font3); style.setWrapText(true); styles.put("cell_h", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setWrapText(true); styles.put("cell_normal", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); styles.put("cell_normal_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setWrapText(true); style.setDataFormat(df.getFormat("dd.MM.yyyy")); styles.put("cell_normal_date", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_LEFT); style.setIndention((short) 1); style.setWrapText(true); styles.put("cell_indented", style); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("cell_blue", style); return styles; }
From source file:de.maklerpoint.office.Schnittstellen.Excel.ExportKalenderExcel.java
License:Open Source License
private static Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) { Map<String, HSSFCellStyle> styles = new HashMap<String, HSSFCellStyle>(); short borderColor = IndexedColors.GREY_50_PERCENT.getIndex(); HSSFCellStyle style; HSSFFont titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 48); titleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle();// ww w .ja va2 s.c o m style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); HSSFFont monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 12); monthFont.setColor(IndexedColors.WHITE.getIndex()); monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(monthFont); styles.put("month", style); HSSFFont dayFont = wb.createFont(); dayFont.setFontHeightInPoints((short) 14); dayFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setLeftBorderColor(borderColor); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); style.setFont(dayFont); styles.put("weekend_left", style); style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); styles.put("weekend_right", style); style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setLeftBorderColor(borderColor); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); style.setFont(dayFont); styles.put("workday_left", style); style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); styles.put("workday_right", style); style = wb.createCellStyle(); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); styles.put("grey_left", style); style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setRightBorderColor(borderColor); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); styles.put("grey_right", style); return styles; }
From source file:de.thorstenberger.taskmodel.impl.ReportBuilderImpl.java
License:Open Source License
private short createUserInfoColumns(Tasklet tasklet, short c, HSSFWorkbook wb, HSSFRow row) { UserInfo userInfo = taskManager.getUserInfo(tasklet.getUserId()); List<UserAttribute> uas = taskManager.availableUserAttributes(); String login;/*from w ww . j av a 2 s . c o m*/ String firstName; String name; List<String> userAttributeValues = new LinkedList<String>(); ; boolean notfound; if (userInfo != null) { login = userInfo.getLogin(); firstName = userInfo.getFirstName(); name = userInfo.getName(); for (UserAttribute ua : uas) { String s = userInfo.getUserAttributeValue(ua.getKey()); if (s == null || s.trim().length() == 0) { s = "-"; } userAttributeValues.add(s); } notfound = false; } else { login = tasklet.getUserId(); firstName = "?"; name = "?"; for (UserAttribute ua : uas) { userAttributeValues.add("?"); } notfound = true; } if (notfound) { HSSFCellStyle cs2 = wb.createCellStyle(); HSSFFont font2 = wb.createFont(); font2.setColor(HSSFColor.RED.index); cs2.setFont(font2); HSSFCell cell2 = row.createCell(c++); cell2.setCellStyle(cs2); cell2.setCellValue(login); } else { row.createCell(c++).setCellValue(login); } row.createCell(c++).setCellValue(firstName); row.createCell(c++).setCellValue(name); for (String uav : userAttributeValues) { row.createCell(c++).setCellValue(uav); } return c; }
From source file:de.viaboxx.nlstools.formats.MBExcelPersistencer.java
License:Apache License
private void initStyles(HSSFWorkbook wb) { // cache styles used to write text into cells HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont();// ww w .j a v a 2s.co m font.setBold(true); style.setFont(font); styles.put(STYLE_BOLD, style); style = wb.createCellStyle(); font = wb.createFont(); font.setItalic(true); style.setFont(font); styles.put(STYLE_ITALIC, style); style = wb.createCellStyle(); font = wb.createFont(); font.setItalic(true); font.setColor(Font.COLOR_RED); style.setFont(font); styles.put(STYLE_REVIEW, style); style = wb.createCellStyle(); style.setFillPattern(FillPatternType.FINE_DOTS); style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); styles.put(STYLE_MISSING, style); style = wb.createCellStyle(); style.setFillPattern(FillPatternType.FINE_DOTS); style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.BLUE_GREY.getIndex()); style.setFont(font); styles.put(STYLE_MISSING_REVIEW, style); style = wb.createCellStyle(); HSSFCreationHelper createHelper = wb.getCreationHelper(); style.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-dd-mm hh:mm")); styles.put(STYLE_DATETIME, style); }
From source file:demo.poi.BigExample.java
License:Apache License
public static void main(String[] args) throws IOException { int rownum;/*w w w . j a va2 s . c o m*/ // create a new file FileOutputStream out = new FileOutputStream("target/bigworkbook.xls"); // create a new workbook HSSFWorkbook wb = new HSSFWorkbook(); // create a new sheet HSSFSheet s = wb.createSheet(); // declare a row object reference HSSFRow r = null; // declare a cell object reference HSSFCell c = null; // create 3 cell styles HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); // create 2 fonts objects HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); //set font 1 to 12 point type f.setFontHeightInPoints((short) 12); //make it red f.setColor(HSSFColor.RED.index); // make it bold //arial is the default font f.setBoldweight(Font.BOLDWEIGHT_BOLD); //set font 2 to 10 point type f2.setFontHeightInPoints((short) 10); //make it the color at palette index 0xf (white) f2.setColor(HSSFColor.WHITE.index); //make it bold f2.setBoldweight(Font.BOLDWEIGHT_BOLD); //set cell stlye cs.setFont(f); //set the cell format see HSSFDataFromat for a full list cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); //set a thin border cs2.setBorderBottom(CellStyle.BORDER_THIN); //fill w fg fill color cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); // set foreground fill to red cs2.setFillForegroundColor(HSSFColor.RED.index); // set the font cs2.setFont(f2); // set the sheet name to HSSF Test wb.setSheetName(0, "HSSF Test"); // create a sheet with 300 rows (0-299) for (rownum = 0; rownum < 300; rownum++) { // create a row r = s.createRow(rownum); // on every other row if ((rownum % 2) == 0) { // make the row height bigger (in twips - 1/20 of a point) r.setHeight((short) 0x249); } //r.setRowNum(( short ) rownum); // create 50 cells (0-49) (the += 2 becomes apparent later for (int cellnum = 0; cellnum < 50; cellnum += 2) { // create a numeric cell c = r.createCell(cellnum); // do some goofy math to demonstrate decimals c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); // on every other row if ((rownum % 2) == 0) { // set this cell to the first cell style we defined c.setCellStyle(cs); } // create a string cell (see why += 2 in the c = r.createCell(cellnum + 1); // set the cell's string value to "TEST" c.setCellValue("TEST"); // make this column a bit wider s.setColumnWidth(cellnum + 1, (int) ((50 * 8) / ((double) 1 / 20))); // on every other row if ((rownum % 2) == 0) { // set this to the white on red cell style // we defined above c.setCellStyle(cs2); } } } //draw a thick black border on the row at the bottom using BLANKS // advance 2 rows rownum++; rownum++; r = s.createRow(rownum); // define the third style to be the default // except with a thick black border at the bottom cs3.setBorderBottom(CellStyle.BORDER_THICK); //create 50 cells for (int cellnum = 0; cellnum < 50; cellnum++) { //create a blank type cell (no value) c = r.createCell(cellnum); // set it to the thick black border style c.setCellStyle(cs3); } //end draw thick black border // demonstrate adding/naming and deleting a sheet // create a sheet, set its title then delete it s = wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); //end deleted sheet // write the workbook to the output stream // close our file (don't blow out our file handles wb.write(out); out.close(); }
From source file:devcup.search4u.xlsview.ConvertResultsToXLS.java
public void createXLSTable() throws IOException { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Result sheet"); //create headerRow Row headerRow = sheet.createRow(0);//from w ww.j av a 2 s .c o m HSSFCellStyle headerStyle = workbook.createCellStyle(); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont partFont = workbook.createFont(); //partFont.setItalic(true); partFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); partFont.setUnderline(HSSFFont.U_DOUBLE); HSSFFont defaultFont = workbook.createFont(); defaultFont.setFontHeightInPoints((short) 10); defaultFont.setFontName("Arial"); defaultFont.setColor(HSSFColor.BLACK.index); defaultFont.setItalic(false); HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 11); font.setFontName("Arial"); font.setColor(HSSFColor.BLUE_GREY.index); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setItalic(true); //style=(HSSFCellStyle) headerRow.getRowStyle(); //style.setFillPattern(CellStyle.SOLID_FOREGROUND); headerStyle.setWrapText(true); headerStyle.setAlignment(CellStyle.ALIGN_CENTER); //style.setFillBackgroundColor(HSSFColor.ROYAL_BLUE.index); //style.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); //style.setHidden(false); //style.setIndention(indent); headerStyle.setFont(font); //create a new cell in headerRow Cell headerCell; headerCell = headerRow.createCell(0); headerCell.setCellValue("?"); headerCell.setCellStyle(headerStyle); //sheet.autoSizeColumn(0); sheet.setColumnWidth(0, 7000); headerCell = headerRow.createCell(1); headerCell.setCellValue(" "); headerCell.setCellStyle(headerStyle); //sheet.autoSizeColumn(1); sheet.setColumnWidth(1, 12000); /*headerCell = headerRow.createCell(2); headerCell.setCellValue("? "); headerCell.setCellStyle(style); sheet.autoSizeColumn(2); //sheet.setColumnWidth(2, 7000); */ headerCell = headerRow.createCell(2); headerCell.setCellValue(" ?"); headerCell.setCellStyle(headerStyle); //sheet.autoSizeColumn(3); sheet.setColumnWidth(2, 18000); style.setWrapText(true); style.setFont(defaultFont); //create another Rows int rowNum = 1; for (SearchResult searchResult : searchResultsList) { for (String key : searchResult.getRelevDocsPath()) { //for (String key : searchResult.getDocumentsFragments().keySet()) { for (ObjectPair<Integer, String> pair : searchResult.getDocumentsFragments().get(key)) { Row row = sheet.createRow(rowNum++); Cell cell; cell = row.createCell(0); cell.setCellValue(searchResult.getQuery()); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue(key); cell.setCellStyle(style); //cell = row.createCell(2); //cell.setCellValue(pair.getFirst()); //cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue(labeledStringToRichTextString(pair.getSecond(), partFont)); cell.setCellStyle(style); } } } try { FileOutputStream out = new FileOutputStream(new File(resultXMLPath)); workbook.write(out); out.close(); System.out.println("Excel written successfully.."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:domain.Excel.java
public void reporteSesionPeso() { // cargarLogo(); sheet.addMergedRegion(CellRangeAddress.valueOf("A1:E1")); sheet.addMergedRegion(CellRangeAddress.valueOf("A2:E2")); sheet.addMergedRegion(CellRangeAddress.valueOf("A3:E4")); /*Name REPORT*/ HSSFFont FontNameReport = wb.createFont(); FontNameReport.setFontName("Calibri"); FontNameReport.setFontHeightInPoints((short) 11); FontNameReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontNameReport.setColor(HSSFColor.DARK_RED.index); HSSFCellStyle styleNameReport = wb.createCellStyle(); styleNameReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleNameReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleNameReport.setFont(FontNameReport); Row row = sheet.createRow(0);//w w w . j a va 2 s. c o m Cell cell = row.createCell(0); cell.setCellValue("REPORTE DE SESIONES POR PESOS"); cell.setCellStyle(styleNameReport); /**/ /*DATE REPORT*/ HSSFFont FontDateReport = wb.createFont(); FontDateReport.setFontName("Calibri"); FontDateReport.setFontHeightInPoints((short) 10); FontDateReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontDateReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleDateReport = wb.createCellStyle(); styleDateReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleDateReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleDateReport.setFont(FontDateReport); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("FECHA DE REPORTE: " + formatoDateTime.format(new Date())); cell.setCellStyle(styleDateReport); /*Etiqueta parametro*/ HSSFFont FontParametroReport = wb.createFont(); FontParametroReport.setFontName("Calibri"); FontParametroReport.setFontHeightInPoints((short) 9); FontParametroReport.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); FontParametroReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleParamReport = wb.createCellStyle(); styleParamReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleParamReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleParamReport.setFont(FontParametroReport); row = sheet.createRow(2); cell = row.createCell(0); String etiqueta_parametro = ""; switch (tipo) { case 1: etiqueta_parametro = "Sesion de dia " + formatoDate.format(fecha_ini); break; case 2: etiqueta_parametro = "Sesiones del " + formatoDate.format(fecha_ini) + " al " + formatoDate.format(fecha_fin); break; case 3: etiqueta_parametro = "Sesiones del animal " + animal.arete_visual; break; } cell.setCellValue(etiqueta_parametro); cell.setCellStyle(styleParamReport); /**/ sheet.createRow(5).createCell(0).setCellValue("Arete Visual"); sheet.getRow(5).createCell(1).setCellValue("Arete Electronico"); sheet.getRow(5).createCell(2).setCellValue("Fecha"); sheet.getRow(5).createCell(3).setCellValue("Peso"); sheet.getRow(5).createCell(4).setCellValue("Corral"); sheet.setColumnWidth(0, 16 * Unidad); sheet.setColumnWidth(1, 16 * Unidad); sheet.setColumnWidth(2, 16 * Unidad); sheet.setColumnWidth(3, 16 * Unidad); sheet.setColumnWidth(4, 16 * Unidad); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); //Condition 1: Cell Value Is greater than 70 (Blue Fill) ConditionalFormattingRule rule1 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.GT, "1000"); PatternFormatting fill1 = rule1.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); //Condition 2: Cell Value Is less than 50 (Green Fill) ConditionalFormattingRule rule2 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.LT, "50"); PatternFormatting fill2 = rule2.createPatternFormatting(); fill2.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND); FontFormatting font = rule1.createFontFormatting(); font.setFontStyle(false, true); font.setFontColorIndex(IndexedColors.WHITE.index); CellRangeAddress[] regions = { CellRangeAddress.valueOf("A6:E6") }; sheetCF.addConditionalFormatting(regions, rule1, rule2); Integer fila_inicial = 6; for (int i = 0; i < this.t_tabla.getRowCount(); i++) { sheet.createRow(fila_inicial + i).createCell(0).setCellValue(t_tabla.getValueAt(i, 1).toString()); sheet.getRow(fila_inicial + i).getCell(0).setCellStyle(styleCenter); for (int j = 1; j < 5; j++) { sheet.getRow(fila_inicial + i).createCell(j).setCellValue(t_tabla.getValueAt(i, j + 1).toString()); sheet.getRow(fila_inicial + i).getCell(j).setCellStyle(styleCenter); } sheet.getRow(fila_inicial + i).getCell(3) .setCellValue(Double.parseDouble(t_tabla.getValueAt(i, 4).toString())); sheet.getRow(fila_inicial + i).getCell(3).setCellStyle(styleRight); } cargarLogo(); }
From source file:domain.Excel.java
private void reporteSesionMedicina() { sheet.addMergedRegion(CellRangeAddress.valueOf("A1:I1")); sheet.addMergedRegion(CellRangeAddress.valueOf("A2:I2")); sheet.addMergedRegion(CellRangeAddress.valueOf("A3:I4")); /*Name REPORT*/ HSSFFont FontNameReport = wb.createFont(); FontNameReport.setFontName("Calibri"); FontNameReport.setFontHeightInPoints((short) 11); FontNameReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontNameReport.setColor(HSSFColor.DARK_RED.index); HSSFCellStyle styleNameReport = wb.createCellStyle(); styleNameReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleNameReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleNameReport.setFont(FontNameReport); Row row = sheet.createRow(0);/*from w ww . jav a2 s . c o m*/ Cell cell = row.createCell(0); cell.setCellValue("REPORTE DE SESIONES POR MEDICAMENTOS"); cell.setCellStyle(styleNameReport); /**/ /*DATE REPORT*/ HSSFFont FontDateReport = wb.createFont(); FontDateReport.setFontName("Calibri"); FontDateReport.setFontHeightInPoints((short) 10); FontDateReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontDateReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleDateReport = wb.createCellStyle(); styleDateReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleDateReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleDateReport.setFont(FontDateReport); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("FECHA DE REPORTE: " + formatoDateTime.format(new Date())); cell.setCellStyle(styleDateReport); /*Etiqueta parametro*/ HSSFFont FontParametroReport = wb.createFont(); FontParametroReport.setFontName("Calibri"); FontParametroReport.setFontHeightInPoints((short) 9); FontParametroReport.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); FontParametroReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleParamReport = wb.createCellStyle(); styleParamReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleParamReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleParamReport.setFont(FontParametroReport); row = sheet.createRow(2); cell = row.createCell(0); String etiqueta_parametro = ""; switch (tipo) { case 1: etiqueta_parametro = "Sesion de dia " + formatoDate.format(fecha_ini); break; case 2: etiqueta_parametro = "Sesiones del " + formatoDate.format(fecha_ini) + " al " + formatoDate.format(fecha_fin); break; case 3: etiqueta_parametro = "Sesiones del animal " + animal.arete_visual; break; } cell.setCellValue(etiqueta_parametro); cell.setCellStyle(styleParamReport); /**/ sheet.createRow(5).createCell(0).setCellValue("Arete Visual"); sheet.getRow(5).createCell(1).setCellValue("Arete Electronico"); sheet.getRow(5).createCell(2).setCellValue("Codigo"); sheet.getRow(5).createCell(3).setCellValue("Medicamento"); sheet.getRow(5).createCell(4).setCellValue("Fecha"); sheet.getRow(5).createCell(5).setCellValue("Corral"); sheet.getRow(5).createCell(6).setCellValue("Dosis"); sheet.getRow(5).createCell(7).setCellValue("Costo"); sheet.getRow(5).createCell(8).setCellValue("Importe"); sheet.setColumnWidth(0, 15 * Unidad); sheet.setColumnWidth(1, 20 * Unidad); sheet.setColumnWidth(2, 15 * Unidad); sheet.setColumnWidth(3, 20 * Unidad); sheet.setColumnWidth(4, 20 * Unidad); sheet.setColumnWidth(5, 20 * Unidad); sheet.setColumnWidth(6, 15 * Unidad); sheet.setColumnWidth(7, 15 * Unidad); sheet.setColumnWidth(8, 15 * Unidad); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); //Condition 1: Cell Value Is greater than 70 (Blue Fill) ConditionalFormattingRule rule1 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.GT, "1000"); PatternFormatting fill1 = rule1.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); //Condition 2: Cell Value Is less than 50 (Green Fill) ConditionalFormattingRule rule2 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.LT, "50"); PatternFormatting fill2 = rule2.createPatternFormatting(); fill2.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND); FontFormatting font = rule1.createFontFormatting(); font.setFontStyle(false, true); font.setFontColorIndex(IndexedColors.WHITE.index); CellRangeAddress[] regions = { CellRangeAddress.valueOf("A6:I6") }; sheetCF.addConditionalFormatting(regions, rule1, rule2); Integer fila_inicial = 6; for (int i = 0; i < this.t_tabla.getRowCount(); i++) { agregarValor(fila_inicial + i, 0, t_tabla.getValueAt(i, 1).toString(), styleCenter); for (int j = 0; j < 9; j++) { agregarValor(fila_inicial + i, j, t_tabla.getValueAt(i, j + 1).toString(), styleCenter); } } cargarLogo(); }
From source file:DomainToolCore.Report.XLSSubDomains.java
License:Open Source License
private HSSFCellStyle setBold() { HSSFCellStyle cellStyle = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(font); return cellStyle; }
From source file:DomainToolCore.Report.XLSSubDomains.java
License:Open Source License
private HSSFCellStyle BackColor() { HSSFCellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setColor(HSSFColor.RED.index);//ww w . j a va2s . c om font.setItalic(true); style.setFont(font); return style; }