List of usage examples for org.apache.poi.ss.usermodel CellStyle setWrapText
void setWrapText(boolean wrapped);
From source file:it.eng.spagobi.engines.worksheet.exporter.WorkSheetXLSExporter.java
License:Mozilla Public License
public CellStyle buildMetadataNameCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_LEFT); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); cellStyle.setWrapText(true); Font font = sheet.getWorkbook().createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints(METADATA_NAME_FONT_SIZE); font.setFontName(FONT_NAME);/*from w w w .jav a 2 s . c o m*/ cellStyle.setFont(font); return cellStyle; }
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); Font font = sheet.getWorkbook().createFont(); font.setFontHeightInPoints(METADATA_VALUE_FONT_SIZE); font.setFontName(FONT_NAME);/*from w ww . j a va2s . c o m*/ 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); Font font = sheet.getWorkbook().createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontHeightInPoints(FILTERS_TITLE_FONT_SIZE); font.setFontName(FONT_NAME);/* w w w. j ava2 s. co m*/ 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); Font font = sheet.getWorkbook().createFont(); font.setFontHeightInPoints(FILTERS_VALUES_FONT_SIZE); font.setFontName(FONT_NAME);/*w w w. ja va 2 s . com*/ 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); questionStyle.setVerticalAlignment(VerticalAlignment.CENTER); CellStyle othersStyle = workbook.createCellStyle(); othersStyle.setAlignment(HorizontalAlignment.CENTER); othersStyle.setVerticalAlignment(VerticalAlignment.CENTER); // Create header row Row headerRow = sheet.createRow(0);//from ww w .j a v a 2s .c o m 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 va2s . c o m*/ 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 . j a v a 2 s . co 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: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. java 2s . c om 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:net.algem.planning.export.PlanningExportService.java
License:Open Source License
/** * * @param wb workbook//from w ww .j av a2s . co m * @return a map, each key-value composed of a style name and a cell style */ private Map<String, CellStyle> createStyles(HSSFWorkbook wb) { Map<String, CellStyle> styles = new HashMap<>(); HSSFFont nf = wb.createFont(); nf.setFontName("monospace"); HSSFFont bf = wb.createFont(); bf.setFontName("monospace"); bf.setBold(true); HSSFFont sf = wb.createFont(); sf.setFontHeightInPoints((short) 8); sf.setFontName("monospace"); CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); styles.put("header", style); //LEFT HEADER style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setFont(bf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_DOTTED); styles.put("hour", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(false); style.setFont(sf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_DOTTED); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-quarter", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(false); style.setFont(sf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_DASHED); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-half", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setFont(nf); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); styles.put("hour-last", style); return styles; }
From source file:net.algem.planning.export.PlanningExportService.java
License:Open Source License
/** * * @param wb workbook//from w w w.j av a 2 s . co m * @param schedule current schedule * @param cache styles cache * @return a cell style */ private CellStyle getCourseStyle(HSSFWorkbook wb, ScheduleObject schedule, Map<java.awt.Color, CellStyle> cache) { java.awt.Color color = colorizer.getScheduleColor(schedule); CellStyle cachedStyle = cache.get(color); if (cachedStyle != null) { return cachedStyle; } else { CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_TOP); style.setWrapText(true); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setFillPattern(CellStyle.SOLID_FOREGROUND); //the cell is painted with a pattern that consists of foreground and background pixels. //If you use SOLID_FOREGROUND, just the foreground pixel are visible. //This color is different from the color used to render text, which is set with the font style.setFillForegroundColor(getColorIndex(wb, color)); // Unused because font is applied as richTextString property /*java.awt.Color textColor = colorizer.getTextColor(schedule); HSSFFont font = wb.createFont(); font.setColor(getColorIndex(wb, textColor)); style.setFont(font); cache.put(color, style);*/ return style; } }