List of usage examples for org.apache.poi.ss.usermodel CellStyle setVerticalAlignment
void setVerticalAlignment(VerticalAlignment align);
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getTopicStyle(HSSFWorkbook wb) { CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(getBoldFont(wb, (short) 14)); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getHeaderStyle(HSSFWorkbook wb) { CellStyle style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); HSSFPalette palette = wb.getCustomPalette(); palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, ExportConstants.GRAY_10_RGB[0], ExportConstants.GRAY_10_RGB[1], ExportConstants.GRAY_10_RGB[2]); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(getBoldFont(wb, (short) 10)); style.setWrapText(true);//from w w w . j av a 2 s .c om return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getGroupStyle(HSSFWorkbook wb) { CellStyle style = createBorderedStyle(wb); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); HSSFPalette palette = wb.getCustomPalette(); palette.setColorAtIndex(HSSFColor.BROWN.index, ExportConstants.LIGHTORANGE_RGB[0], ExportConstants.LIGHTORANGE_RGB[1], ExportConstants.LIGHTORANGE_RGB[2]); style.setFillForegroundColor(HSSFColor.BROWN.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(getItalicFont(wb, (short) 10)); style.setWrapText(true);/*from ww w. j av a 2s .c om*/ return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getInfoStyle(Workbook wb, boolean bold) { Font font = getBoldFont(wb, (short) 11); if (!bold)//from w ww .j a va 2s. c o m font.setBoldweight(Font.BOLDWEIGHT_NORMAL); CellStyle style = wb.createCellStyle(); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(font); style.setIndention((short) 1); style.setWrapText(true); return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public CellStyle getBoderedBasicStyle(Workbook wb) { CellStyle style = createBorderedStyle(wb); style.setIndention((short) 1); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true);//from w ww . j a v a 2 s.c o m return style; }
From source file:org.sigmah.server.endpoint.export.sigmah.spreadsheet.ExcelUtils.java
License:Open Source License
public void createLinkCell(HSSFCell cell, String value, String target, boolean bordered) { cell.setCellValue(value);/*from w ww .ja v a 2 s . c o m*/ CellStyle style = wb.createCellStyle(); if (bordered) style = createBorderedStyle(wb); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); style.setFont(hlink_font); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setIndention((short) 1); style.setWrapText(true); HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT); link.setAddress("'" + normalizeAsLink(target) + "'!A1"); cell.setHyperlink(link); cell.setCellStyle(style); }
From source file:org.unitime.timetable.export.XLSPrinter.java
License:Apache License
public XLSPrinter(OutputStream output, boolean checkLast) { iOutput = output;//from w w w.j av a 2 s . co m iCheckLast = checkLast; iWorkbook = new HSSFWorkbook(); iSheet = iWorkbook.createSheet(); iSheet.setDisplayGridlines(false); iSheet.setPrintGridlines(false); iSheet.setFitToPage(true); iSheet.setHorizontallyCenter(true); PrintSetup printSetup = iSheet.getPrintSetup(); printSetup.setLandscape(true); iSheet.setAutobreaks(true); printSetup.setFitHeight((short) 1); printSetup.setFitWidth((short) 1); iStyles = new HashMap<String, CellStyle>(); CellStyle style; style = iWorkbook.createCellStyle(); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFont(getFont(true, false, false, Color.BLACK)); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setWrapText(true); iStyles.put("header", style); style = iWorkbook.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFont(getFont(false, false, false, Color.BLACK)); style.setWrapText(true); iStyles.put("plain", style); style = iWorkbook.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFont(getFont(false, false, false, Color.BLACK)); iStyles.put("number", style); }
From source file:org.unitime.timetable.export.XLSPrinter.java
License:Apache License
protected CellStyle getStyle(A f, boolean dashed, String format) { String styleId = (dashed ? "D" : "") + (f.has(F.BOLD) ? "b" : "") + (f.has(F.ITALIC) ? "i" : "") + (f.has(F.UNDERLINE) ? "u" : "") + (f.has(F.RIGHT) ? "R" : f.has(F.CENTER) ? "C" : "L") + (f.hasColor() ? "#" + Integer.toHexString(f.getColor().getRGB()) : "") + (format == null ? "" : "|" + format); CellStyle style = iStyles.get(styleId); if (style == null) { style = iWorkbook.createCellStyle(); if (dashed) { style.setBorderTop(BorderStyle.DASHED); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); }/* w ww . ja v a2s.c o m*/ style.setAlignment(f.has(F.RIGHT) ? HorizontalAlignment.RIGHT : f.has(F.CENTER) ? HorizontalAlignment.CENTER : HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFont(getFont(f.has(F.BOLD), f.has(F.ITALIC), f.has(F.UNDERLINE), f.getColor())); style.setWrapText(true); if (format != null) style.setDataFormat(iWorkbook.createDataFormat().getFormat(format)); iStyles.put(styleId, style); } return style; }
From source file:org.xianairlines.action.staffs.StaffsList.java
public void exportStaffsByColumNames() throws UnsupportedEncodingException { ServletOutputStream os = null;/*www.j av a2 s . c om*/ try { final HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); os = response.getOutputStream(); response.setContentType("application/x-download"); final String newFileName = encodeFileName("??.xls"); response.addHeader("Content-disposition", "attachment;filename=" + newFileName + ";charset=UTF-8"); Workbook wb = new HSSFWorkbook(); Sheet sheet1 = wb.createSheet("sheet1"); Row row = null; Cell cell = null; CellStyle cellStyle = wb.createCellStyle(); // ? cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); // ? cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // Font Font font = wb.createFont(); font.setFontName(""); font.setColor(HSSFColor.BLUE.index); font.setItalic(true); font.setFontHeight((short) 300); row = sheet1.createRow(0); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); for (int i = 0; i < columNames.length; i++) { sheet1.setColumnWidth(i, (short) 6000); String[] colums = columNames[i].split(","); cell = row.createCell(i); cell.setCellStyle(cellStyle); cell.setCellValue(colums[1]); } List<Staffs> list = this.getResultList(); for (int i = 1; i <= list.size(); i = i + 1) { row = sheet1.createRow(i); row.setHeightInPoints(20); for (int j = 0; j < columNames.length; j++) { String[] colums = columNames[j].split(","); cell = row.createCell(j); cell.setCellStyle(cellStyle); Object value = this.getStaffsFieldValue((Staffs) list.get(i - 1), colums[0]); if (value == null) { cell.setCellValue(""); } else if (value instanceof java.util.Date) { String cellValue = dateFormat.format((java.util.Date) value); cell.setCellValue(cellValue); } else { cell.setCellValue(value.toString()); } } } wb.write(os); os.flush(); } catch (Exception e) { } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } facesContext.responseComplete(); } }
From source file:org.zafritech.zidingorms.io.excel.ExcelFunctions.java
private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CreationHelper creationHelper = wb.getCreationHelper(); CellStyle style; // Header Font Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 12); headerFont.setBold(true);/*w ww .j a v a2 s .c om*/ headerFont.setColor(IndexedColors.WHITE.getIndex()); // Header Left Aligned Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(headerFont); style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); styles.put("HeaderLeftAlign", style); // Header Center Aligned Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(headerFont); style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); styles.put("HeaderCenterAlign", style); // Body Left Aligned Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); styles.put("BodyLeftAlign", style); // Body Center Aligned Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.TOP); styles.put("BodyCenterAlign", style); // Body Left Aligned WrapText Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setWrapText(true); styles.put("BodyLeftAlignWrapText", style); // Body Left Aligned Date Format Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.TOP); style.setDataFormat(creationHelper.createDataFormat().getFormat("yyyy-MM-dd HH:mm:ss")); styles.put("BodyLeftAlignDate", style); // Body Center Aligned Date Format Style style = createBorderedStyle(wb); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.TOP); style.setDataFormat(creationHelper.createDataFormat().getFormat("yyyy-MM-dd HH:mm:ss")); styles.put("BodyCenterAlignDate", style); return styles; }