List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createFont
@Override
public HSSFFont createFont()
From source file:br.sp.telesul.service.ExportServiceImpl.java
public void writeExcel(String templateHead, String[] columns, HSSFWorkbook workbook) { try {/*from w w w .j a v a2 s.c om*/ List<Funcionario> funcionarios = funcionarioService.search(); HSSFSheet sheet = workbook.createSheet(templateHead); Row rowHeading = sheet.createRow(0); for (int i = 0; i < columns.length; i++) { rowHeading.createCell(i).setCellValue(columns[i]); } for (int i = 0; i < columns.length; i++) { CellStyle stylerowHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 11); font.setColor(HSSFColor.WHITE.index); stylerowHeading.setFont(font); stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER); stylerowHeading.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); stylerowHeading.setFillPattern(CellStyle.SOLID_FOREGROUND); rowHeading.getCell(i).setCellStyle(stylerowHeading); } int r = 1; for (Funcionario f : funcionarios) { Row row = sheet.createRow(r); Cell Nome = row.createCell(0); Nome.setCellValue(f.getNome()); Cell cargo = row.createCell(1); cargo.setCellValue(f.getCargo()); Cell dtAdmissao = row.createCell(2); dtAdmissao.setCellValue(f.getDtAdmissao()); CellStyle styleDate = workbook.createCellStyle(); HSSFDataFormat dfAdmissao = workbook.createDataFormat(); styleDate.setDataFormat(dfAdmissao.getFormat("dd/mm/yyyy")); dtAdmissao.setCellStyle(styleDate); Cell area = row.createCell(3); area.setCellValue(f.getArea()); Cell gestor = row.createCell(4); gestor.setCellValue(f.getGestor()); try { Cell email = row.createCell(5); email.setCellValue(f.getEmail()); } catch (NullPointerException ne) { } try { Cell telefone = row.createCell(6); telefone.setCellValue(f.getTelefone()); } catch (NullPointerException e) { } try { Cell celular = row.createCell(7); celular.setCellValue(f.getCelular()); } catch (NullPointerException e) { } r++; } for (int i = 0; i < columns.length; i++) { sheet.autoSizeColumn(i); } } catch (Exception e) { logger.error("Error gerate Report: " + e); System.out.println("Error" + e); } }
From source file:br.sp.telesul.service.ExportServiceImpl.java
public void writeExcelFormacao(String templateHead, String[] columns, HSSFWorkbook workbook) { try {/*ww w. ja va2 s. c o m*/ List<Funcionario> funcionarios = funcionarioService.search(); HSSFSheet sheet = workbook.createSheet(templateHead); Row rowHeading = sheet.createRow(0); for (int i = 0; i < columns.length; i++) { rowHeading.createCell(i).setCellValue(columns[i]); } //Estilizar o Cabealho - Stylesheet the heading for (int i = 0; i < columns.length; i++) { CellStyle stylerowHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 11); font.setColor(HSSFColor.WHITE.index); stylerowHeading.setFont(font); stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER); stylerowHeading.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); stylerowHeading.setFillPattern(CellStyle.SOLID_FOREGROUND); rowHeading.getCell(i).setCellStyle(stylerowHeading); } //Preencher linhas int r = 1; for (Funcionario f : funcionarios) { if (!f.getFormacoes().isEmpty()) { for (Formacao fmc : f.getFormacoes()) { if (!fmc.getInstituicao().isEmpty() || !fmc.getCurso().isEmpty() || !fmc.getNivel().isEmpty()) { Row row = sheet.createRow(r); try { Cell Nome = row.createCell(0); Nome.setCellValue(f.getNome()); } catch (NullPointerException e) { } try { Cell curso = row.createCell(1); curso.setCellValue(fmc.getCurso()); } catch (NullPointerException e) { } try { Cell instituicao = row.createCell(2); instituicao.setCellValue(fmc.getInstituicao()); } catch (NullPointerException e) { } try { Cell nivel = row.createCell(3); nivel.setCellValue(fmc.getNivel()); } catch (NullPointerException e) { } try { Cell copia = row.createCell(4); copia.setCellValue(fmc.getCopiaCertificado()); } catch (NullPointerException e) { } r++; } } } } for (int i = 0; i < columns.length; i++) { sheet.autoSizeColumn(i); } } catch (Exception e) { System.out.println("Error " + e); } }
From source file:br.sp.telesul.service.ExportServiceImpl.java
public void writeExcelCertificacoes(String templateHead, String[] columns, HSSFWorkbook workbook) { try {/*ww w . j a va 2 s . c om*/ List<Funcionario> funcionarios = funcionarioService.search(); HSSFSheet sheet = workbook.createSheet(templateHead); Row rowHeading = sheet.createRow(0); for (int i = 0; i < columns.length; i++) { rowHeading.createCell(i).setCellValue(columns[i]); } //Estilizar o Cabealho - Stylesheet the heading for (int i = 0; i < columns.length; i++) { CellStyle stylerowHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 11); font.setColor(HSSFColor.WHITE.index); stylerowHeading.setFont(font); stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER); stylerowHeading.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); stylerowHeading.setFillPattern(CellStyle.SOLID_FOREGROUND); rowHeading.getCell(i).setCellStyle(stylerowHeading); } //Preencher linhas int r = 1; for (Funcionario f : funcionarios) { if (!f.getCertificacoes().isEmpty()) { for (Certificacao ct : f.getCertificacoes()) { Row row = sheet.createRow(r); CellStyle styleDate = workbook.createCellStyle(); HSSFDataFormat dfExame = workbook.createDataFormat(); styleDate.setDataFormat(dfExame.getFormat("dd/mm/yyyy")); try { Cell Nome = row.createCell(0); Nome.setCellValue(f.getNome()); } catch (NullPointerException e) { } try { Cell cod = row.createCell(1); cod.setCellValue(ct.getCodigo()); } catch (NullPointerException e) { } try { Cell nome = row.createCell(3); nome.setCellValue(ct.getNome()); } catch (NullPointerException e) { } try { Cell empresa = row.createCell(2); empresa.setCellValue(ct.getEmpresa()); } catch (NullPointerException e) { } try { Cell dtExame = row.createCell(4); dtExame.setCellValue(ct.getDtExame()); dtExame.setCellStyle(styleDate); } catch (NullPointerException e) { } try { Cell dtValidade = row.createCell(5); dtValidade.setCellValue(ct.getDtValidade()); dtValidade.setCellStyle(styleDate); } catch (NullPointerException e) { } try { Cell copia = row.createCell(6); copia.setCellValue(ct.getCopia()); } catch (NullPointerException e) { } r++; } } } for (int i = 0; i < columns.length; i++) { sheet.autoSizeColumn(i); } // String file = "C:/Users/ebranco.TELESULCORP/new.xls"; // FileOutputStream out = new FileOutputStream(file); // workbook.write(out); // out.close(); // workbook.close(); // System.out.println("Excell write succesfully"); } catch (Exception e) { System.out.println("Error" + e); } }
From source file:br.sp.telesul.service.ExportServiceImpl.java
public void writeExcelIdiomas(String templateHead, String[] columns, HSSFWorkbook workbook) { try {// ww w. ja v a 2 s . c o m List<Funcionario> funcionarios = funcionarioService.search(); HSSFSheet sheet = workbook.createSheet(templateHead); Row rowHeading = sheet.createRow(0); for (int i = 0; i < columns.length; i++) { rowHeading.createCell(i).setCellValue(columns[i]); } //Estilizar o Cabealho - Stylesheet the heading for (int i = 0; i < columns.length; i++) { CellStyle stylerowHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 11); font.setColor(HSSFColor.WHITE.index); stylerowHeading.setFont(font); stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER); stylerowHeading.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); stylerowHeading.setFillPattern(CellStyle.SOLID_FOREGROUND); rowHeading.getCell(i).setCellStyle(stylerowHeading); } //Preencher linhas int r = 1; for (Funcionario f : funcionarios) { if (!f.getIdiomas().isEmpty()) { for (Idioma idm : f.getIdiomas()) { try { if (idm.getNivel() != null || idm.getNome() != null) { Row row = sheet.createRow(r); Cell Nome = row.createCell(0); Nome.setCellValue(f.getNome()); Cell language = row.createCell(1); language.setCellValue(idm.getNome().toString()); Cell nivel = row.createCell(2); nivel.setCellValue(idm.getNivel().toString()); r++; } } catch (NullPointerException ne) { System.out.println("Error " + ne); break; } } } } for (int i = 0; i < columns.length; i++) { sheet.autoSizeColumn(i); } } catch (Exception e) { System.out.println("Error" + e); } }
From source file:br.sp.telesul.service.ExportServiceImpl.java
public void stylizeHeader(Row rowHeading, HSSFWorkbook workbook, String[] columns) { for (int i = 0; i < columns.length; i++) { CellStyle stylerowHeading = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBold(true);//from w w w .j ava 2 s .c o m font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 11); font.setColor(HSSFColor.WHITE.index); stylerowHeading.setFont(font); stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER); stylerowHeading.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index); stylerowHeading.setFillPattern(CellStyle.SOLID_FOREGROUND); rowHeading.getCell(i).setCellStyle(stylerowHeading); } }
From source file:cn.mario256.blog.ExcelView.java
License:Open Source License
/** * ?Excel/*from w w w. j a v a 2s.c o m*/ * * @param model * ? * @param workbook * HSSFWorkbook * @param request * HttpServletRequest * @param response * HttpServletResponse */ 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" + " " + "S" + "H" + "O" + "P" + "+" + "+")); 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:co.turnus.analysis.data.bottlenecks.io.XlsAlgoBottlenecksDataWriter.java
License:Open Source License
public void write(AlgoBottlenecksData report, File file) { try {// w w w . j a va 2s .co m HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HotspotsDataAnalyser analyzer = new HotspotsDataAnalyser(report); writeSummary(workbook, report.getNetwork(), analyzer); writeActorClassesTable(workbook, analyzer); writeActorsTable(workbook, analyzer); writeActionActorClassTable(workbook, analyzer); writeActionActorTable(workbook, analyzer); // check if there are also impact analysis data ImpactData impactData = report.getImpactData(); if (impactData != null) { writeImpactAnalysis(workbook, impactData); } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.analysis.data.buffers.io.XlsBufferMinimizationDataWriter.java
License:Open Source License
public void write(BufferMinimizationData report, File file) { try {/* w ww . j a v a2 s .c om*/ HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); int solutionId = 1; for (BuffersData data : report.getBuffersData()) { writeData(workbook, data, report.getNetwork(), report.getAlgorithm(), solutionId++); } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.analysis.data.partitioning.io.XlsPartitioningDataWriter.java
License:Open Source License
public void write(PartitioningData report, File file) { try {// w ww. j ava 2s . c o m HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); int solutionId = 1; for (PartitionsData data : report.getPartitionsData()) { writeData(workbook, data, report.getNetwork(), report.getAlgorithm(), solutionId++); } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }
From source file:co.turnus.analysis.data.pipelining.io.XlsSimplePipeliningDataWriter.java
License:Open Source License
public void write(SimplePipelingData report, File file) { try {//w ww .jav a 2 s . com HSSFWorkbook workbook = new HSSFWorkbook(); titleFont = workbook.createFont(); titleFont.setFontName("Arial"); titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle = workbook.createCellStyle(); cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm")); HSSFSheet sheet = workbook.createSheet("Pipelinable <Actor, Action>"); // Action Actor Class Results Cell cell = sheet.createRow(0).createCell(0); HSSFRichTextString title = new HSSFRichTextString("Action and Actor Pipelining Results"); title.applyFont(titleFont); cell.setCellValue(title); Row row = sheet.createRow(1); sheet.addMergedRegion(new CellRangeAddress(1, 3, 0, 0)); row.createCell(0).setCellValue("Actor"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 1, 1)); row.createCell(1).setCellValue("Action"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 2, 2)); row.createCell(2).setCellValue("pipelinable"); sheet.addMergedRegion(new CellRangeAddress(1, 1, 3, 10)); row.createCell(3).setCellValue("Consecutive Executions"); sheet.addMergedRegion(new CellRangeAddress(1, 3, 11, 11)); row.createCell(11).setCellValue("Splittable Actions"); row = sheet.createRow(2); sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 6)); row.createCell(3).setCellValue("Pipelinable"); sheet.addMergedRegion(new CellRangeAddress(2, 2, 7, 10)); row.createCell(7).setCellValue("Unconstrained"); row = sheet.createRow(3); row.createCell(3).setCellValue("min"); row.createCell(4).setCellValue("mean"); row.createCell(5).setCellValue("max"); row.createCell(6).setCellValue("var"); row.createCell(7).setCellValue("min"); row.createCell(8).setCellValue("mean"); row.createCell(9).setCellValue("max"); row.createCell(10).setCellValue("var"); int rowId = 4; Map<Actor, Map<Action, SimpleActionPipeliningData>> table = report.asTable().rowMap(); for (Map<Action, SimpleActionPipeliningData> ac : table.values()) { for (SimpleActionPipeliningData data : ac.values()) { row = sheet.createRow(rowId); row.createCell(0).setCellValue(data.getActor().getId()); row.createCell(1).setCellValue(data.getAction().getId()); row.createCell(2).setCellValue(data.isPipelinable()); StatisticalData stat = data.getPipelinableRepetitions(); if (stat.getSamples() > 0) { row.createCell(3).setCellValue(stat.getMin()); row.createCell(4).setCellValue(stat.getMean()); row.createCell(5).setCellValue(stat.getMax()); row.createCell(6).setCellValue(stat.getVariance()); } else { row.createCell(3).setCellValue("-"); row.createCell(4).setCellValue("-"); row.createCell(5).setCellValue("-"); row.createCell(6).setCellValue("-"); } stat = data.getUnconstrainedRepetitions(); if (stat.getSamples() > 0) { row.createCell(7).setCellValue(stat.getMin()); row.createCell(8).setCellValue(stat.getMean()); row.createCell(9).setCellValue(stat.getMax()); row.createCell(10).setCellValue(stat.getVariance()); } else { row.createCell(7).setCellValue("-"); row.createCell(8).setCellValue("-"); row.createCell(9).setCellValue("-"); row.createCell(10).setCellValue("-"); } StringBuffer b = new StringBuffer(); for (Action action : data.getSplittableActions()) { b.append(action.getId()).append(" "); } row.createCell(11).setCellValue(b.toString()); rowId++; } } OutputStream out = new FileOutputStream(file); out = new BufferedOutputStream(out); workbook.write(out); out.close(); } catch (Exception e) { throw new TurnusRuntimeException("Error writing the excel file " + file, e.getCause()); } }