List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle
CellStyle createCellStyle();
From source file:com.saba.CalendarDemo.java
License:Apache License
/** * CreateBorderedStyle : /*from ww w . ja v a 2s. co m*/ * left , right , bottom & top borderstyle setting for sheet * @param wb * @return */ private static CellStyle createBorderedStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); return style; }
From source file:com.sany.appbom.service.AppBomServiceImpl.java
License:Open Source License
public void setExcelData(Workbook workbook, boolean is2003, List<AppBom> beans) { try {//w w w . j a va 2 s. c o m Sheet sheet = null; CellStyle cellStyle = null; Font font = null; if (is2003) { sheet = (HSSFSheet) workbook.getSheetAt(0); } else { sheet = (XSSFSheet) workbook.getSheetAt(0); cellStyle = (XSSFCellStyle) workbook.createCellStyle(); } for (int i = 0; i < beans.size(); i++) { AppBom bom = beans.get(i); Row row = null; row = sheet.createRow(i + 2); row.setHeight((short) 450); row.createCell(0).setCellValue(bom.getBm()); row.createCell(1).setCellValue(bom.getApp_name_en()); row.createCell(2).setCellValue(bom.getApply_domain()); row.createCell(3).setCellValue(bom.getApp_name()); row.createCell(4).setCellValue(bom.getDescription()); row.createCell(5).setCellValue(getSoftLevel(bom.getSoft_level())); row.createCell(6).setCellValue(bom.getSupplier()); row.createCell(7).setCellValue(bom.getStart_year()); row.createCell(8).setCellValue(getState(bom.getState())); row.createCell(9).setCellValue(getRdType(bom.getRd_type())); row.createCell(10).setCellValue(bom.getVersion_no()); row.createCell(11).setCellValue(bom.getDomain_url()); row.createCell(12).setCellValue(bom.getStruct_mode()); row.createCell(13).setCellValue(bom.getSoft_language()); row.createCell(14).setCellValue(bom.getDevelop_tool()); row.createCell(15).setCellValue(bom.getDb_type()); row.createCell(16).setCellValue(bom.getDepartment_develop()); row.createCell(17).setCellValue(bom.getProduct_manager()); row.createCell(18).setCellValue(bom.getDepartment_maintain()); row.createCell(19).setCellValue(bom.getSys_manager()); row.createCell(20).setCellValue(getPlanType(bom.getPlan_type())); row.createCell(21).setCellValue(bom.getEvolve_strategy()); row.createCell(22).setCellValue(bom.getEvolve_plan()); row.createCell(23).setCellValue(bom.getEvolve_depart()); row.createCell(24).setCellValue(getManageScope(bom.getManage_scope())); row.createCell(25).setCellValue(bom.getMain_description()); } } catch (Exception e) { e.printStackTrace(); } finally { } }
From source file:com.seer.datacruncher.profiler.spring.ExporterController.java
License:Open Source License
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String type = CommonUtil.notNullValue(request.getParameter("exportaction")); String columns = CommonUtil.notNullValue(request.getParameter("exportcolumns")); String data = CommonUtil.notNullValue(request.getParameter("exportdata")); if (type.equals("csv")) { PrintWriter out = response.getWriter(); response.setContentType("application/csv"); response.setHeader("content-disposition", "attachment;filename=analysis_data.csv"); // set the file // name to // whatever // required.. out.println(columns.replace("&&&&&", ",")); for (String strData : data.split("@@@@@")) { out.println(strData.replace("&&&&&", ",")); }/*from ww w. j av a 2 s. c o m*/ out.flush(); out.close(); } else if (type.equals("xml")) { PrintWriter out = response.getWriter(); response.setContentType("text/xml"); response.setHeader("content-disposition", "attachment;filename=analysis_data.xml"); // set the file // name to // whatever // required.. try { StringBuffer xml = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xml.append("<table><header>"); String colArr[] = columns.split("&&&&&"); for (String col : colArr) { xml.append("<columnName>" + col + "</columnName>"); } xml.append("</header>"); for (String strData : data.split("@@@@@")) { xml.append("<row>"); int ind = 0; for (String val : strData.split("&&&&&")) { xml.append("<" + colArr[ind] + ">" + val + "</" + colArr[ind] + "/>"); ind++; } xml.append("</row>"); } xml.append("</table>"); out.print(xml.toString()); } catch (Exception e) { e.printStackTrace(); } out.flush(); out.close(); } else if (type.equals("excel")) { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=analysis_data.xls"); Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); String colArr[] = columns.split("&&&&&"); short ind = 0; CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); Row row = sheet.createRow(0); for (String col : colArr) { Cell cell = row.createCell(ind); cell.setCellValue(col); cell.setCellStyle(style); ind++; } ind = 1; for (String strData : data.split("@@@@@")) { Row valRow = sheet.createRow(ind); short cellInd = 0; for (String val : strData.split("&&&&&")) { valRow.createCell(cellInd).setCellValue(val); cellInd++; } ind++; } // Write the output to a file OutputStream resOout = response.getOutputStream(); wb.write(resOout); resOout.close(); } return null; }
From source file:com.shiyq.poi.HSSFTest.java
public static boolean createExcel(String excelName) { boolean created = false; Workbook wb = new HSSFWorkbook(); Font font = wb.createFont();//from w w w . j a v a 2 s . c o m font.setBold(true); CellStyle headStyle = wb.createCellStyle(); headStyle.setFont(font); Sheet sheet = wb.createSheet("20165???"); String[] head = { "??", "?", "??", "???", "????", "????", "?", "??", "", "", "??" }; String[] code = { "card_no", "card_type", "spread_time", "spread_emp_no", "spread_emp_name", "owner_name", "plate", "blance", "start_time", "end_time", "month_money" }; List<Map<String, Object>> list = setList(); setSheet(sheet, list, head, headStyle, code); // int startRow = 4; int endRow = 8; int startColumn = head.length + 4; int endColumn = head.length + 8; String describe = "1?" + (new Date().toString()) + "\n"; describe += "2.\n"; describe += "3.?2016-4-42016-5-4"; CellStyle descStyle = wb.createCellStyle(); descStyle.setAlignment(CellStyle.ALIGN_LEFT); descStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); setSheet(sheet, startRow, endRow, startColumn, endColumn, describe, descStyle); Sheet sheet1 = wb.createSheet("20166???"); setSheet(sheet1, list, head, headStyle, code); setSheet(sheet1, startRow, endRow, startColumn, endColumn, describe, descStyle); try { try (FileOutputStream fileOut = new FileOutputStream(excelName)) { wb.write(fileOut); created = true; } } catch (FileNotFoundException ex) { Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(HSSFTest.class.getName()).log(Level.SEVERE, null, ex); } return created; }
From source file:com.siemens.sw360.exporter.ExcelExporter.java
License:Open Source License
/** * Create style for data cells//w w w . j av a 2 s. c om */ private static CellStyle createCellStyte(Workbook workbook) { CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); return cellStyle; }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, String value, short halign) { Cell cell = row.createCell(column);/*from w w w .j a v a 2s . c om*/ cell.setCellValue(value); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, double value, short halign) { Cell cell = row.createCell(column);//from w ww. j ava 2 s .co m cell.setCellValue(value); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cell.setCellStyle(cellStyle); }
From source file:com.skt.adcas.lte.action.DownLinkByNMSAction.java
private static void createCell(Workbook wb, Row row, short column, short halign, short valign, String text) { Cell cell = row.createCell(column);/* w ww . j ava 2 s. c om*/ cell.setCellValue(text); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cell.setCellStyle(cellStyle); }
From source file:com.ssic.education.provider.controller.ProSupplierController.java
@RequestMapping(value = "/excel") @ResponseBody/* w ww. j a v a 2 s .c om*/ public ModelAndView exportExcel(SupplierDto supplierDto, HttpServletRequest request, HttpServletResponse response) { SessionInfo info = (SessionInfo) request.getSession().getAttribute(ConfigUtil.SESSIONINFONAME); if (info == null) { return null; } supplierDto.setReceiverId(info.getSupplierId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d"); Date date = new Date(); String filename = Tools.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; HSSFCell cell; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); Workbook workbook = new HSSFWorkbook(); sheet = (HSSFSheet) workbook.createSheet(""); try { List<String> titles = new ArrayList<String>(); titles.add("????"); titles.add("???"); // titles.add("????"); // titles.add("??????"); titles.add("????"); titles.add("???"); // titles.add("?"); // titles.add("???"); titles.add("?"); titles.add("?"); int len = titles.size(); HSSFCellStyle headerStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont headerFont = (HSSFFont) workbook.createFont(); // headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 11); headerStyle.setFont(headerFont); short width = 20, height = 25 * 20; sheet.setDefaultColumnWidth(width); HSSFRow sheetRow = sheet.createRow(0); for (int i = 0; i < len; i++) { // String title = titles.get(i); cell = sheetRow.createCell(i); cell.setCellStyle(headerStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); DataGrid dg = supplierService.findProSupplier(supplierDto, null); List<SupplierDto> expList = dg.getRows(); List<PageData> varList = new ArrayList<PageData>(); if (!CollectionUtils.isEmpty(expList)) { for (int i = 0; i < expList.size(); i++) { PageData vpd = new PageData(); vpd.put("var1", expList.get(i).getSupplierName()); vpd.put("var2", expList.get(i).getAddress()); // vpd.put("var3", expList.get(i).getFoodServiceCode()); // vpd.put("var4", expList.get(i).getFoodBusinessCode()); vpd.put("var3", expList.get(i).getFoodCirculationCode()); vpd.put("var4", expList.get(i).getFoodProduceCode()); // vpd.put("var7", expList.get(i).getBusinessLicense()); // vpd.put("var8", expList.get(i).getSupplierCode()); vpd.put("var5", expList.get(i).getCorporation()); vpd.put("var6", expList.get(i).getContactWay()); varList.add(vpd); } } for (int i = 0; i < varList.size(); i++) { HSSFRow row = sheet.createRow(i + 1); PageData vpd = varList.get(i); for (int j = 0; j < len; j++) { String varstr = vpd.getString("var" + (j + 1)) != null ? vpd.getString("var" + (j + 1)) : ""; cell = row.createCell(j); HSSFCellStyle cellStyle2 = (HSSFCellStyle) workbook.createCellStyle(); HSSFDataFormat format = (HSSFDataFormat) workbook.createDataFormat(); cellStyle2.setDataFormat(format.getFormat("@")); cell.setCellStyle(cellStyle2); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(varstr); } } OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (Exception e) { } return null; }
From source file:com.ssic.education.provider.controller.WaresController.java
@RequestMapping(value = "/excel") @ResponseBody// w ww. ja v a 2 s. co m public ModelAndView exportExcel(ProWaresDto proWaresDto, HttpServletRequest request, HttpServletResponse response) { SessionInfo info = (SessionInfo) request.getSession().getAttribute(ConfigUtil.SESSIONINFONAME); if (info == null) { return null; } proWaresDto.setSupplierId(info.getSupplierId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.M.d"); Date date = new Date(); String filename = Tools.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; HSSFCell cell; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); Workbook workbook = new HSSFWorkbook(); sheet = (HSSFSheet) workbook.createSheet(""); try { List<String> titles = new ArrayList<String>(); titles.add("??"); titles.add("???"); titles.add(""); titles.add("?"); titles.add("?"); // titles.add("??"); // titles.add("???"); // titles.add("??"); titles.add("?"); titles.add("???"); titles.add(""); int len = titles.size(); HSSFCellStyle headerStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont headerFont = (HSSFFont) workbook.createFont(); // headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 11); headerStyle.setFont(headerFont); short width = 20, height = 25 * 20; sheet.setDefaultColumnWidth(width); HSSFRow sheetRow = sheet.createRow(0); for (int i = 0; i < len; i++) { // String title = titles.get(i); cell = sheetRow.createCell(i); cell.setCellStyle(headerStyle); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = (HSSFCellStyle) workbook.createCellStyle(); // ? contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); List<ProWaresDto> expList = waresService.findAllWares(proWaresDto, null); List<PageData> varList = new ArrayList<PageData>(); if (!CollectionUtils.isEmpty(expList)) { for (int i = 0; i < expList.size(); i++) { PageData vpd = new PageData(); vpd.put("var1", expList.get(i).getWaresName()); vpd.put("var2", expList.get(i).getAmountUnit()); vpd.put("var3", expList.get(i).getSpec()); vpd.put("var4", ProductClass.getName(expList.get(i).getWaresType())); vpd.put("var5", expList.get(i).getManufacturer()); // vpd.put("var5", expList.get(i).getEnName()); // vpd.put("var6", expList.get(i).getBarCode()); // vpd.put("var7", expList.get(i).getCustomCode()); vpd.put("var6", expList.get(i).getShelfLife()); vpd.put("var7", expList.get(i).getUnit()); vpd.put("var8", expList.get(i).getPlace()); varList.add(vpd); } } for (int i = 0; i < varList.size(); i++) { HSSFRow row = sheet.createRow(i + 1); PageData vpd = varList.get(i); for (int j = 0; j < len; j++) { String varstr = vpd.getString("var" + (j + 1)) != null ? vpd.getString("var" + (j + 1)) : ""; cell = row.createCell(j); HSSFCellStyle cellStyle2 = (HSSFCellStyle) workbook.createCellStyle(); HSSFDataFormat format = (HSSFDataFormat) workbook.createDataFormat(); cellStyle2.setDataFormat(format.getFormat("@")); cell.setCellStyle(cellStyle2); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(varstr); } } OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (Exception e) { } return null; }