List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setWrapText
@Override public void setWrapText(boolean wrapped)
From source file:com.sec.ose.osi.report.standard.ISheetTemplate.java
License:Open Source License
/** * @param color//from ww w . j a va2s. co m * @param font * @return CellStyle */ protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) { XSSFCellStyle style = wb.createCellStyle(); style.setFillForegroundColor(color); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); // new line style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); if (font != null) style.setFont(font); return style; }
From source file:coverageqc.functions.MyExcelEditor.java
private static XSSFCellStyle getDefaultCellStyle(XSSFRow currentRow) { XSSFCellStyle cellStyle = currentRow.getSheet().getWorkbook().createCellStyle(); cellStyle.setWrapText(true); cellStyle.setBorderBottom(cellStyle.BORDER_THIN); cellStyle.setBorderLeft(cellStyle.BORDER_THIN); cellStyle.setBorderRight(cellStyle.BORDER_THIN); cellStyle.setBorderTop(cellStyle.BORDER_THIN); XSSFFont myFont = currentRow.getSheet().getWorkbook().createFont(); myFont.setFontHeight(9);//from w w w .j av a 2s.co m cellStyle.setFont(myFont); cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(new XSSFColor(Color.white)); return cellStyle; }
From source file:coverageqc.functions.MyExcelEditor.java
private static XSSFCellStyle getGrayCellStyle(XSSFRow currentRow) { XSSFCellStyle cellStyle = currentRow.getSheet().getWorkbook().createCellStyle(); cellStyle.setWrapText(true); cellStyle.setBorderBottom(cellStyle.BORDER_THIN); cellStyle.setBorderLeft(cellStyle.BORDER_THIN); cellStyle.setBorderRight(cellStyle.BORDER_THIN); cellStyle.setBorderTop(cellStyle.BORDER_THIN); XSSFFont myFont = currentRow.getSheet().getWorkbook().createFont(); myFont.setFontHeight(9);/*ww w. ja v a 2s . c o m*/ cellStyle.setFont(myFont); cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(new XSSFColor(Color.gray)); return cellStyle; }
From source file:coverageqc.functions.MyExcelGenerator.java
private XSSFCellStyle getDefaultCellStyle(XSSFRow currentRow, Color specifiedColor) { XSSFCellStyle cellStyle = currentRow.getSheet().getWorkbook().createCellStyle(); cellStyle.setWrapText(true); cellStyle.setBorderBottom(cellStyle.BORDER_THIN); cellStyle.setBorderLeft(cellStyle.BORDER_THIN); cellStyle.setBorderRight(cellStyle.BORDER_THIN); cellStyle.setBorderTop(cellStyle.BORDER_THIN); XSSFFont myFont = currentRow.getSheet().getWorkbook().createFont(); myFont.setFontHeight(9);//from w w w .java 2 s . co m cellStyle.setFont(myFont); cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(new XSSFColor(specifiedColor)); return cellStyle; }
From source file:edu.vt.vbi.patric.common.ExcelHelper.java
License:Apache License
/** * This method creates a map of Cellstyle objects for page building. Note: this method used for XSSF pages * // w w w .ja v a 2 s. co m * @return hashmap of styles */ private Map<String, XSSFCellStyle> createXStyles() { XSSFCellStyle style = (XSSFCellStyle) createBorderStyle(); // create style for cells in header row Font headerFont = xwb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(0, 52, 94))); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setWrapText(true); style.setFont(headerFont); xstyles.put("header", style); // create styles for alternating background color cells Font bodyFont = xwb.createFont(); bodyFont.setFontHeightInPoints((short) 8); style = (XSSFCellStyle) createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(230, 240, 248))); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(bodyFont); style.setWrapText(true); xstyles.put("bg2", style); style = (XSSFCellStyle) createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFont(bodyFont); xstyles.put("bg1", style); style = (XSSFCellStyle) createBorderStyle(); style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 193, 193))); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(bodyFont); style.setWrapText(true); xstyles.put("empty", style); return xstyles; }
From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java
License:Apache License
/** * [Flow #-3] ? ? : ?? ?(? ?, Border? ?, ? ?, )? *//* w ww. j a v a 2 s .co m*/ @Test public void testWriteExcelFileAttribute() throws Exception { try { LOGGER.debug("testWriteExcelFileAttribute start...."); short rowheight = 40 * 10; int columnwidth = 30; StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testWriteExcelFileAttribute.xlsx"); // delete file if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet1 = wb.createSheet("new sheet"); wb.createSheet("second sheet"); // ? ? sheet1.setDefaultRowHeight(rowheight); sheet1.setDefaultColumnWidth(columnwidth); Font f2 = wb.createFont(); XSSFCellStyle cs = wb.createCellStyle(); cs.setFont(f2); cs.setWrapText(true); // cs.setAlignment(CellStyle.ALIGN_RIGHT); cs.setFillPattern(CellStyle.DIAMONDS); // ? XSSFRow r1 = sheet1.createRow(0); r1.createCell(0); // ? ? cs.setFillForegroundColor(IndexedColors.BLUE.getIndex()); // cs.setFillBackgroundColor(IndexedColors.RED.getIndex()); // sheet1.setDefaultColumnStyle((short) 0, cs); Workbook tmp = excelService.createWorkbook(wb, sb.toString()); Sheet sheetTmp1 = tmp.getSheetAt(0); assertEquals(rowheight, sheetTmp1.getDefaultRowHeight()); assertEquals(columnwidth, sheetTmp1.getDefaultColumnWidth()); CellStyle cs1 = tmp.getCellStyleAt((short) (tmp.getNumCellStyles() - 1)); LOGGER.debug("getAlignment : {}", cs1.getAlignment()); assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment()); LOGGER.debug("getFillPattern : {}", cs1.getFillPattern()); assertEquals(XSSFCellStyle.DIAMONDS, cs1.getFillPattern()); LOGGER.debug("getFillForegroundColor : {}", cs1.getFillForegroundColor()); LOGGER.debug("getFillBackgroundColor : {}", cs1.getFillBackgroundColor()); LOGGER.debug( "XSSFWorkbook.getFillBackgroundColor(), XSSFColor().getIndexed() ? ? 0 ? ?"); assertEquals(IndexedColors.BLUE.getIndex(), cs1.getFillForegroundColor()); assertEquals(IndexedColors.RED.getIndex(), cs1.getFillBackgroundColor()); } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testWriteExcelFileAttribute end...."); } }
From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java
private static void CreaateStyleOfErrorList(XSSFWorkbook ErrorWorkbook, XSSFRow row, String cell_ref, String sheet_name, String error_desc, String error_level) { XSSFCellStyle StyleOfCell = ErrorWorkbook.createCellStyle(); StyleOfCell.setAlignment(XSSFCellStyle.ALIGN_CENTER); StyleOfCell.setFillPattern(FillPatternType.SOLID_FOREGROUND); if (error_level.equalsIgnoreCase("Warning")) { StyleOfCell.setFillForegroundColor(new XSSFColor(new java.awt.Color(155, 194, 230))); } else {/*from w w w. j a v a 2s . co m*/ StyleOfCell.setFillForegroundColor(new XSSFColor(new java.awt.Color(225, 171, 171))); } StyleOfCell.setBorderLeft((short) 1); StyleOfCell.setBorderRight((short) 1); StyleOfCell.setBorderTop((short) 1); StyleOfCell.setBorderBottom((short) 1); StyleOfCell.setWrapText(true); //create font XSSFFont fontOfCell = ErrorWorkbook.createFont(); fontOfCell.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); fontOfCell.setFontHeightInPoints((short) 10); fontOfCell.setFontName("Calibri"); fontOfCell.setColor(new XSSFColor(new java.awt.Color(0, 0, 0))); StyleOfCell.setFont(fontOfCell); Cell Rowcell_0 = row.createCell(0); Cell Rowcell_1 = row.createCell(1); Cell Rowcell_2 = row.createCell(2); Cell Rowcell_3 = row.createCell(3); Rowcell_0.setCellValue(cell_ref); Rowcell_1.setCellValue(sheet_name); Rowcell_2.setCellValue(error_desc); Rowcell_3.setCellValue(error_level); Rowcell_0.setCellStyle(StyleOfCell); Rowcell_1.setCellStyle(StyleOfCell); Rowcell_2.setCellStyle(StyleOfCell); Rowcell_3.setCellStyle(StyleOfCell); }
From source file:jdbreport.model.io.xls.poi.Excel2007Writer.java
License:Apache License
protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) { XSSFCellStyle newStyle = (XSSFCellStyle) 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(new XSSFColor(border.getColor())); }/*from www . java2s .c o m*/ border = style.getBorders(Border.LINE_TOP); if (border != null) { newStyle.setBorderTop(getBorder(border)); newStyle.setTopBorderColor(new XSSFColor(border.getColor())); } border = style.getBorders(Border.LINE_LEFT); if (border != null) { newStyle.setBorderLeft(getBorder(border)); newStyle.setLeftBorderColor(new XSSFColor(border.getColor())); } border = style.getBorders(Border.LINE_RIGHT); if (border != null) { newStyle.setBorderRight(getBorder(border)); newStyle.setRightBorderColor(new XSSFColor(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)) { newStyle.setFillForegroundColor(new XSSFColor(style.getBackground())); 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:localization.checkURL.java
public static void check(String desktopFile, String serverFile, String inputFolder) { try {//from w ww.j av a2 s . c o m String desktopFolder = desktopFile.substring(desktopFile.lastIndexOf("\\") + 1, desktopFile.length()); desktop = desktopFolder.substring(0, desktopFolder.indexOf("_")); String serverFolder = serverFile.substring(serverFile.lastIndexOf("\\") + 1, serverFile.length()); server = serverFolder.substring(0, serverFolder.indexOf("_")); pubList = new ArrayList<>(); searchFile(inputFolder); String parFolder = inputFolder.substring(0, inputFolder.lastIndexOf("\\")); HOName = parFolder.substring(parFolder.lastIndexOf("\\") + 1, parFolder.lastIndexOf("\\") + 5); lang = inputFolder.substring(inputFolder.lastIndexOf("\\") + 1, inputFolder.length()); outputFileName = parFolder.substring(parFolder.lastIndexOf("\\") + 1, parFolder.length()); outputFilePath = parFolder + "\\" + outputFileName + "_" + lang + ".xlsx"; valueArray = new String[pubList.size() + 1][6]; valueArray[0][0] = "Language"; valueArray[0][1] = "HO#"; valueArray[0][2] = "Publication Name"; valueArray[0][3] = "Type"; valueArray[0][4] = "Topic Name"; valueArray[0][5] = "URL"; for (int i = 0; i < pubList.size(); i++) { String fullPath = pubList.get(i); valueArray[i + 1][0] = lang.toUpperCase().trim(); valueArray[i + 1][1] = HOName.trim(); valueArray[i + 1][4] = fullPath.substring(fullPath.lastIndexOf("\\") + 1, fullPath.length()); if (fullPath.contains("\\topic\\")) { valueArray[i + 1][3] = "topic"; valueArray[i + 1][2] = fullPath .substring(fullPath.indexOf("\\P") + 4, fullPath.indexOf("\\topic\\")).trim(); } else if (fullPath.contains("\\map\\")) { valueArray[i + 1][3] = "map"; valueArray[i + 1][2] = fullPath .substring(fullPath.indexOf("\\P") + 4, fullPath.indexOf("\\map\\")).trim(); } } /* for(int i = 0; i < valueArray.length; i++){ for(int j = 0; j < valueArray[i].length; j++){ System.out.print(valueArray[i][j] + ","); } System.out.println(); }*/ File inputDesktopFile = new File(desktopFile); File inputServerFile = new File(serverFile); XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(inputDesktopFile)); XSSFSheet mysheet = workbook.getSheetAt(0); int desktopRowNum = mysheet.getLastRowNum(); XSSFWorkbook serverWorkbook = new XSSFWorkbook(new FileInputStream(inputServerFile)); XSSFSheet serverSheet = serverWorkbook.getSheetAt(0); int serverRowNum = serverSheet.getLastRowNum(); for (int k = 1; k < valueArray.length; k++) { //System.out.println(valueArray[k][3]); if (valueArray[k][3].equals("topic") && (!valueArray[k][4].trim().startsWith("cfg"))) { //System.out.println(k + " " +valueArray[k][3]); String source = valueArray[k][4].trim(); for (int i = 1; i < desktopRowNum + 1; i++) { Row desktopRow = mysheet.getRow(i); if (desktopRow != null) { String targetString = desktopRow.getCell(2).getStringCellValue().trim(); if (source.contains(targetString)) { String desktopURL = desktopRow.getCell(0).getStringCellValue().trim(); desktopURL = desktopURL.replace(".com/en\\", ".com/" + lang.toLowerCase() + "\\"); desktopURL = desktopURL.replace("http://" + desktop, "http://" + desktop + "uat"); valueArray[k][5] = desktopURL; } } } for (int j = 0; j < serverRowNum + 1; j++) { Row serverRow = serverSheet.getRow(j); if (serverRow != null) { String targetString1 = serverRow.getCell(2).getStringCellValue().trim(); if (source.contains(targetString1)) { String serverURL = serverRow.getCell(0).getStringCellValue().trim(); serverURL = serverURL.replace("/en\\", "/" + lang.toLowerCase() + "\\"); serverURL = serverURL.replace("http://" + server, "http://" + server + "uat"); // System.out.println(serverURL); if (valueArray[k][5] != null) { valueArray[k][5] = valueArray[k][5] + "\n" + serverURL; } else { valueArray[k][5] = serverURL; } } } } } XSSFWorkbook outputworkbook = new XSSFWorkbook(); XSSFSheet outputsheet = outputworkbook.createSheet("sheet1"); XSSFCellStyle outputstyle = outputworkbook.createCellStyle(); outputstyle.setWrapText(true); int outputRowNum = 0; int outputCellNum = 0; for (int i = 0; i < valueArray.length; i++) { Row outputRow = outputsheet.createRow(outputRowNum++); for (int j = 0; j < valueArray[1].length; j++) { Cell outputCell = outputRow.createCell(outputCellNum++); if (valueArray[i][j] != null) { outputCell.setCellValue(valueArray[i][j]); } else { outputCell.setCellValue("N/A"); } if (j == 5) { //outputsheet.autoSizeColumn(4); outputCell.setCellStyle(outputstyle); } } outputCellNum = 0; } outputsheet.autoSizeColumn(2); outputsheet.autoSizeColumn(4); outputsheet.autoSizeColumn(5); FileOutputStream out = new FileOutputStream(new File(outputFilePath)); outputworkbook.write(out); out.close(); } } catch (Exception e) { try { File file = new File(userDir + "\\log.txt"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(e.getMessage()); bw.write(e.getLocalizedMessage()); bw.close(); fw.close(); } catch (Exception e1) { e1.printStackTrace(); } e.printStackTrace(); } }
From source file:mvjce.Excel_operations.java
public static void fill_exceldata(XSSFWorkbook workbook, XSSFSheet spreadsheet) { try {//w w w. j a va 2 s. c o m Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Sample_data", "root", "root"); Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet detail = st.executeQuery( "select attendance.USN,Student_info.Name,attendance.sub1_class,attendance.sub2_class," + " attendance.sub3_class,attendance.sub4_class,attendance.sub5_class,attendance.sub6_class,attendance.sub7_class,attendance.sub8_class from attendance inner join " + " Student_info on attendance.USN = Student_info.USN where class='" + Writesheet.sec + "' and semester=" + Writesheet.sem_string + " ;"); int i = 1, j = 8; XSSFFont font = workbook.createFont(); font.setFontName("Arial"); font.setBold(true); XSSFCellStyle style = workbook.createCellStyle(); style.setAlignment(XSSFCellStyle.ALIGN_LEFT); style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); style.setFont(font); XSSFCell cell; while (detail.next()) { XSSFRow row = spreadsheet.createRow((short) j); row.setHeight((short) 900); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue(i); i++; cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue(detail.getString(1)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 2); cell.setCellValue(detail.getString(2)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 3); cell.setCellValue(detail.getString(3)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 5); cell.setCellValue(detail.getString(4)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 7); cell.setCellValue(detail.getString(5)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 9); cell.setCellValue(detail.getString(6)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 11); cell.setCellValue(detail.getString(7)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 13); cell.setCellValue(detail.getString(8)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 15); cell.setCellValue(detail.getString(9)); cell.setCellStyle(style); cell = (XSSFCell) row.createCell((short) 17); cell.setCellValue(detail.getString(10)); cell.setCellStyle(style); j++; } } catch (Exception e) { System.out.println(e); } }