List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD
short BOLDWEIGHT_BOLD
To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.
Click Source Link
From source file:com.app.ExcelView.java
License:Open Source License
/** * ?Excel//w ww .j av a2 s .c o m * * @param model * ? * @param workbook * workbook * @param request * request * @param response * response */ public void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.notEmpty(properties); HSSFSheet sheet; if (StringUtils.isNotEmpty(sheetName)) { sheet = workbook.createSheet(sheetName); } else { sheet = workbook.createSheet(); } int rowNumber = 0; if (titles != null && titles.length > 0) { HSSFRow header = sheet.createRow(rowNumber); header.setHeight((short) 400); for (int i = 0; i < properties.length; i++) { HSSFCell cell = header.createCell(i); HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setFontHeightInPoints((short) 11); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(font); cell.setCellStyle(cellStyle); if (i == 0) { HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFComment comment = patriarch .createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 4, 4)); comment.setString(new HSSFRichTextString("P" + "o" + "w" + "e" + "r" + "e" + "d" + " " + "B" + "y" + " " + "A" + "P" + "P" + "T" + "E" + "A" + "M")); cell.setCellComment(comment); } if (titles.length > i && titles[i] != null) { cell.setCellValue(titles[i]); } else { cell.setCellValue(properties[i]); } if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } rowNumber++; } if (data != null) { for (Object item : data) { HSSFRow row = sheet.createRow(rowNumber); for (int i = 0; i < properties.length; i++) { HSSFCell cell = row.createCell(i); if (converters != null && converters.length > i && converters[i] != null) { Class<?> clazz = PropertyUtils.getPropertyType(item, properties[i]); ConvertUtils.register(converters[i], clazz); cell.setCellValue(BeanUtils.getProperty(item, properties[i])); ConvertUtils.deregister(clazz); if (clazz.equals(Date.class)) { DateConverter dateConverter = new DateConverter(); dateConverter.setPattern(DEFAULT_DATE_PATTERN); ConvertUtils.register(dateConverter, Date.class); } } else { cell.setCellValue(BeanUtils.getProperty(item, properties[i])); } if (rowNumber == 0 || rowNumber == 1) { if (widths != null && widths.length > i && widths[i] != null) { sheet.setColumnWidth(i, widths[i]); } else { sheet.autoSizeColumn(i); } } } rowNumber++; } } if (contents != null && contents.length > 0) { rowNumber++; for (String content : contents) { HSSFRow row = sheet.createRow(rowNumber); HSSFCell cell = row.createCell(0); HSSFCellStyle cellStyle = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.GREY_50_PERCENT.index); cellStyle.setFont(font); cell.setCellStyle(cellStyle); cell.setCellValue(content); rowNumber++; } } response.setContentType("application/force-download"); if (StringUtils.isNotEmpty(filename)) { response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); } else { response.setHeader("Content-disposition", "attachment"); } }
From source file:com.automaster.autoview.server.servlet.ExcelServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /*response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=filename.xls"); HSSFWorkbook workbook = new HSSFWorkbook(); // .../*w w w . ja v a 2 s .co m*/ // Now populate workbook the usual way. // ... OutputStream arqSaida = response.getOutputStream(); workbook.write(arqSaida); // Write workbook to response. arqSaida.flush(); arqSaida.close();*/ //getServletContext().getRealPath("/") String tempoDecorrido = " 0"; String url = getServletContext().getRealPath("/"); String placa = request.getParameter("placa"); //TimeZone timeZoneMundial = TimeZone.getTimeZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); Timestamp dataInicio = new Timestamp(Long.parseLong(request.getParameter("dataInicio"))); Timestamp dataFim = new Timestamp(Long.parseLong(request.getParameter("dataFim"))); //String timeZoneInterface = request.getParameter("timeZone"); /*String timeZone = "Z"; if(timeZoneInterface.equalsIgnoreCase("0")){ timeZone = "Z"; } else { timeZone = String.valueOf((-1) * (Integer.parseInt(timeZoneInterface) / 60)); } */ TimeZone timeZonePadrao = TimeZone.getTimeZone(ZoneId.of("-3")); System.out.println("Time zone Cliente : " + timeZonePadrao); //System.out.println("timeZoneInterface: "+timeZoneInterface); //System.out.println("timeZone: "+timeZone); //String ign = request.getParameter("ign"); ZzzPosPlacaVeiculoDAO zzzPosPlacaVeiculoDAO = new ZzzPosPlacaVeiculoDAO(); ArrayList<TreeMap<String, String>> posicoes = zzzPosPlacaVeiculoDAO.buscarPosicoesPorIntervaloData(placa, dataInicio, dataFim); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=Historico-" + placa + ".xlsx"); Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("Histrico - " + placa); int pictureIdx; try ( //add picture data to this workbook. InputStream is = new FileInputStream(url + "/imagens/logo.jpg")) { byte[] bytes = IOUtils.toByteArray(is); pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); } CreationHelper helper = wb.getCreationHelper(); // Create the drawing patriarch. This is the top level container for all shapes. Drawing drawing = sheet.createDrawingPatriarch(); //add a picture shape ClientAnchor anchor = helper.createClientAnchor(); //set top-left corner of the picture, //subsequent call of Picture#resize() will operate relative to it anchor.setCol1(1); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); //auto-size picture relative to its top-left corner pict.resize(3, 3); //pict.resize(); //sheet.setColumnWidth(0, 200); Font fonte = wb.createFont(); fonte.setFontHeightInPoints((short) 24); fonte.setFontName("Arial"); fonte.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fonte.setItalic(true); CellStyle estiloTitulo = wb.createCellStyle(); estiloTitulo.setAlignment(HSSFCellStyle.ALIGN_CENTER); estiloTitulo.setFont(fonte); Font fonteCabecalho = wb.createFont(); fonteCabecalho.setFontHeightInPoints((short) 14); fonteCabecalho.setFontName("Arial"); fonteCabecalho.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //fonteCabecalho.setItalic(true); CellStyle estiloCabecalho = wb.createCellStyle(); estiloCabecalho.setAlignment(HSSFCellStyle.ALIGN_CENTER); estiloCabecalho.setFont(fonteCabecalho); Font fonteTituloTabela = wb.createFont(); //fonteTituloTabela.setFontHeightInPoints((short) 14); fonteTituloTabela.setFontName("Arial"); fonteTituloTabela.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); CellStyle estilo = wb.createCellStyle(); estilo.setAlignment(HSSFCellStyle.ALIGN_CENTER); estilo.setFont(fonteTituloTabela); CellStyle estiloCorpo = wb.createCellStyle(); estiloCorpo.setAlignment(HSSFCellStyle.ALIGN_CENTER); //estiloCorpo.setFillBackgroundColor(HSSFColor.WHITE.index); //estiloCorpo.setFont(fonteTituloTabela); XSSFRow linha6 = (XSSFRow) sheet.createRow(6); XSSFCell cell046 = linha6.createCell(3); cell046.setCellValue("Relatrio de Posies"); cell046.setCellStyle(estiloTitulo); //sheet.addMergedRegion(new CellRangeAddress(6, 6, 0, 3)); XSSFRow linha7 = (XSSFRow) sheet.createRow(7); XSSFCell cell047 = linha7.createCell(3); cell047.setCellValue("Veculo : " + placa); cell047.setCellStyle(estiloCabecalho); //sheet.addMergedRegion(new CellRangeAddress(7, 7, 0, 3)); XSSFRow linha8 = (XSSFRow) sheet.createRow(8); XSSFCell cell038 = linha8.createCell(3); //TimeZone.setDefault(timeZoneMundial); //Date dataHoraInicio0 = new Date(Long.parseLong(request.getParameter("dataInicio"))); //TimeZone.setDefault(timeZoneCliente); //Date dataHoraInicio = new Date(dataHoraInicio0.getTime()); SimpleDateFormat dataFormatadaCabecalho = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); dataFormatadaCabecalho.setTimeZone(timeZonePadrao); cell038.setCellValue("Perodo: De: " + dataFormatadaCabecalho.format(dataInicio) + " at: " + dataFormatadaCabecalho.format(dataFim)); cell038.setCellStyle(estiloCabecalho); //sheet.addMergedRegion(new CellRangeAddress(8, 8, 0, 3)); sheet.setColumnWidth(0, 5000); sheet.setColumnWidth(1, 3000); sheet.setColumnWidth(2, 3500); //sheet.setColumnWidth(3, 4000); sheet.setColumnWidth(3, 30000); //sheet.setColumnWidth(4, 4000); //sheet.setColumnWidth(4, 30000); sheet.setColumnWidth(5, 3000); sheet.setColumnWidth(6, 3000); sheet.setColumnWidth(7, 3000); sheet.setColumnWidth(8, 3000); sheet.setColumnWidth(9, 3000); //sheet.setColumnWidth(10, 20000); sheet.setColumnWidth(11, 3000); XSSFRow linha9 = (XSSFRow) sheet.createRow(10); XSSFCell cell0 = linha9.createCell(0); cell0.setCellValue("Data e hora"); cell0.setCellStyle(estilo); XSSFCell cell1 = linha9.createCell(1); cell1.setCellValue("Velocidade"); cell1.setCellStyle(estilo); XSSFCell cell2 = linha9.createCell(2); cell2.setCellValue("Ignio"); cell2.setCellStyle(estilo); //XSSFCell cell3 = linha9.createCell(3); //cell3.setCellValue("Latitude"); //cell3.setCellStyle(estilo); //XSSFCell cell4 = linha9.createCell(4); //cell4.setCellValue("Longitude"); //cell4.setCellStyle(estilo); //XSSFCell cell5 = linha9.createCell(5); //cell5.setCellValue("Satlite"); //cell5.setCellStyle(estilo); //XSSFCell cell6 = linha9.createCell(6); //cell6.setCellValue("GPS"); //cell6.setCellStyle(estilo); //XSSFCell cell7 = linha9.createCell(7); //cell7.setCellValue("Entrada"); //cell7.setCellStyle(estilo); //XSSFCell cell8 = linha9.createCell(8); //cell8.setCellValue("Sada"); //cell8.setCellStyle(estilo); //XSSFCell cell9 = linha9.createCell(9); //cell9.setCellValue("Evento"); //cell9.setCellStyle(estilo); XSSFCell cell10 = linha9.createCell(3); cell10.setCellValue("Endereo"); cell10.setCellStyle(estilo); //sheet.addMergedRegion(new CellRangeAddress(11, 11, 4, 8)); //XSSFCell cell11 = linha9.createCell(11); //cell11.setCellValue("Direo"); //cell11.setCellStyle(estilo); int linha = 0; int j = 11; double latAnt = 0; double lonAnt = 0; double latAtual = 0; double lonAtual = 0; double distancia = 0; double distanciaTotal = 0; for (int i = 0; i < posicoes.size(); i++) { XSSFRow row = (XSSFRow) sheet.createRow(j); if (i == 0) { distancia = 0; //System.out.println("linha 00 - EXCEL"); } else { //System.out.println("linha 01 - EXCEL"); latAnt = Double.parseDouble(posicoes.get(i - 1).get("lat")); lonAnt = Double.parseDouble(posicoes.get(i - 1).get("lon")); latAtual = Double.parseDouble(posicoes.get(i).get("lat")); lonAtual = Double.parseDouble(posicoes.get(i).get("lon")); //System.out.println("linha 02 - PDF"); if (latAnt == latAtual && lonAnt == lonAtual) { distancia = 0; } else { distancia = caculaDistanciaEntreDoisPontos(latAnt, lonAnt, latAtual, lonAtual); //System.out.println("linha 03 - PDF"); } } distanciaTotal = distanciaTotal + distancia; /*if(i==0) { latAnt = Double.parseDouble(posicoes.get(i).get("lat")); lonAnt = Double.parseDouble(posicoes.get(i).get("lon")); } else{ latAnt = Double.parseDouble(posicoes.get(i-1).get("lat")); lonAnt = Double.parseDouble(posicoes.get(i-1).get("lon")); } double latAtual = Double.parseDouble(posicoes.get(i).get("lat")); double lonAtual = Double.parseDouble(posicoes.get(i).get("lon")); double distancia = caculaDistanciaEntreDoisPontos(latAnt, lonAnt, latAtual, lonAtual); distanciaTotal = distanciaTotal + distancia;*/ for (int col = 0; col < posicoes.get(linha).size(); col++) { XSSFCell cell = row.createCell(col); cell.setCellStyle(estiloCorpo); switch (col) { case 0: Date dataHora0 = new Date(Long.parseLong(posicoes.get(i).get("dataHora"))); Date dataHora = new Date(dataHora0.getTime()); SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); dataFormatada.setTimeZone(timeZonePadrao); cell.setCellValue(dataFormatada.format(dataHora)); break; case 1: cell.setCellValue(posicoes.get(linha).get("vel")); break; case 2: cell.setCellValue( posicoes.get(linha).get("ign").equalsIgnoreCase("True") ? "Ligada" : "Desligada"); break; /*case 3: cell.setCellValue(posicoes.get(linha).get("lat")); break; case 4: cell.setCellValue(posicoes.get(linha).get("lon")); break; case 5: cell.setCellValue(posicoes.get(linha).get("sat")); break; case 6: cell.setCellValue(posicoes.get(linha).get("gps")); break; case 7: cell.setCellValue(posicoes.get(linha).get("entrada")); break; case 8: cell.setCellValue(posicoes.get(linha).get("saida")); break; case 9: cell.setCellValue(posicoes.get(linha).get("evento")); break;*/ case 3: cell.setCellValue(posicoes.get(linha).get("endereco") == null ? "Sem endereo" : posicoes.get(linha).get("endereco")); break; /*case 11: cell.setCellValue(posicoes.get(linha).get("direcao")); break;*/ } } j = j + 1; linha = linha + 1; } tempoDecorrido = calculaDatas(Long.parseLong(posicoes.get(0).get("dataHora")), Long.parseLong(posicoes.get(posicoes.size() - 1).get("dataHora"))); int index = 0; String kms = "0"; String m = ""; double metros = 0; if (distanciaTotal > 0) { BigDecimal decimalFormatado = new BigDecimal(distanciaTotal).setScale(2, RoundingMode.HALF_EVEN); index = String.valueOf(decimalFormatado).indexOf("."); kms = String.valueOf(decimalFormatado).substring(0, index); m = "0" + (String.valueOf(decimalFormatado).substring(index)); metros = Double.parseDouble(m) * 1000; } //String formatted = NumberFormat.getFormat("000.00").format(metros); //System.out.println("Percorridos aproximadamente : "+kms+" KM e "+metros+" metros"); XSSFRow linhaX = (XSSFRow) sheet.createRow(linha + 12); XSSFCell cellX = linhaX.createCell(0); sheet.addMergedRegion(new CellRangeAddress(linha + 12, linha + 12, 0, 3)); cellX.setCellStyle(estilo); cellX.setCellValue( "Percorridos: " + kms + " KM e " + String.valueOf(metros) + " metros. Tempo: " + tempoDecorrido); ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); wb.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); OutputStream outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush(); }
From source file:com.bdx.rainbow.spsy.service.impl.EnterpriseLicenseServiceImpl.java
/** * * @param title ??/* ww w. j av a 2s .c o m*/ * @param headers ?? * @param resultLists ? * @param pattern ?,"yyyy-MM-dd" */ private HSSFWorkbook exportExcel(String title, String[] headers, List<DubboEnterpriseLicense> resultLists, String pattern) { if (resultLists == null) { return null; } if (pattern == null && StringUtils.isEmpty(pattern)) { pattern = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(pattern); // HSSFWorkbook workbook = new HSSFWorkbook(); // ? HSSFSheet sheet = workbook.createSheet(title); // 15 sheet.setDefaultColumnWidth((short) 15); // ?? HSSFCellStyle style = workbook.createCellStyle(); // ? style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // ?? style.setFont(font); // ??? HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // ?? HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // ?? style2.setFont(font2); // HSSFRow row = sheet.createRow(0); for (short i = 0; i < headers.length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style); HSSFRichTextString text = new HSSFRichTextString(headers[i]); cell.setCellValue(text); } // ????? for (int i = 0; i < resultLists.size(); i++) { row = sheet.createRow(i + 1); int index = 0; // HSSFCell cell = row.createCell(j); // row.createCell(index++).setCellStyle(style2); DubboEnterpriseLicense info = resultLists.get(i); row.createCell(index++).setCellValue(info.getEnterpriseName()); row.createCell(index++).setCellValue(info.getOrganizationCode()); row.createCell(index++).setCellValue(info.getLegalPerson()); row.createCell(index++).setCellValue(info.getLegalPersonPhone()); String type = info.getLicenseType(); if ("001".equals(type)) { row.createCell(index++).setCellValue(""); } else if ("002".equals(type)) { row.createCell(index++).setCellValue("??"); } else if ("003".equals(type)) { row.createCell(index++).setCellValue(""); } else if ("004".equals(type)) { row.createCell(index++).setCellValue("?"); } else { row.createCell(index++).setCellValue(type); } row.createCell(index++).setCellValue(info.getLicenseCode()); if (info.getLicenseTime() != null) { row.createCell(index++).setCellValue(sdf.format(info.getLicenseTime())); } else { row.createCell(index++).setCellValue(""); } if (info.getInvalidDate() != null) { Long time = (System.currentTimeMillis() - info.getInvalidDate().getTime()) / (1000 * 3600 * 24); if (time > 0) { row.createCell(index++).setCellValue(""); } else if (time <= 0) { row.createCell(index++).setCellValue(""); } else { row.createCell(index++).setCellValue("1"); } } else { row.createCell(index++).setCellValue(""); } } return workbook; }
From source file:com.beginner.core.utils.ObjectExcelView.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* www . ja va2 s . c om*/ protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { Date date = new Date(); String filename = DateUtil.date2Str(date, "yyyyMMddHHmmss"); HSSFSheet sheet; HSSFCell cell; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + filename + ".xls"); sheet = workbook.createSheet("sheet1"); List<String> titles = (List<String>) model.get("titles"); int len = titles.size(); HSSFCellStyle headerStyle = workbook.createCellStyle(); //? headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont headerFont = workbook.createFont(); // headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 11); headerStyle.setFont(headerFont); short width = 20, height = 25 * 20; sheet.setDefaultColumnWidth(width); for (int i = 0; i < len; i++) { // String title = titles.get(i); cell = getCell(sheet, 0, i); cell.setCellStyle(headerStyle); setText(cell, title); } sheet.getRow(0).setHeight(height); HSSFCellStyle contentStyle = workbook.createCellStyle(); //? contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); List<PageData> varList = (List<PageData>) model.get("varList"); int varCount = varList.size(); for (int i = 0; i < varCount; i++) { 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 = getCell(sheet, i + 1, j); cell.setCellStyle(contentStyle); setText(cell, varstr); } } }
From source file:com.brick.customer.util.CustomerInfoExcel.java
@SuppressWarnings("unchecked") public HSSFWorkbook createReport(Map<String, Object> params, Context context) throws Exception { ExcelFileWriter efw = new ExcelFileWriter(); HSSFSheet sheet = efw.createSheet(context.contextMap.get("sheetName") == null ? "summary" : (String) context.contextMap.get("sheetName")); List<HashMap<String, Object>> list = (List<HashMap<String, Object>>) params.get("cusInfo"); sheet.setColumnWidth(0, 5000);/*from w w w. jav a 2s . c om*/ sheet.setColumnWidth(1, 3000); sheet.setColumnWidth(2, 5300); sheet.setColumnWidth(3, 3600); sheet.setColumnWidth(4, 4600); sheet.setColumnWidth(5, 10000); sheet.setColumnWidth(6, 6000); sheet.setColumnWidth(7, 4000); sheet.setColumnWidth(8, 3500); sheet.setColumnWidth(9, 3500); sheet.setColumnWidth(10, 3500); sheet.setColumnWidth(11, 4200); sheet.setColumnWidth(12, 4200); sheet.setColumnWidth(13, 4200); sheet.setColumnWidth(14, 4800); sheet.setColumnWidth(15, 5000); sheet.setColumnWidth(16, 5000); sheet.setColumnWidth(17, 3000); sheet.setColumnWidth(18, 4500); sheet.setColumnWidth(19, 4500); sheet.setColumnWidth(20, 3000); sheet.setColumnWidth(21, 4300); sheet.setColumnWidth(22, 4000); sheet.setColumnWidth(23, 7000); sheet.setColumnWidth(24, 10000); HSSFFont headFont0 = null; HSSFCellStyle headStyle0 = null; headFont0 = efw.getWorkbook().createFont(); headFont0.setFontHeightInPoints((short) 13); //? headFont0.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // headStyle0 = efw.getWorkbook().createCellStyle(); //? headStyle0.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? headStyle0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // headStyle0.setWrapText(true); // ? headStyle0.setFillBackgroundColor((short) 59); headStyle0.setFont(headFont0); //?? HSSFCellStyle cellMoney = efw.getWorkbook().createCellStyle(); HSSFDataFormat format = efw.getWorkbook().createDataFormat(); cellMoney.setAlignment(HSSFCellStyle.ALIGN_RIGHT); cellMoney.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); cellMoney.setDataFormat(format.getFormat("#,###,##0")); HSSFRow row0 = sheet.createRow(0); HSSFCell cell0 = row0.createCell(0); cell0.setCellValue("?"); cell0.setCellStyle(headStyle0); HSSFCell cell1 = row0.createCell(1); cell1.setCellValue("??"); cell1.setCellStyle(headStyle0); HSSFCell cell2 = row0.createCell(2); cell2.setCellValue("???"); cell2.setCellStyle(headStyle0); HSSFCell cell3 = row0.createCell(3); cell3.setCellValue("??"); cell3.setCellStyle(headStyle0); HSSFCell cell4 = row0.createCell(4); cell4.setCellValue("?"); cell4.setCellStyle(headStyle0); HSSFCell cell5 = row0.createCell(5); cell5.setCellValue("??"); cell5.setCellStyle(headStyle0); HSSFCell cell6 = row0.createCell(6); cell6.setCellValue("??"); cell6.setCellStyle(headStyle0); HSSFCell cell7 = row0.createCell(7); cell7.setCellValue("?"); cell7.setCellStyle(headStyle0); HSSFCell cell8 = row0.createCell(8); cell8.setCellValue("?"); cell8.setCellStyle(headStyle0); HSSFCell cell9 = row0.createCell(9); cell9.setCellValue(""); cell9.setCellStyle(headStyle0); HSSFCell cell10 = row0.createCell(10); cell10.setCellValue(""); cell10.setCellStyle(headStyle0); HSSFCell cell11 = row0.createCell(11); cell11.setCellValue("??"); cell11.setCellStyle(headStyle0); HSSFCell cell12 = row0.createCell(12); cell12.setCellValue("?"); cell12.setCellStyle(headStyle0); HSSFCell cell13 = row0.createCell(13); cell13.setCellValue("?"); cell13.setCellStyle(headStyle0); HSSFCell cell14 = row0.createCell(14); cell14.setCellValue(""); cell14.setCellStyle(headStyle0); HSSFCell cell15 = row0.createCell(15); cell15.setCellValue("?"); cell15.setCellStyle(headStyle0); HSSFCell cell16 = row0.createCell(16); cell16.setCellValue("??"); cell16.setCellStyle(headStyle0); HSSFCell cell17 = row0.createCell(17); cell17.setCellValue("?"); cell17.setCellStyle(headStyle0); HSSFCell cell18 = row0.createCell(18); cell18.setCellValue("??"); cell18.setCellStyle(headStyle0); HSSFCell cell19 = row0.createCell(19); cell19.setCellValue("?"); cell19.setCellStyle(headStyle0); HSSFCell cell20 = row0.createCell(20); cell20.setCellValue(""); cell20.setCellStyle(headStyle0); HSSFCell cell21 = row0.createCell(21); cell21.setCellValue("???"); cell21.setCellStyle(headStyle0); HSSFCell cell22 = row0.createCell(22); cell22.setCellValue("??"); cell22.setCellStyle(headStyle0); HSSFCell cell23 = row0.createCell(23); cell23.setCellValue("??"); cell23.setCellStyle(headStyle0); HSSFCell cell24 = row0.createCell(24); cell24.setCellValue(""); cell24.setCellStyle(headStyle0); for (int i = 0; i < list.size(); i++) { HSSFRow row1 = sheet.createRow(i + 1); HSSFCell cellr0 = row1.createCell(0); cellr0.setCellValue((String) list.get(i).get("CUST_CODE")); HSSFCell cellr1 = row1.createCell(1); cellr1.setCellValue((String) list.get(i).get("NAME")); HSSFCell cellr2 = row1.createCell(2); cellr2.setCellValue((String) list.get(i).get("CUST_NAME")); HSSFCell cellr3 = row1.createCell(3); cellr3.setCellValue((String) list.get(i).get("CORP_ORAGNIZATION_CODE")); HSSFCell cellr4 = row1.createCell(4); cellr4.setCellValue((String) list.get(i).get("CUST_AREA")); HSSFCell cellr5 = row1.createCell(5); cellr5.setCellValue((String) list.get(i).get("CORP_WORK_ADDRESS")); HSSFCell cellr6 = row1.createCell(6); cellr6.setCellValue((String) list.get(i).get("VIRTUAL_CODE")); HSSFCell cellr7 = row1.createCell(7); String s = null; int type = Integer.parseInt(list.get(i).get("STATETYPE").toString()); switch (type) { case 0: s = ""; break; case 1: s = ""; break; case 2: s = "??"; break; case 3: s = ""; break; case 4: s = ""; break; } cellr7.setCellValue(s); HSSFCell cellr8 = row1.createCell(8); cellr8.setCellValue((String) list.get(i).get("CORP_SETUP_DATE")); HSSFCell cellr9 = row1.createCell(9); double n = list.get(i).get("CORP_REGISTE_CAPITAL") == null ? 0 : (Double) list.get(i).get("CORP_REGISTE_CAPITAL"); cellr9.setCellValue(n); cellr9.setCellStyle(cellMoney); HSSFCell cellr10 = row1.createCell(10); double m = list.get(i).get("CORP_PAICLUP_CAPITAL") == null ? 0 : (Double) list.get(i).get("CORP_PAICLUP_CAPITAL"); cellr10.setCellValue(m); cellr10.setCellStyle(cellMoney); HSSFCell cellr11 = row1.createCell(11); cellr11.setCellValue((String) list.get(i).get("CORP_BUSINESS_LICENSE")); HSSFCell cellr12 = row1.createCell(12); cellr12.setCellValue((String) list.get(i).get("TAX_CODE")); HSSFCell cellr13 = row1.createCell(13); cellr13.setCellValue((String) list.get(i).get("CORP_TAX_CODE")); HSSFCell cellr14 = row1.createCell(14); cellr14.setCellValue((String) list.get(i).get("CORP_PERIOD_VALIDITY")); HSSFCell cellr15 = row1.createCell(15); cellr15.setCellValue((String) list.get(i).get("CORP_WORK_ADDRESS")); HSSFCell cellr16 = row1.createCell(16); cellr16.setCellValue((String) list.get(i).get("CORP_BUSINESS_RANGE")); HSSFCell cellr17 = row1.createCell(17); cellr17.setCellValue((String) list.get(i).get("CORP_COMPANY_ZIP")); HSSFCell cellr18 = row1.createCell(18); cellr18.setCellValue((String) list.get(i).get("CORP_COMPANY_WEBSITE")); HSSFCell cellr19 = row1.createCell(19); cellr19.setCellValue((String) list.get(i).get("CORP_COMPANY_EMAIL")); HSSFCell cellr20 = row1.createCell(20); cellr20.setCellValue((String) list.get(i).get("CORP_HEAD_SIGNATURE")); HSSFCell cellr21 = row1.createCell(21); cellr21.setCellValue((String) list.get(i).get("CORP_HS_IDCARD")); HSSFCell cellr22 = row1.createCell(22); cellr22.setCellValue((String) list.get(i).get("CORP_HS_LINK_MODE")); HSSFCell cellr23 = row1.createCell(23); cellr23.setCellValue((String) list.get(i).get("CORP_HS_HOME_ADDRESS")); HSSFCell cellr24 = row1.createCell(24); cellr24.setCellValue((String) list.get(i).get("REMARK")); } return efw.getWorkbook(); }
From source file:com.cimmyt.reports.impl.ServiceReportCustomQueryImpl.java
License:Apache License
public ServiceReportCustomQueryImpl() { book = new HSSFWorkbook(); sheet = book.createSheet();//from ww w. jav a2s .c o m plainStyle = book.createFont(); headerStyle = book.createFont(); plainStyle.setFontHeightInPoints((short) 11); plainStyle.setBoldweight((short) 11); plainStyle.setFontName(HSSFFont.FONT_ARIAL); BeanUtils.copyProperties(plainStyle, headerStyle); headerStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerCellStyle = book.createCellStyle(); headerCellStyle.setWrapText(true); headerCellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY); headerCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); headerCellStyle.setFont(headerStyle); plainCellStyle = book.createCellStyle(); plainCellStyle.setWrapText(true); plainCellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY); plainCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); plainCellStyle.setFont(plainStyle); }
From source file:com.cimmyt.reports.impl.ServiceReportKBioImpl.java
License:Apache License
/** * Method to put style to header and normally cell * @param objLibro/*from w w w .jav a 2 s . co m*/ * @param isHeader * @return */ private HSSFCellStyle styleCellNormally(HSSFWorkbook objLibro, boolean isHeader) { HSSFFont sourceStyle = objLibro.createFont(); sourceStyle.setFontHeightInPoints((short) 11); sourceStyle.setBoldweight((short) 11); sourceStyle.setFontName(HSSFFont.FONT_ARIAL); if (isHeader) { sourceStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } HSSFCellStyle styleCell = objLibro.createCellStyle(); styleCell.setWrapText(true); styleCell.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY); styleCell.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); styleCell.setFont(sourceStyle); return styleCell; }
From source file:com.comcast.cats.config.ui.monitoring.reboot.UpTimeAndRebootStatusBean.java
License:Open Source License
public void postProcessXls(Object document) { logger.trace("postProcessXls start document " + document); if (document != null) { HSSFWorkbook workBook = (HSSFWorkbook) document; HSSFSheet sheet = workBook.getSheetAt(0); HSSFRow headerRow = sheet.getRow(0); for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) { sheet.setColumnWidth(i, 30 * 265); // width for 40 characters }/*w w w. j a va 2s .com*/ sheet.shiftRows(0, sheet.getLastRowNum(), 5); // shift rows 0 to n // by 1 to get space // for header sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F3")); HSSFFont headerFont = workBook.createFont(); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle headerCellStyle = workBook.createCellStyle(); headerCellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); headerCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headerCellStyle.setFont(headerFont); headerCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headerCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFCell headerCell = headerRow.createCell(0); headerCell.setCellStyle(headerCellStyle); headerCell.setCellValue("CATS Uptime and Reboot Status : " + (new Date())); HSSFCellStyle metaDataCellStyle = workBook.createCellStyle(); metaDataCellStyle.setFont(headerFont); HSSFRow metaDataRow = sheet.getRow(3); if (metaDataRow == null) { metaDataRow = sheet.createRow(3); } HSSFCell metaDataKey = metaDataRow.createCell(0); metaDataKey.setCellStyle(metaDataCellStyle); metaDataKey.setCellValue("CATS Instance"); HSSFCell metaDataValue = metaDataRow.createCell(1); metaDataValue.setCellStyle(metaDataCellStyle); metaDataValue.setCellValue(AuthController.getHostAddress()); HSSFCellStyle datatTableHeaderCellStyle = workBook.createCellStyle(); datatTableHeaderCellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); datatTableHeaderCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); datatTableHeaderCellStyle.setFont(headerFont); HSSFRow actualDataTableHeaderRow = sheet.getRow(5); for (int i = 0; i < actualDataTableHeaderRow.getPhysicalNumberOfCells(); i++) { HSSFCell cell = actualDataTableHeaderRow.getCell(i); if (cell != null) { String cellValue = cell.getStringCellValue(); cellValue = cellValue.replace("<br/> ", ""); // replace // any line // breaks cell.setCellValue(cellValue); cell.setCellStyle(datatTableHeaderCellStyle); } } } logger.trace("postProcessXls end"); }
From source file:com.demo.common.extreme.view.XlsView.java
License:Apache License
private Map initStyles(HSSFWorkbook wb, short fontHeight) { Map result = new HashMap(); HSSFCellStyle titleStyle = wb.createCellStyle(); HSSFCellStyle textStyle = wb.createCellStyle(); HSSFCellStyle boldStyle = wb.createCellStyle(); HSSFCellStyle numericStyle = wb.createCellStyle(); HSSFCellStyle numericStyleBold = wb.createCellStyle(); HSSFCellStyle moneyStyle = wb.createCellStyle(); HSSFCellStyle moneyStyleBold = wb.createCellStyle(); HSSFCellStyle percentStyle = wb.createCellStyle(); HSSFCellStyle percentStyleBold = wb.createCellStyle(); // Add to export totals HSSFCellStyle moneyStyle_Totals = wb.createCellStyle(); HSSFCellStyle naStyle_Totals = wb.createCellStyle(); HSSFCellStyle numericStyle_Totals = wb.createCellStyle(); HSSFCellStyle percentStyle_Totals = wb.createCellStyle(); HSSFCellStyle textStyle_Totals = wb.createCellStyle(); result.put("titleStyle", titleStyle); result.put("textStyle", textStyle); result.put("boldStyle", boldStyle); result.put("numericStyle", numericStyle); result.put("numericStyleBold", numericStyleBold); result.put("moneyStyle", moneyStyle); result.put("moneyStyleBold", moneyStyleBold); result.put("percentStyle", percentStyle); result.put("percentStyleBold", percentStyleBold); // Add to export totals result.put("moneyStyle_Totals", moneyStyle_Totals); result.put("naStyle_Totals", naStyle_Totals); result.put("numericStyle_Totals", numericStyle_Totals); result.put("percentStyle_Totals", percentStyle_Totals); result.put("textStyle_Totals", textStyle_Totals); HSSFDataFormat format = wb.createDataFormat(); // Global fonts HSSFFont font = wb.createFont();// ww w .j a va2 s .c o m font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFColor.BLACK.index); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints(fontHeight); HSSFFont fontBold = wb.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setColor(HSSFColor.BLACK.index); fontBold.setFontName(HSSFFont.FONT_ARIAL); fontBold.setFontHeightInPoints(fontHeight); // Money Style moneyStyle.setFont(font); moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle.setDataFormat(format.getFormat(moneyFormat)); // Money Style Bold moneyStyleBold.setFont(fontBold); moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyleBold.setDataFormat(format.getFormat(moneyFormat)); // Percent Style percentStyle.setFont(font); percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle.setDataFormat(format.getFormat(percentFormat)); // Percent Style Bold percentStyleBold.setFont(fontBold); percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyleBold.setDataFormat(format.getFormat(percentFormat)); // Standard Numeric Style numericStyle.setFont(font); numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Standard Numeric Style Bold numericStyleBold.setFont(fontBold); numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Title Style titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBottomBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setLeftBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setRightBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setTopBorderColor(HSSFColor.BLACK.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Standard Text Style textStyle.setFont(font); textStyle.setWrapText(true); // Standard Text Style boldStyle.setFont(fontBold); boldStyle.setWrapText(true); // Money Style Total moneyStyle_Totals.setFont(fontBold); moneyStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); moneyStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); moneyStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); moneyStyle_Totals.setDataFormat(format.getFormat(moneyFormat)); // n/a Style Total naStyle_Totals.setFont(fontBold); naStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); naStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); naStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); naStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Numeric Style Total numericStyle_Totals.setFont(fontBold); numericStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); numericStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); numericStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); numericStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Percent Style Total percentStyle_Totals.setFont(fontBold); percentStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); percentStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); percentStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); percentStyle_Totals.setDataFormat(format.getFormat(percentFormat)); // Text Style Total textStyle_Totals.setFont(fontBold); textStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); textStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); textStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_LEFT); textStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return result; }
From source file:com.develog.utils.report.engine.export.JRXlsExporter.java
License:Open Source License
/** * */// w w w . ja v a 2s. co m protected HSSFFont getLoadedFont(JRFont font, short forecolor) { HSSFFont cellFont = null; if (loadedFonts != null && loadedFonts.size() > 0) { HSSFFont cf = null; for (int i = 0; i < loadedFonts.size(); i++) { cf = (HSSFFont) loadedFonts.get(i); if (cf.getFontName().equals(font.getFontName()) && (cf.getColor() == forecolor) && (cf.getFontHeightInPoints() == (short) font.getSize()) && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline())) && (cf.getStrikeout() == font.isStrikeThrough()) && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold())) && (cf.getItalic() == font.isItalic())) { cellFont = cf; break; } } } if (cellFont == null) { cellFont = workbook.createFont(); cellFont.setFontName(font.getFontName()); cellFont.setColor(forecolor); cellFont.setFontHeightInPoints((short) font.getSize()); if (font.isUnderline()) { cellFont.setUnderline(HSSFFont.U_SINGLE); } if (font.isStrikeThrough()) { cellFont.setStrikeout(true); } if (font.isBold()) { cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } if (font.isItalic()) { cellFont.setItalic(true); } loadedFonts.add(cellFont); } return cellFont; }