List of usage examples for org.apache.poi.ss.usermodel CellStyle setWrapText
void setWrapText(boolean wrapped);
From source file:org.spdx.spdxspreadsheet.AbstractSheet.java
License:Apache License
public static CellStyle createLeftWrapStyle(Workbook wb) { CellStyle wrapStyle = wb.createCellStyle(); wrapStyle.setWrapText(true); wrapStyle.setAlignment(CellStyle.ALIGN_LEFT); return wrapStyle; }
From source file:org.spdx.spdxspreadsheet.AbstractSheet.java
License:Apache License
public static CellStyle createCenterStyle(Workbook wb) { CellStyle centerStyle = wb.createCellStyle(); centerStyle.setWrapText(false); centerStyle.setAlignment(CellStyle.ALIGN_CENTER); return centerStyle; }
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 a v a2 s .c om 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()); }/*from ww w . ja v a2 s .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.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 w w.j ava2 s. c o m*/ 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; }
From source file:output.ExcelM3Upgrad.java
/** * create a library of cell styles/*from w w w.ja va2s.c om*/ */ private static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); DataFormat df = wb.createDataFormat(); Font font1 = wb.createFont(); 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); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(false); styles.put("cell_centered", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(true); styles.put("cell_centered_locked", 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("d-mmm")); // styles.put("header_date", style); 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); style.setLocked(false); styles.put("cell_b_centered", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFont(font1); style.setLocked(true); styles.put("cell_b_centered_locked", style); style = createBorderedStyle(wb); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setFont(font1); style.setDataFormat(df.getFormat("d-mmm")); 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("d-mmm")); styles.put("cell_g", style); Font 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("d-mmm")); styles.put("cell_bg", style); Font 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("d-mmm")); 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:packtest.NewLinesInCells.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet();// w ww.j av a 2 s. c o m Row row = sheet.createRow(2); Cell cell = row.createCell(2); cell.setCellValue("Use \n with word wrap on to create a new line"); //to enable newlines you need set a cell styles with wrap=true CellStyle cs = wb.createCellStyle(); cs.setWrapText(true); cell.setCellStyle(cs); //increase row height to accomodate two lines of text row.setHeightInPoints((2 * sheet.getDefaultRowHeightInPoints())); //adjust column width to fit the content sheet.autoSizeColumn(2); FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:paysheets.PaySheet.java
private void addNonSerialListData(PaySheetEntry inEntry, HSSFRow row, HSSFCell cell) { cell = row.getCell(NONSERIAL_INDEX); CellStyle wrapNewLines = workbook.createCellStyle(); wrapNewLines.setWrapText(true); cell.setCellStyle(wrapNewLines);//w w w .j a v a2 s. c o m List<String> nonSerialList = inEntry.getNonSerializedList(); if (!nonSerialList.isEmpty()) { String nonSerialString = ""; // Using normal for loop to interate so we don't add a new line // at the end of the cell int listSize = nonSerialList.size(); for (int i = 0; i < listSize; i++) { if (i < listSize - 1) { // Add a new line on to the end of the cell nonSerialString = nonSerialString + nonSerialList.get(i) + "\n"; } else { nonSerialString = nonSerialString + nonSerialList.get(i); } } cell.setCellValue(nonSerialString); } }
From source file:paysheets.PaySheet.java
private void addSHSData(PaySheetEntry inEntry, HSSFRow row, HSSFCell cell) { cell = row.getCell(SHS_INDEX);// w ww . ja v a 2 s . c o m CellStyle wrapNewLines = workbook.createCellStyle(); wrapNewLines.setWrapText(true); cell.setCellStyle(wrapNewLines); List<String> shsList = inEntry.getSHSList(); if (!shsList.isEmpty()) { String shsString = ""; // Using normal for loop to interate so we don't add a new line // at the end of the cell int listSize = shsList.size(); for (int i = 0; i < listSize; i++) { if (i < listSize - 1) { // Add a new line on to the end of the cell shsString = shsString + shsList.get(i) + "\n"; } else { shsString = shsString + shsList.get(i); } } cell.setCellValue(shsString); } }
From source file:paysheets.PaySheet.java
private void addSerializedListData(PaySheetEntry inEntry, HSSFRow row, HSSFCell cell) { cell = row.getCell(SERIAL_INDEX);//from w ww . j av a 2s. co m // Set cell style to wrap lines CellStyle wrapNewLines = workbook.createCellStyle(); wrapNewLines.setWrapText(true); cell.setCellStyle(wrapNewLines); List<String> serialList = inEntry.getSerializedList(); if (!serialList.isEmpty()) { String serialString = ""; // Using normal for loop to interate so we don't add a new line // at the end of the cell int listSize = serialList.size(); for (int i = 0; i < listSize; i++) { if (i < listSize - 1) { serialString = serialString + serialList.get(i) + "\n"; } else { // Don't add newline on last element serialString = serialString + serialList.get(i); } } cell.setCellValue(serialString); } }