List of usage examples for org.apache.poi.ss.usermodel CellStyle setVerticalAlignment
void setVerticalAlignment(VerticalAlignment align);
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java
License:Mozilla Public License
public CellStyle buildMetadataValueCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_LEFT); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); cellStyle.setWrapText(true);/*from w w w. ja v a 2 s. c o m*/ Font font = sheet.getWorkbook().createFont(); font.setFontHeightInPoints(METADATA_VALUE_FONT_SIZE); font.setFontName(FONT_NAME); cellStyle.setFont(font); return cellStyle; }
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java
License:Mozilla Public License
public CellStyle buildFiltersTitleCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_LEFT); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setWrapText(false);//from w w w . j ava2 s .c om Font font = sheet.getWorkbook().createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints(FILTERS_TITLE_FONT_SIZE); font.setFontName(FONT_NAME); cellStyle.setFont(font); return cellStyle; }
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java
License:Mozilla Public License
public CellStyle buildFiltersValuesCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_LEFT); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setWrapText(false);// w ww .ja v a 2s . c o m Font font = sheet.getWorkbook().createFont(); font.setFontHeightInPoints(FILTERS_VALUES_FONT_SIZE); font.setFontName(FONT_NAME); cellStyle.setFont(font); return cellStyle; }
From source file:it.unitn.elisco.utils.Utilities.java
public static Workbook getExcelFromQuestionList(String workbookName, List<Question> questions) { // Create EXCEL File (Workbook with sheets) Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(workbookName); // Create styles for cells CellStyle questionStyle = workbook.createCellStyle(); questionStyle.setWrapText(true);//www. j av a 2 s . c o m questionStyle.setVerticalAlignment(VerticalAlignment.CENTER); CellStyle othersStyle = workbook.createCellStyle(); othersStyle.setAlignment(HorizontalAlignment.CENTER); othersStyle.setVerticalAlignment(VerticalAlignment.CENTER); // Create header row Row headerRow = sheet.createRow(0); headerRow.createCell(0).setCellValue("ID"); headerRow.createCell(1).setCellValue("TAG"); headerRow.createCell(2).setCellValue("DOMANDA"); headerRow.createCell(3).setCellValue("APRROVATA (SI/NO)"); headerRow.getCell(0).setCellStyle(othersStyle); headerRow.getCell(1).setCellStyle(othersStyle); headerRow.getCell(2).setCellStyle(othersStyle); headerRow.getCell(3).setCellStyle(othersStyle); int rownum = 1; for (Question question : questions) { // Create a row Row row = sheet.createRow(rownum++); // Create cells for id and question and set their values row.createCell(0).setCellValue(question.getId()); row.createCell(1).setCellValue(question.getTag()); row.createCell(2).setCellValue(question.getBody()); // Create empty cell for admin input row.createCell(3); // Set cell styles row.getCell(0).setCellStyle(othersStyle); row.getCell(1).setCellStyle(othersStyle); row.getCell(2).setCellStyle(questionStyle); row.getCell(3).setCellStyle(othersStyle); } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.setColumnWidth(2, 100 * 256); // Set questionStyle column width to 100 characters sheet.autoSizeColumn(3); return workbook; }
From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java
License:Apache License
protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) { CellStyle newStyle = 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(colorToIndex(wb, border.getColor())); }/*from w w w .j a v a 2 s. c om*/ border = style.getBorders(Border.LINE_TOP); if (border != null) { newStyle.setBorderTop(getBorder(border)); newStyle.setTopBorderColor(colorToIndex(wb, border.getColor())); } border = style.getBorders(Border.LINE_LEFT); if (border != null) { newStyle.setBorderLeft(getBorder(border)); newStyle.setLeftBorderColor(colorToIndex(wb, border.getColor())); } border = style.getBorders(Border.LINE_RIGHT); if (border != null) { newStyle.setBorderRight(getBorder(border)); newStyle.setRightBorderColor(colorToIndex(wb, 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)) { short colorIndex = colorToIndex(wb, style.getBackground()); newStyle.setFillForegroundColor(colorIndex); 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:ke.co.mspace.nonsmppmanager.service.SMSOutServiceImpl.java
private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();//from ww w . ja v a 2 s .c o m style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 11); monthFont.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(monthFont); style.setWrapText(true); styles.put("header", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula_2", style); return styles; }
From source file:ke.co.tawi.babblesms.server.utils.export.topups.AllTopupsExportUtil.java
License:Open Source License
/** * Cell styles used for formatting the sheets * * @param wb//from w ww . j av a 2 s . c o m * @return Map<String, {@link CellStyle}> */ public static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font 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); Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 48); titleFont.setColor(IndexedColors.DARK_BLUE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); return styles; }
From source file:kitt.admin.controller.UserController.java
@RequestMapping(value = "/downloadData") @Authority(role = AuthenticationRole.Service) @Authority(role = AuthenticationRole.TraderAssistant) @Authority(role = AuthenticationRole.LegalPersonnel) @Authority(role = AuthenticationRole.Admin) @Authority(role = AuthenticationRole.Operation) public void downloadUserData(String status, @RequestParam(value = "securephone", required = false, defaultValue = "") String securephone, @RequestParam(value = "clienttype", required = false, defaultValue = "0") int clienttype, @RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @RequestParam(value = "endDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException { List<Map<String, Object>> users = userMapper.userExport(status, Where.$like$(securephone), clienttype, startDate, endDate);//from w ww . j av a 2s .c o m String filename = status + "?"; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(filename); HSSFRow row = sheet.createRow(0); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); sheet.setVerticallyCenter(true); sheet.setHorizontallyCenter(true); sheet.setColumnWidth(0, 1200); sheet.setColumnWidth(1, 3600); sheet.setColumnWidth(2, 8000); sheet.setColumnWidth(3, 4500); sheet.setColumnWidth(4, 4500); String[] excelHeader = { "??", "", "??", "??", "" }; for (int i = 0; i < excelHeader.length; i++) { sheet.autoSizeColumn(i, true); HSSFCell cell = row.createCell(i); cell.setCellValue(excelHeader[i]); cell.setCellStyle(cellStyle); } for (int i = 0; i < users.size(); i++) { Map<String, Object> resultSet = users.get(i); sheet.autoSizeColumn(i, true); row = sheet.createRow(i + 1); row.setRowStyle(cellStyle); row.createCell(0).setCellValue(i + 1); row.createCell(1).setCellValue(String.valueOf(resultSet.get("tradername")).equals("null") ? "" : String.valueOf(resultSet.get("tradername"))); row.createCell(2).setCellValue(String.valueOf(resultSet.get("companyname"))); row.createCell(3).setCellValue(String.valueOf(resultSet.get("securephone"))); row.createCell(4).setCellValue(String.valueOf(resultSet.get("verifytime"))); } response.setCharacterEncoding("UTF-8"); response.setContentType("application/x-download"); filename += LocalDate.now() + ".xls"; if (request.getHeader("user-agent").toLowerCase().contains("firefox")) { filename = new String(filename.getBytes("UTF-8"), "ISO-8859-1"); } else { filename = URLEncoder.encode(filename, "UTF-8"); } response.addHeader("Content-Disposition", "attachment; filename=" + filename); OutputStream out = response.getOutputStream(); wb.write(out); out.close(); }
From source file:main.resources.FileExcel.java
public static void generaXlsx() throws IOException { //nombre del archivo de Excel String nombreArchivo = "quincena.xlsx"; String nombreHoja1 = "fecha";//nombre de la hoja1 Workbook libroTrabajo = new XSSFWorkbook(); Sheet hoja1 = libroTrabajo.createSheet(nombreHoja1); Row row = hoja1.createRow((short) 1); //row.setHeightInPoints(10); //alto de celda Cell cell = row.createCell((short) 1); Cell cell1 = row.createCell((short) 1); cell.setCellValue("Asistencia fecha xxxxxx"); CellStyle cellStyle = libroTrabajo.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); //cellStyle.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex()); //cellStyle.setFillPattern(CellStyle.BIG_SPOTS); cellStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex()); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex()); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setRightBorderColor(IndexedColors.AUTOMATIC.getIndex()); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex()); hoja1.addMergedRegion(new CellRangeAddress(1, // first row (0-based) primera fila 1, //lasto row (0-based) ultima fila 1, //first column (0-based) numero de columna inicial 5 //last column (0-based) numero de columna final ));/* w w w .j a va2s . c o m*/ cell.setCellStyle(cellStyle); cell1.setCellStyle(cellStyle); //escribir este libro en un OutputStream. try (FileOutputStream fileOut = new FileOutputStream(nombreArchivo)) { //escribir este libro en un OutputStream. libroTrabajo.write(fileOut); fileOut.flush(); } }
From source file:model.Reports.java
private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();//from w w w .j a v a 2s . c o m style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(titleFont); styles.put("title", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 11); monthFont.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(monthFont); style.setWrapText(true); styles.put("header", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setWrapText(true); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); styles.put("cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setDataFormat(wb.createDataFormat().getFormat("0.00")); styles.put("formula_2", style); return styles; }