List of usage examples for org.apache.poi.ss.usermodel CellStyle setWrapText
void setWrapText(boolean wrapped);
From source file:org.cerberus.service.export.ExportServiceFactory.java
License:Open Source License
private int createRow(String test, HashMap<String, List<TestCaseExecution>> executionsPerTestCase, Sheet sheet, int currentIndex, List<String> mapCountries) { int lastRow = currentIndex + executionsPerTestCase.size(); int current = currentIndex; TreeMap<String, List<TestCaseExecution>> sortedKeys = new TreeMap<String, List<TestCaseExecution>>( executionsPerTestCase);/*from w ww. jav a 2s . c o m*/ CellStyle wrapStyle = sheet.getColumnStyle(0); //Create new style wrapStyle.setWrapText(true); //Set wordwrap for (String testCaseKey : sortedKeys.keySet()) { List<String> browserEnvironment = new LinkedList<String>(); String application; String description; Row r = sheet.createRow(current); List<TestCaseExecution> executionList = executionsPerTestCase.get(testCaseKey); Cell testCell = r.createCell(0); testCell.setCellValue(test); testCell.setCellStyle(wrapStyle); r.createCell(1).setCellValue(testCaseKey); //gets the first object to retrieve the application - at least exists one test case execution if (executionList.isEmpty()) { application = "N/D"; description = "N/D"; } else { application = executionList.get(0).getApplication(); description = executionList.get(0).getTestCaseObj().getBehaviorOrValueExpected(); } //Sets the application and description r.createCell(2).setCellValue(application); r.createCell(3).setCellValue(description); int rowStartedTestCaseInfo = current; for (TestCaseExecution exec : executionList) { if (browserEnvironment.isEmpty()) { browserEnvironment.add(exec.getEnvironment() + "_" + exec.getBrowser()); r.createCell(4).setCellValue(exec.getEnvironment()); r.createCell(5).setCellValue(exec.getBrowser()); } else { int index = browserEnvironment.indexOf(exec.getEnvironment() + "_" + exec.getBrowser()); //Does not exist any information about browser and environment if (browserEnvironment.indexOf(exec.getEnvironment() + "_" + exec.getBrowser()) == -1) { //need to add another row with the same characteristics r = sheet.createRow(++current); r.createCell(0).setCellValue(test); r.createCell(1).setCellValue(testCaseKey); r.createCell(2).setCellValue(application); r.createCell(3).setCellValue(description); r.createCell(4).setCellValue(exec.getEnvironment()); r.createCell(5).setCellValue(exec.getBrowser()); browserEnvironment.add(exec.getEnvironment() + "_" + exec.getBrowser()); } else { //there is information about the browser and environment Row rowExisting = sheet.getRow(rowStartedTestCaseInfo + index); r = rowExisting; } } //TODO:FN tirar daqui estes valores int indexOfCountry = mapCountries.indexOf(exec.getCountry()) + 6; Cell executionResult = r.createCell(indexOfCountry); executionResult.setCellValue(exec.getControlStatus()); //Create hyperling CreationHelper createHelper = sheet.getWorkbook().getCreationHelper(); CellStyle hlinkstyle = sheet.getWorkbook().createCellStyle(); Font hlinkfont = sheet.getWorkbook().createFont(); hlinkfont.setUnderline(XSSFFont.U_SINGLE); hlinkfont.setColor(HSSFColor.BLUE.index); hlinkstyle.setFont(hlinkfont); Hyperlink link = (Hyperlink) createHelper.createHyperlink(Hyperlink.LINK_URL); link.setAddress("http://www.tutorialspoint.com/"); executionResult.setHyperlink((Hyperlink) link); executionResult.setCellStyle(hlinkstyle); } current++; } /*r.createCell(1).setCellValue(""); r.createCell(2).setCellValue(""); r.createCell(3).setCellValue(""); r.createCell(4).setCellValue(""); r.createCell(5).setCellValue(""); */ // for(TestCaseWithExecution exec : execution){ // // //r.createCell(2).setCellValue(exec.getDescription()); // //r.createCell(3).setCellValue(exec.getApplication()); // //r.createCell(4).setCellValue(exec.getEnvironment()); // //r.createCell(5).setCellValue(exec.getBrowser()); // int indexOfCountry = mapCountries.indexOf(exec.getCountry()) + 6; // r.createCell(indexOfCountry).setCellValue(exec.getControlStatus()); // //current++; // } //puts the test name in the first column /*r = sheet.getRow(currentIndex); r.getCell(0).setCellValue(test); */ /*CellRangeAddress range = new CellRangeAddress(currentIndex, lastRow, 0, 0); sheet.addMergedRegion(range);*/ return lastRow; }
From source file:org.dashbuilder.dataset.backend.DataSetBackendServicesImpl.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();/*from w w w . jav a 2 s .co m*/ style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 10); cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3))); styles.put("integer_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4))); styles.put("decimal_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); styles.put("text_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat() .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern))); styles.put("date_cell", style); return styles; }
From source file:org.dashbuilder.dataset.service.DataSetExportServicesImpl.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBold(true);//from w w w .ja v a 2s. co m style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 10); cellFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3))); styles.put("integer_number_cell", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4))); styles.put("decimal_number_cell", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); styles.put(TEXT_CELL, style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat() .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern))); styles.put("date_cell", style); return styles; }
From source file:org.devgateway.eudevfin.sheetexp.poi.PoiObjectCreator.java
License:Open Source License
private CellStyle createBodyStringCellStyle() { final CellStyle style = this.workbook.createCellStyle(); final Font font = this.workbook.createFont(); style.setFont(font);/*from w ww .j a va 2s . com*/ style.setWrapText(true); return style; }
From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetExporterImpl.java
License:Open Source License
private void addDefaultCellStyles(Workbook workbook, Map<String, CellStyle> keyStyleMap) { final CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setLocked(true);//from w w w . j a va 2 s. com keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED, cellStyle); final CellStyle cellStyle2 = workbook.createCellStyle(); cellStyle2.setLocked(true); cellStyle2.setWrapText(true); keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED_AND_WRAPPED, cellStyle2); final CellStyle cellStyle3 = workbook.createCellStyle(); cellStyle3.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$ keyStyleMap.put(EMFFormsCellStyleConstants.TEXT, cellStyle3); final CellStyle cellStyle4 = workbook.createCellStyle(); cellStyle4.setDataFormat((short) BuiltinFormats.getBuiltinFormat("m/d/yy")); //$NON-NLS-1$ keyStyleMap.put(EMFFormsCellStyleConstants.DATE, cellStyle4); }
From source file:org.jboss.dashboard.displayer.table.ExportTool.java
License:Apache License
private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();/*from w ww. j a v a2s . c o m*/ style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 10); cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3))); styles.put("integer_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4))); styles.put("decimal_number_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); styles.put("text_cell", style); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat() .getFormat(DateFormatConverter.convert(LocaleManager.currentLocale(), dateFormatPattern))); styles.put("date_cell", style); return styles; }
From source file:org.kurator.validation.actors.io.AnalysisSpreadsheetBuilder.java
License:Open Source License
private void initFirstSheet(long count) { StringBuffer stringBuffer = new StringBuffer(); try {/*w ww . j a v a2s .co m*/ BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(this.getClass().getResourceAsStream("/analysis.txt"))); String line = null; while ((line = bufferedReader.readLine()) != null) { stringBuffer.append(line).append("\n"); } stringBuffer.append("\nTotal record count: " + count + " occurrence records."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // TODO: Add list of sources to first page HSSFSheet sheet = wb.createSheet("Description"); sheet.setColumnWidth(0, 18000); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(0); CellStyle style = wb.createCellStyle(); style.setWrapText(true); cell.setCellStyle(style); cell.setCellValue(stringBuffer.toString()); }
From source file:org.netxilia.impexp.impl.PoiUtils.java
License:Open Source License
public static CellStyle netxiliaStyle2Poi(Styles nxStyle, Workbook workbook, CellStyle poiStyle) { if (nxStyle == null) { return poiStyle; }// w w w .j ava 2 s. co m poiStyle.setWrapText(nxStyle.contains(DefaultStyle.nowrap.getStyle())); // font short bold = nxStyle.contains(DefaultStyle.bold.getStyle()) ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL; byte underline = nxStyle.contains(DefaultStyle.underline.getStyle()) ? Font.U_SINGLE : Font.U_NONE; boolean italic = nxStyle.contains(DefaultStyle.italic.getStyle()); boolean strikeout = nxStyle.contains(DefaultStyle.strikeout.getStyle()); Font defaultFont = workbook.getFontAt(poiStyle.getFontIndex()); Font font = workbook.findFont(bold, defaultFont.getColor(), defaultFont.getFontHeight(), defaultFont.getFontName(), italic, strikeout, defaultFont.getTypeOffset(), underline); if (font == null) { font = workbook.createFont(); font.setBoldweight(bold); font.setItalic(italic); font.setUnderline(underline); font.setStrikeout(strikeout); } poiStyle.setFont(font); // borders if (nxStyle.contains(DefaultStyle.borderLeft.getStyle())) { poiStyle.setBorderLeft(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderRight.getStyle())) { poiStyle.setBorderRight(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderTop.getStyle())) { poiStyle.setBorderTop(CellStyle.BORDER_THIN); } if (nxStyle.contains(DefaultStyle.borderBottom.getStyle())) { poiStyle.setBorderBottom(CellStyle.BORDER_THIN); } // align if (nxStyle.contains(DefaultStyle.alignLeft.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_LEFT); } else if (nxStyle.contains(DefaultStyle.alignRight.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_RIGHT); } else if (nxStyle.contains(DefaultStyle.alignCenter.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_CENTER); } else if (nxStyle.contains(DefaultStyle.alignJustify.getStyle())) { poiStyle.setAlignment(CellStyle.ALIGN_JUSTIFY); } return poiStyle; }
From source file:org.phenotips.export.internal.Styler.java
License:Open Source License
public void style(DataCell dataCell, Cell cell, Workbook wBook) { Set<StyleOption> styles = dataCell.getStyles(); CellStyle cellStyle = wBook.createCellStyle(); /* For \n to work properly set to true */ cellStyle.setWrapText(true); if (this.defaultFont == null) { this.defaultFont = createDefaultFont(wBook); }/*from w w w .j a va 2 s. c o m*/ cellStyle.setFont(this.defaultFont); if (styles == null) { if (this.styleCache.containsKey(Collections.<StyleOption>emptySet())) { cell.setCellStyle(this.styleCache.get(Collections.<StyleOption>emptySet())); return; } cell.setCellStyle(cellStyle); this.styleCache.put(Collections.<StyleOption>emptySet(), cellStyle); return; } if (this.styleCache.containsKey(styles)) { cell.setCellStyle(this.styleCache.get(styles)); return; } /* Priority can be coded in by placing the if statement lower, for higher priority */ /** Font styles */ Font headerFont = null; if (styles.contains(StyleOption.HEADER)) { headerFont = wBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(headerFont); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.LARGE_HEADER)) { if (headerFont == null) { headerFont = wBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } headerFont.setFontHeightInPoints((short) 12); cellStyle.setFont(headerFont); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.YES)) { Font font = createDefaultFont(wBook); font.setColor(HSSFColor.GREEN.index); cellStyle.setFont(font); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.NO)) { Font font = createDefaultFont(wBook); font.setColor(HSSFColor.DARK_RED.index); font.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(font); cell.setCellStyle(cellStyle); } /** Border styles */ if (styles.contains(StyleOption.HEADER_BOTTOM)) { cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.SECTION_BORDER_LEFT)) { cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.SECTION_BORDER_RIGHT)) { cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.PATIENT_BORDER)) { cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.FEATURE_SEPARATOR)) { cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex()); cell.setCellStyle(cellStyle); } if (styles.contains(StyleOption.YES_NO_SEPARATOR)) { cellStyle.setBorderTop(CellStyle.BORDER_DASHED); cellStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); cell.setCellStyle(cellStyle); } /* Keep this as the last statement. */ this.styleCache.put(styles, cellStyle); }
From source file:org.projectforge.excel.CellFormat.java
License:Open Source License
/** * Please note: the data format should be set by the ContentProvider (for re-usage). * @param cellStyle// ww w.j ava 2 s . c o m */ public void copyToCellStyle(final CellStyle cellStyle) { if (alignment != null) { cellStyle.setAlignment(alignment); } if (font != null) { cellStyle.setFont(font); } if (fillForegroundColor != null) { cellStyle.setFillForegroundColor(fillForegroundColor); } if (wrapText != null) { cellStyle.setWrapText(wrapText); } }