List of usage examples for org.apache.poi.ss.usermodel Font setBold
public void setBold(boolean bold);
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloProveedor(Workbook wb) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); fuente.setFontName("Calibri"); fuente.setBold(true); fuente.setFontHeightInPoints((short) 32); fuente.setColor(IndexedColors.ROYAL_BLUE.getIndex()); estiloCelda.setFont(fuente);//www. ja v a 2 s . c o m estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); return estiloCelda; }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloColumnas(Workbook wb, int tipo) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); if (tipo == COLUMNA) { estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); fuente.setBold(true); }/*from ww w .ja v a2 s .co m*/ if (tipo == SURTIDO) { fuente.setColor(IndexedColors.WHITE.getIndex()); estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); } fuente.setFontName("Calibri"); fuente.setFontHeightInPoints((short) 11); estiloCelda.setFont(fuente); estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); if (tipo == COLUMNA) { estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); } else { estiloCelda.setBorderBottom(BorderStyle.THIN); estiloCelda.setBorderTop(BorderStyle.THIN); estiloCelda.setBorderLeft(BorderStyle.THIN); estiloCelda.setBorderRight(BorderStyle.THIN); } return estiloCelda; }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloTotales(Workbook wb) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); estiloCelda.setFillForegroundColor(IndexedColors.ROYAL_BLUE.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); fuente.setFontName("Calibri"); fuente.setBold(true); fuente.setFontHeightInPoints((short) 14); fuente.setColor(IndexedColors.WHITE.getIndex()); estiloCelda.setFont(fuente);/* w w w. ja va2s. co m*/ estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); return estiloCelda; }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloCuadro(Workbook wb, int tipo) { CellStyle estiloCelda = wb.createCellStyle(); Font fuente = wb.createFont(); if (tipo == AMARILLO) { estiloCelda.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); }/* w ww. ja va 2 s.c om*/ fuente.setFontName("Calibri"); fuente.setBold(true); fuente.setFontHeightInPoints((short) 12); estiloCelda.setFont(fuente); estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); estiloCelda.setAlignment(HorizontalAlignment.CENTER); estiloCelda.setBorderBottom(BorderStyle.THIN); estiloCelda.setBorderTop(BorderStyle.THIN); estiloCelda.setBorderLeft(BorderStyle.THIN); estiloCelda.setBorderRight(BorderStyle.THIN); return estiloCelda; }
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloHeader(Workbook wb, int tipo) { Font fuente = wb.createFont(); CreationHelper createHelper = wb.getCreationHelper(); fuente.setFontName("Calibri"); fuente.setBold(true); if (tipo == TITULO || tipo == SUCURSAL || tipo == LABEL || tipo == FECHA) { fuente.setFontHeightInPoints((short) 16); } else if (tipo == USUARIO) { fuente.setFontHeightInPoints((short) 20); }/*from www . j av a 2 s .c o m*/ CellStyle estiloCelda = wb.createCellStyle(); estiloCelda.setFont(fuente); if (tipo == TITULO || tipo == USUARIO || tipo == LABEL || tipo == FECHA) { estiloCelda.setFillForegroundColor(IndexedColors.WHITE.getIndex()); } else if (tipo == SUCURSAL) { estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); } estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setWrapText(false); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setWrapText(true); } estiloCelda.setAlignment(HorizontalAlignment.CENTER); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setVerticalAlignment(VerticalAlignment.BOTTOM); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); } if (tipo == SUCURSAL) { estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); } if (tipo == FECHA) { estiloCelda.setDataFormat(createHelper.createDataFormat().getFormat("dd \"de\" mmmm \"de\" yyyy")); } return estiloCelda; }
From source file:com.company.et.service.XlsService.java
private static void setCellStyle(Workbook wb, Sheet s, Cell cell) { CellStyle cellStyle = wb.createCellStyle(); // if (cell.getStringCellValue().equals("??")) { // s.autoSizeColumn(0,true); // }//from ww w . j a v a 2 s . co m cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); Font font = wb.createFont(); font.setBold(true); cellStyle.setFont(font); cell.setCellStyle(cellStyle); }
From source file:com.diversityarrays.kdxplore.exportdata.CellStyleProvider.java
License:Open Source License
public CellStyle getBoldHeading() { if (boldHeading == null) { boldHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true); boldHeading.setFont(font);//w ww. j av a 2s.c o m } return boldHeading; }
From source file:com.ferid.app.classroom.utility.ExcelStyleManager.java
License:Apache License
/** * Header cell style (dates)/*from w w w . jav a 2 s .co m*/ * @param wb Workbook * @return CellStyle */ public static CellStyle getHeaderCellStyle(Workbook wb) { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); Font font = wb.createFont(); font.setFontHeightInPoints((short) 8); font.setBold(true); cellStyle.setFont(font); cellStyle.setWrapText(true); cellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); return cellStyle; }
From source file:com.funtl.framework.smoke.core.commons.excel.ExportExcel.java
License:Apache License
/** * ?// ww w.j ava 2s . c o m * * @param wb * @return ? */ private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); // style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Font titleFont = wb.createFont(); titleFont.setFontName("Arial"); titleFont.setFontHeightInPoints((short) 16); titleFont.setBold(true); // titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(titleFont); styles.put("title", style); style = wb.createCellStyle(); style.setVerticalAlignment(VerticalAlignment.CENTER); // style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setBorderRight(BorderStyle.THIN); // style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.THIN); // style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderTop(BorderStyle.THIN); // style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.THIN); // style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); Font dataFont = wb.createFont(); dataFont.setFontName("Arial"); dataFont.setFontHeightInPoints((short) 10); style.setFont(dataFont); styles.put("data", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.LEFT); // style.setAlignment(CellStyle.ALIGN_LEFT); styles.put("data1", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); styles.put("data2", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.RIGHT); // style.setAlignment(CellStyle.ALIGN_RIGHT); styles.put("data3", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); // style.setWrapText(true); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); // style.setFillPattern(CellStyle.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeightInPoints((short) 10); headerFont.setBold(true); // headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); styles.put("header", style); return styles; }
From source file:com.guardias.excel.CalendarToExcel.java
License:Apache License
public static void GenerateExcel(String RutaFile, Calendar calendar, String JSONContenidos, Medico AdministratorUser) throws IOException { Guardias[] lGuardias;//from ww w .j a v a 2 s .c o m Gson gson = new GsonBuilder().create(); lGuardias = gson.fromJson(JSONContenidos, Guardias[].class); boolean xlsx = true; int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); DateFormat _format = new SimpleDateFormat("yyyy-MM-dd"); Workbook wb = xlsx ? new XSSFWorkbook() : new HSSFWorkbook(); Map<String, CellStyle> styles = createStyles(wb); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.setFirstDayOfWeek(Calendar.MONDAY); //create a sheet for each month Sheet sheet = wb.createSheet(_format.format(calendar.getTime())); CellStyle styleBORDER = wb.createCellStyle(); styleBORDER.setBorderRight(CellStyle.BORDER_THICK); styleBORDER.setBorderBottom(CellStyle.BORDER_THICK); styleBORDER.setBorderTop(CellStyle.BORDER_THICK); styleBORDER.setBorderLeft(CellStyle.BORDER_THICK); styleBORDER.setRightBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); styleBORDER.setLeftBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); styleBORDER.setTopBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); styleBORDER.setBottomBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); // //turn off gridlines sheet.setDisplayGridlines(true); sheet.autoSizeColumn(0); sheet.setPrintGridlines(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); //header with month titles Row monthRow = sheet.createRow(1); Font fontH = wb.createFont(); CellStyle CStyleH = wb.createCellStyle(); CStyleH.setBorderRight(CellStyle.BORDER_THICK); CStyleH.setRightBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); fontH.setBold(true); CStyleH.setFont(fontH); for (int i = 0; i < days.length; i++) { Cell monthCell = monthRow.createCell(i); monthCell.setCellStyle(CStyleH); monthCell.setCellValue(days[i]); sheet.autoSizeColumn(i); } int cnt = 1, day = 1; int rownum = 2; for (int j = 0; j < 6; j++) { Row row = sheet.createRow(rownum++); Row rowGuardias; boolean bRowsCreated = false; // row.setHeightInPoints(100); for (int i = 0; i < days.length; i++) { Cell dayCell_1 = row.createCell(i); // Cell dayCell_2 = row.createCell(i*2 + 1); int currentDayOfWeek = (calendar.get(Calendar.DAY_OF_WEEK) + 7 - calendar.getFirstDayOfWeek()) % 7; //int day_of_week = calendar.get(Calendar.DAY_OF_WEEK); if (cnt > currentDayOfWeek && calendar.get(Calendar.MONTH) == month) { Font font = wb.createFont(); CellStyle CStyle = wb.createCellStyle(); short colorI = HSSFColor.AQUA.index; // presencia //font.set(colorI); CStyle.setFillForegroundColor(colorI); CStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); //CStyle.setBorderBottom( colorBorder); CStyle.setBorderRight(CellStyle.BORDER_THICK); CStyle.setBorderBottom(CellStyle.BORDER_THICK); CStyle.setBorderTop(CellStyle.BORDER_THICK); CStyle.setBorderLeft(CellStyle.BORDER_THICK); CStyle.setRightBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); CStyle.setLeftBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); CStyle.setTopBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); CStyle.setBottomBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); //CStyle.setFont(font); dayCell_1.setCellValue(day); dayCell_1.setCellStyle(CStyle); sheet.autoSizeColumn(i); String _Dia = _format.format(calendar.getTime()); int DataRowCont = 1; // esto sirve para coger la fila de los datos de cada dia for (int d = 0; d < lGuardias.length; d++) { Guardias oGuardias = lGuardias[d]; if (oGuardias.getDiaGuardia().equals(_Dia)) { if (!bRowsCreated) rowGuardias = sheet.createRow(rownum++); else rowGuardias = sheet.getRow(row.getRowNum() + DataRowCont); Cell dayCell_1_GUARDIAS = rowGuardias.createCell(i); // Cell dayCell_2_GUARDIAS = rowGuardias.createCell(i*2 + 1); List<Medico> _lMedico = MedicoDBImpl.getMedicos(oGuardias.getIdMedico(), AdministratorUser.getServicioId()); Medico _oMedico = _lMedico.get(0); font = wb.createFont(); CStyle = wb.createCellStyle(); // PRESENCIA // LOCALIZADA //XSSFRichTextString richString = new HSSFRichTextString(_oMedico.getApellidos() + " " + _oMedico.getNombre()); colorI = HSSFColor.LIGHT_ORANGE.index; // presencia if (oGuardias.getTipo().equals(Util.eTipoGuardia.LOCALIZADA.toString().toLowerCase())) colorI = HSSFColor.GREEN.index; else if (oGuardias.getTipo() .equals(Util.eTipoGuardia.REFUERZO.toString().toLowerCase())) colorI = HSSFColor.BLUE.index; else if (oGuardias.getTipo().equals("")) // residente colorI = HSSFColor.RED.index; font.setColor(colorI); CStyle.setFont(font); //CStyle.setBorderBottom( colorBorder); CStyle.setBorderRight(CellStyle.BORDER_THICK); CStyle.setRightBorderColor(IndexedColors.LIGHT_ORANGE.getIndex()); dayCell_1_GUARDIAS.setCellValue(_oMedico.getApellidos() + " " + _oMedico.getNombre() + "[" + _oMedico.getIDMEDICO() + "]"); dayCell_1_GUARDIAS.setCellStyle(CStyle); DataRowCont++; } } bRowsCreated = true; // dayCell_1_GUARDIAS.setCellValue(TextoGuardias.toString()); calendar.set(Calendar.DAY_OF_MONTH, ++day); /*if(i == 0 || i == days.length-1) { dayCell_1.setCellStyle(styles.get("weekend_left")); dayCell_2.setCellStyle(styles.get("weekend_right")); } else { dayCell_1.setCellStyle(styles.get("workday_left")); dayCell_2.setCellStyle(styles.get("workday_right")); } } else { dayCell_1.setCellStyle(styles.get("grey_left")); dayCell_2.setCellStyle(styles.get("grey_right"));*/ } cnt++; } if (calendar.get(Calendar.MONTH) > month) break; } // } // Write the output to a file String file = RutaFile; FileOutputStream out = new FileOutputStream(file); wb.write(out); out.close(); wb.close(); }