List of usage examples for org.apache.poi.hssf.usermodel HSSFRow createCell
@Override public HSSFCell createCell(int column)
From source file:br.com.muranodesign.resources.AlunoVariavelResource.java
License:Creative Commons License
/** * Gerar relatrio de aluno variavel/*from w w w . j a va 2 s. c o m*/ * @param Tutoria * @param Ano * @param Periodo * @param Nome * @param Sexo * @param Datanascimento * @param Endereco * @param TelefoneResidencial * @param TelefoneCelular * @param email * @param NomeResponsavel * @param ParentescoResponsavel * @param TelefoneResidencialResponsavel * @param TelefoneCelularResponsavel * @param TelefoneComercialResponsavel * @param emailResponsavel * @param NomeMae * @param EnderecoMae * @param TelefoneCelularMae * @param TelefoneResidencialMae * @param TelefoneComercialMae * @param emailMae * @return list */ @Path("Relatorio") @POST @Produces("application/json") public List<String> relatorio(@FormParam("Tutoria") int Tutoria, @FormParam("Ano") int Ano, @FormParam("Periodo") int Periodo, @FormParam("Neces") String Neces, @FormParam("Prog") String Prog, @FormParam("Status") String Status, @FormParam("tutoria") String tut, @FormParam("Nome") String Nome, @FormParam("Sexo") String Sexo, @FormParam("Datanascimento") String Datanascimento, @FormParam("Endereco") String Endereco, @FormParam("TelefoneResidencial") String TelefoneResidencial, @FormParam("TelefoneCelular") String TelefoneCelular, @FormParam("email") String email, @FormParam("NomeResponsavel") String NomeResponsavel, @FormParam("ParentescoResponsavel") String ParentescoResponsavel, @FormParam("TelefoneResidencialResponsavel") String TelefoneResidencialResponsavel, @FormParam("TelefoneCelularResponsavel") String TelefoneCelularResponsavel, @FormParam("TelefoneComercialResponsavel") String TelefoneComercialResponsavel, @FormParam("emailResponsavel") String emailResponsavel, @FormParam("NomeMae") String NomeMae, @FormParam("EnderecoMae") String EnderecoMae, @FormParam("TelefoneCelularMae") String TelefoneCelularMae, @FormParam("TelefoneResidencialMae") String TelefoneResidencialMae, @FormParam("TelefoneComercialMae") String TelefoneComercialMae, @FormParam("emailMae") String emailMae) { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet firstSheet = workbook.createSheet("Relatorio Aluno"); FileOutputStream fos = null; String nomeArquivo; try { nomeArquivo = new StringUtil().geraNomeAleatorio("xls", 15); fos = new FileOutputStream(new File("/home/tomcat/webapps/files/" + nomeArquivo)); //fos = new FileOutputStream(new File("C:/Users/murano/Desktop/Teste/" + nomeArquivo)); HSSFRow row = firstSheet.createRow(0); List<String> retorno = new ArrayList<String>(); List<List<String>> listRetorno = new ArrayList<List<String>>(); int h = 0; row = firstSheet.createRow(h); row.createCell((short) 0).setCellValue("Tutoria"); row.createCell((short) 1).setCellValue("Nome"); row.createCell((short) 2).setCellValue("Sexo"); row.createCell((short) 3).setCellValue("Datanascimento"); row.createCell((short) 4).setCellValue("Endereco"); row.createCell((short) 5).setCellValue("TelefoneResidencial"); row.createCell((short) 6).setCellValue("TelefoneCelular"); row.createCell((short) 7).setCellValue("email"); row.createCell((short) 8).setCellValue("NomeResponsavel"); row.createCell((short) 9).setCellValue("ParentescoResponsavel"); row.createCell((short) 10).setCellValue("TelefoneResidencialResponsavel"); row.createCell((short) 11).setCellValue("TelefoneCelularResponsavel"); row.createCell((short) 12).setCellValue("TelefoneComercialResponsavel"); row.createCell((short) 13).setCellValue("emailResponsavel"); row.createCell((short) 14).setCellValue("NomeMae"); row.createCell((short) 15).setCellValue("EnderecoMae"); row.createCell((short) 16).setCellValue("TelefoneCelularMae"); row.createCell((short) 17).setCellValue("TelefoneResidencialMae"); row.createCell((short) 18).setCellValue("TelefoneComercialMae"); row.createCell((short) 19).setCellValue("emailMae"); List<AlunoVariavel> list = new AlunoVariavelService().listarRelatorioSecretaria(Tutoria, Ano, Periodo, Neces, Prog, Status); for (AlunoVariavel alunoVariavel : list) { h++; row = firstSheet.createRow(h); //row.createCell((short) 0).setCellValue("Relatrio"); if (tut != "" && tut != null) { String valor = alunoVariavel.getGrupo().getTutoria().getTutoria(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 0).setCellValue(valor); } else { retorno.add("no informado"); } } if (Nome != "" && Nome != null) { String valor = alunoVariavel.getAluno().getNome(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 1).setCellValue(valor); } else { retorno.add("no informado"); } } if (Sexo != "" && Sexo != null) { String valor = alunoVariavel.getAluno().getSexo(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 2).setCellValue(valor); } else { retorno.add("no informado"); } } if (Datanascimento != "" && Datanascimento != null) { Date valor = alunoVariavel.getAluno().getDataNascimento(); if (valor != null) { DateFormat formatter = new SimpleDateFormat("dd-MM-yy"); String dataS = formatter.format(valor); //Date data = (Date) formatter.parse(dataS); retorno.add(dataS); row.createCell((short) 3).setCellValue(valor); } else { retorno.add(null); } } if (Endereco != "" && Endereco != null) { String valor = alunoVariavel.getAluno().getEndereco(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 4).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneResidencial != "" && TelefoneResidencial != null) { String valor = alunoVariavel.getAluno().getTelefoneResidencialResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 5).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneCelular != "" && TelefoneCelular != null) { String valor = alunoVariavel.getAluno().getTelefoneCelularResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 6).setCellValue(valor); } else { retorno.add("no informado"); } } if (email != "" && email != null) { String valor = alunoVariavel.getAluno().getEmail(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 7).setCellValue(valor); } else { retorno.add("no informado"); } } if (NomeResponsavel != "" && NomeResponsavel != null) { String valor = alunoVariavel.getAluno().getNomeResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 8).setCellValue(valor); } else { retorno.add("no informado"); } } if (ParentescoResponsavel != "" && ParentescoResponsavel != null) { String valor = alunoVariavel.getAluno().getParentescoResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 9).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneResidencialResponsavel != "" && TelefoneResidencialResponsavel != null) { String valor = alunoVariavel.getAluno().getTelefoneResidencialResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 10).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneCelularResponsavel != "" && TelefoneCelularResponsavel != null) { String valor = alunoVariavel.getAluno().getTelefoneCelularResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 11).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneComercialResponsavel != "" && TelefoneComercialResponsavel != null) { String valor = alunoVariavel.getAluno().getTelefoneComercialResponsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 12).setCellValue(valor); } else { retorno.add("no informado"); } } if (emailResponsavel != "" && emailResponsavel != null) { String valor = alunoVariavel.getAluno().getEmail1Responsavel(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 13).setCellValue(valor); } else { retorno.add("no informado"); } } if (NomeMae != "" && NomeMae != null) { String valor = alunoVariavel.getAluno().getNomeMae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 14).setCellValue(valor); } else { retorno.add("no informado"); } } if (EnderecoMae != "" && EnderecoMae != null) { String valor = alunoVariavel.getAluno().getEnderecoMae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 15).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneCelularMae != "" && TelefoneCelularMae != null) { String valor = alunoVariavel.getAluno().getTelefoneCelularMae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 16).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneResidencialMae != "" && TelefoneResidencialMae != null) { String valor = alunoVariavel.getAluno().getTelefoneResidencialMae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 17).setCellValue(valor); } else { retorno.add("no informado"); } } if (TelefoneComercialMae != "" && TelefoneComercialMae != null) { String valor = alunoVariavel.getAluno().getTelefoneComercialMae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 18).setCellValue(valor); } else { retorno.add("no informado"); } } if (emailMae != "" && emailMae != null) { String valor = alunoVariavel.getAluno().getEmail1Mae(); if (valor != null && valor != "-") { retorno.add(valor); row.createCell((short) 19).setCellValue(valor); } else { retorno.add("no informado"); } } listRetorno.add(retorno); } if (listRetorno.isEmpty()) { retorno.add("no h valores"); listRetorno.add(retorno); } workbook.write(fos); retorno.add("http://177.55.99.90/files/" + nomeArquivo); //retorno.add("http://172.16.31.178/"+nomeArquivo); listRetorno.add(retorno); return listRetorno.get(0); } catch (Exception e) { e.printStackTrace(); logger.info("Erro ao exportar arquivo"); } finally { try { fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:br.com.pontocontrol.controleponto.controller.impl.ExportadorXLSController.java
@Override public boolean extrair(FolhaMensalPonto folhaMensal, String outputFileDir) { Calendar data = Calendar.getInstance(); data.set(Calendar.MONTH, folhaMensal.getMes()); data.set(Calendar.YEAR, folhaMensal.getAno()); final String nomeArquivo = format("%s-%s_%s.xls", SessaoManager.getInstance().getUsuarioAutenticado().getLogin(), formatDate("yyyy-MMMM", data.getTime()), formatDate("yyyyMMddHHmmssSSS", new Date())); final String filePath = format("%s/%s", outputFileDir, nomeArquivo); File arquivoXLS = new File(filePath); FileOutputStream fos = null;//from w w w .j av a 2s.co m try { arquivoXLS.createNewFile(); fos = new FileOutputStream(arquivoXLS); HSSFWorkbook workbook = HSSFWorkbook.create(InternalWorkbook.createWorkbook()); final String nomePlanilha = formatDate("MMM-yy", data.getTime()); HSSFSheet planilha = workbook.createSheet(nomePlanilha); //TOTAL ROW HSSFRow totalRow = planilha.createRow(0); totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_TXT).setCellValue("Total:"); totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_VALUE).setCellValue(folhaMensal.calcularTotalMensal()); totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_TXT).setCellValue("Variao:"); totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_VALUE).setCellValue(folhaMensal.calcularVariacaoMensal()); //HEADER HSSFRow headerRow = planilha.createRow(1); headerRow.createCell(CELL_INDEX.DIA).setCellValue("Dia"); headerRow.createCell(CELL_INDEX.ENTRADA).setCellValue("Entrada"); headerRow.createCell(CELL_INDEX.ALMOCO).setCellValue("Almoo"); headerRow.createCell(CELL_INDEX.RETORNO).setCellValue("Retorno"); headerRow.createCell(CELL_INDEX.SAIDA).setCellValue("Sada"); headerRow.createCell(CELL_INDEX.TOTAL_EXP).setCellValue("Expediente"); headerRow.createCell(CELL_INDEX.VARIACAO).setCellValue("Variao"); formatHeaderRow(workbook, headerRow); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, folhaMensal.getAno()); cal.set(Calendar.MONTH, folhaMensal.getMes()); for (int dia = 1; dia <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); dia++) { int i = planilha.getPhysicalNumberOfRows(); HSSFRow row = planilha.createRow(i); cal.set(Calendar.DAY_OF_MONTH, dia); row.createCell(CELL_INDEX.DIA).setCellValue(formatDate("MMM dd, EEE", cal.getTime())); RegistroDiarioPonto reg = folhaMensal.getRegistros().get(dia); if (reg != null) { row.createCell(CELL_INDEX.ENTRADA) .setCellValue(reg.getEntrada() != null ? reg.getEntrada().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.ALMOCO) .setCellValue(reg.getAlmoco() != null ? reg.getAlmoco().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.RETORNO) .setCellValue(reg.getRetorno() != null ? reg.getRetorno().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.SAIDA) .setCellValue(reg.getSaida() != null ? reg.getSaida().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue( reg.isRegistroDiarioCompleto() ? reg.calcularTotalExpedienteAsNumber() : 0); row.createCell(CELL_INDEX.VARIACAO) .setCellValue(reg.isRegistroDiarioCompleto() ? reg.calcularVariacaoExpediente() : 0); } else { row.createCell(CELL_INDEX.ENTRADA).setCellValue(""); row.createCell(CELL_INDEX.ALMOCO).setCellValue(""); row.createCell(CELL_INDEX.RETORNO).setCellValue(""); row.createCell(CELL_INDEX.SAIDA).setCellValue(""); row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue(""); row.createCell(CELL_INDEX.VARIACAO).setCellValue(""); } if (SessaoManager.getInstance().getUsuarioAutenticado().checarSeDiaExpediente(cal)) { formatRow(workbook, row); } else { formatHeaderRow(workbook, row); } } for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) { planilha.autoSizeColumn(i); } workbook.write(fos); fos.flush(); return true; } catch (IOException ex) { LOG.log(Level.SEVERE, "Erro ao criar arquivo XLS de sada", ex); return false; } finally { IOUtils.closeQuietly(fos); } }
From source file:br.edu.tglima.model.result.PlanilhaXLS.java
License:Open Source License
/** * Mtodo responsvel por gerar a planilha XLS. * /* w ww.ja va 2 s.c om*/ * * @param arquivo Referente ao local e nome do arquivo. * @return Retorno do tipo Boolean, indicando se o arquivo foi gerado * com sucesso, ou no. */ public boolean gerarPlanilha(File arquivo) { try { /*Verificamos se j existe um arquivo com esse "nome". Caso ele exista, ele ser removido e o novo arquivo ser gerado.*/ if (workbook.getNumberOfSheets() > 0) { workbook.removeSheetAt(0); } HSSFSheet sheet = workbook.createSheet("Valores Exportados"); /* Criando as linhas. --------------------------------------------- */ HSSFRow header1 = sheet.createRow((short) 0); HSSFRow linha02 = sheet.createRow((short) 1); HSSFRow linha03 = sheet.createRow((short) 2); HSSFRow linha04 = sheet.createRow((short) 3); HSSFRow linha05 = sheet.createRow((short) 4); HSSFRow header2 = sheet.createRow((short) 7); HSSFRow linha09 = sheet.createRow((short) 8); HSSFRow linha10 = sheet.createRow((short) 9); HSSFRow linha11 = sheet.createRow((short) 10); HSSFRow linha12 = sheet.createRow((short) 11); HSSFRow linha13 = sheet.createRow((short) 12); HSSFRow linha14 = sheet.createRow((short) 13); HSSFRow linha15 = sheet.createRow((short) 14); HSSFRow linha17 = sheet.createRow((short) 16); HSSFRow header3 = sheet.createRow((short) 19); HSSFRow linha21 = sheet.createRow((short) 20); HSSFRow linha22 = sheet.createRow((short) 21); HSSFRow linha23 = sheet.createRow((short) 22); HSSFRow linha25 = sheet.createRow((short) 24); // ------------------------------------------------------------------------ // /* Mesclando as clulas. ------------------------------------------ */ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2)); sheet.addMergedRegion(new CellRangeAddress(7, 7, 0, 2)); sheet.addMergedRegion(new CellRangeAddress(19, 19, 0, 2)); // ------------------------------------------------------------------------ // /* Definindo a largura das colunas. ------------------------------- */ sheet.setColumnWidth(0, 12000); sheet.setColumnWidth(1, 5200); sheet.setColumnWidth(2, 6500); // ------------------------------------------------------------------------ // /* Definindo os estilos das clulas. ------------------------------ */ CellStyle headerStyle = workbook.createCellStyle(); Font headerFont = workbook.createFont(); headerFont.setFontHeightInPoints((short) 20); headerStyle.setFont(headerFont); headerStyle.setAlignment(HorizontalAlignment.CENTER); CellStyle cellCentered = workbook.createCellStyle(); cellCentered.setAlignment(HorizontalAlignment.CENTER); CellStyle cellFontBold = workbook.createCellStyle(); Font fontBold = workbook.createFont(); fontBold.setBold(true); cellFontBold.setFont(fontBold); CellStyle cellResulted = workbook.createCellStyle(); Font resultFont = workbook.createFont(); resultFont.setBold(true); cellResulted.setFont(resultFont); cellResulted.setAlignment(HorizontalAlignment.CENTER); Cell cell; // ------------------------------------------------------------------------ // /* Criando as Colunas da Tabela ----------------------------------- */ //Colunas da linha 1 header1.createCell(0).setCellValue("Dados Fornecidos"); //Colunas da linha 2 linha02.createCell(0).setCellValue("Data de Entrada"); linha02.createCell(2).setCellValue(this.rst.getDataEntrada()); //Colunas da Linha 3 linha03.createCell(0).setCellValue("Data de Sada"); linha03.createCell(2).setCellValue(this.rst.getDataSaida()); //Colunas da Linha 4 linha04.createCell(0).setCellValue("Salrio Informado"); linha04.createCell(2).setCellValue(this.rst.getSalario()); //Colunas da Linha 5 linha05.createCell(0).setCellValue("Motivo da Sada"); linha05.createCell(2).setCellValue(this.rst.getMotivoRes()); //Colunas da linha 8 header2.createCell(0).setCellValue("Resciso"); //Colunas da linha 9 linha09.createCell(0).setCellValue("Item"); linha09.createCell(1).setCellValue("Referncia"); linha09.createCell(2).setCellValue("Valor"); //Colunas da Linha 10 linha10.createCell(0).setCellValue("Saldo Salrio"); linha10.createCell(1).setCellValue(this.rst.getTotDiasTrabUltMes()); linha10.createCell(2).setCellValue(this.rst.getUltSalario()); //Colunas da Linha 11 linha11.createCell(0).setCellValue("13 Proporcional"); linha11.createCell(1).setCellValue(this.rst.getTotMesesTrabUltAno()); linha11.createCell(2).setCellValue(this.rst.getVlrDecimo()); //Colunas da Linha 12 linha12.createCell(0).setCellValue("Frias Proporcional"); linha12.createCell(1).setCellValue(this.rst.getTotMesesAqFerias()); linha12.createCell(2).setCellValue(this.rst.getVlrFerias()); //Colunas da Linha 13 linha13.createCell(0).setCellValue("1/3 Frias Proporcional"); linha13.createCell(1).setCellValue("-"); linha13.createCell(2).setCellValue(this.rst.getVlrTercoFerias()); //Colunas da Linha 14 linha14.createCell(0).setCellValue("Frias Vencidas"); linha14.createCell(1).setCellValue(this.rst.getTotFeriasVenc()); linha14.createCell(2).setCellValue(this.rst.getVlrFeriasVenc()); //Colunas da linha 15 linha15.createCell(0).setCellValue("Aviso Prvio"); linha15.createCell(1).setCellValue(this.rst.getTotDiasAviso()); linha15.createCell(2).setCellValue(this.rst.getVlrAvisoP()); //Colunas da linha 17 linha17.createCell(0).setCellValue("Valor Total"); linha17.createCell(1).setCellValue("-"); linha17.createCell(2).setCellValue(this.rst.getVlrTotVenc()); //Colunas da Linha 20 header3.createCell(0).setCellValue("FGTS"); //Colunas da Linha 21 linha21.createCell(0).setCellValue("Valores do FGTS estaro disponveis para saque?"); linha21.createCell(2).setCellValue(this.rst.getReceberFgts()); //Colunas da Linha 22 linha22.createCell(0).setCellValue("Saldo FGTS"); linha22.createCell(2).setCellValue(this.rst.getSaldoFgts()); //Colunas da Linha 23 linha23.createCell(0).setCellValue("Multa de 40%"); linha23.createCell(2).setCellValue(this.rst.getVlrMulta()); //Colunas da Linha 25 linha25.createCell(0).setCellValue("Valor total"); linha25.createCell(2).setCellValue(this.rst.getVlrTotFgts()); // ------------------------------------------------------------------------ // /* Aplicando os estilos nas clulas ------------------------------- */ cell = header1.getCell(0); cell.setCellStyle(headerStyle); header1.setRowStyle(headerStyle); header1.setHeightInPoints(30); cell = header2.getCell(0); cell.setCellStyle(headerStyle); header2.setRowStyle(headerStyle); header2.setHeightInPoints(30); cell = header3.getCell(0); cell.setCellStyle(headerStyle); header3.setRowStyle(headerStyle); header3.setHeightInPoints(30); linha02.getCell(2).setCellStyle(cellCentered); linha03.getCell(2).setCellStyle(cellCentered); linha04.getCell(2).setCellStyle(cellCentered); linha05.getCell(2).setCellStyle(cellCentered); linha09.getCell(1).setCellStyle(cellCentered); linha09.getCell(2).setCellStyle(cellCentered); linha10.getCell(1).setCellStyle(cellCentered); linha10.getCell(2).setCellStyle(cellCentered); linha11.getCell(1).setCellStyle(cellCentered); linha11.getCell(2).setCellStyle(cellCentered); linha12.getCell(1).setCellStyle(cellCentered); linha12.getCell(2).setCellStyle(cellCentered); linha13.getCell(1).setCellStyle(cellCentered); linha13.getCell(2).setCellStyle(cellCentered); linha14.getCell(1).setCellStyle(cellCentered); linha14.getCell(2).setCellStyle(cellCentered); linha15.getCell(1).setCellStyle(cellCentered); linha15.getCell(2).setCellStyle(cellCentered); linha17.getCell(0).setCellStyle(cellFontBold); linha17.getCell(1).setCellStyle(cellCentered); linha17.getCell(2).setCellStyle(cellResulted); linha21.getCell(2).setCellStyle(cellCentered); linha22.getCell(2).setCellStyle(cellCentered); linha23.getCell(2).setCellStyle(cellCentered); linha25.getCell(0).setCellStyle(cellFontBold); linha25.getCell(2).setCellStyle(cellResulted); // ------------------------------------------------------------------------ // /* Escrever, salvar e fechar o arquivo ---------------------------- */ workbook.write(arquivo); // Escrevendo no arquivo. workbook.close(); // Salvando e fechando o arquivo. return true; } catch (Exception e) { System.err.println("No foi possvel gerar seu arquivo!" + " \n" + e.getLocalizedMessage()); return false; } }
From source file:br.prof.salesfilho.oci.service.ExcelService.java
public void createSheet(String name, List<ClassificationResult> classificationResults) { HSSFSheet sheet = workbook.createSheet(name); HSSFRow rowhead = sheet.createRow((short) 0); rowhead.createCell(0).setCellValue("fileName"); rowhead.createCell(1).setCellValue("finalClassification"); rowhead.createCell(2).setCellValue("date"); rowhead.createCell(3).setCellValue("nudeAvgScore"); rowhead.createCell(4).setCellValue("notNudeAvgScore"); rowhead.createCell(5).setCellValue("maybeNudeAvgScore"); rowhead.createCell(6).setCellValue("kernelSize"); rowhead.createCell(7).setCellValue("executionTime"); rowhead.createCell(8).setCellValue("classificationLevel"); int idx = 1;/*from ww w. j a v a 2 s.c om*/ for (ClassificationResult classificationResult : classificationResults) { HSSFRow row = sheet.createRow((short) idx); row.createCell(0).setCellValue(classificationResult.getFileName()); row.createCell(1).setCellValue(classificationResult.getFinalClassification()); row.createCell(2).setCellValue(classificationResult.getDate()); row.createCell(3).setCellValue(classificationResult.getNudeAvgScore()); row.createCell(4).setCellValue(classificationResult.getNotNudeAvgScore()); row.createCell(5).setCellValue(classificationResult.getMaybeNudeAvgScore()); row.createCell(6).setCellValue(classificationResult.getKernelSize()); row.createCell(7).setCellValue(classificationResult.getExecutionTime()); row.createCell(8).setCellValue(classificationResult.getClassificationLevel()); idx++; } }
From source file:br.solutio.licita.controlador.ControladorPregao.java
public void editandoXlsParaExportar(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet planilha = wb.getSheetAt(0); //Move as celulas selecionadas para baixo de acordo com o valor informado planilha.shiftRows(planilha.getFirstRowNum(), planilha.getLastRowNum(), 5); HSSFRow linha0 = planilha.createRow(0); linha0.createCell(0).setCellValue("Instituio Licitadora:"); planilha.addMergedRegion(new CellRangeAddress(0, 0, 0, 1)); linha0.createCell(2)//ww w.j a v a 2 s .c o m .setCellValue(" " + getEntidade().getInstituicaoLicitadora().getPessoaJuridica().getNomeFantasia()); planilha.addMergedRegion(new CellRangeAddress(0, 0, 2, 6)); HSSFRow linha1 = planilha.createRow(1); linha1.createCell(0).setCellValue("Numero do Pregao:"); planilha.addMergedRegion(new CellRangeAddress(1, 1, 0, 1)); linha1.createCell(2).setCellValue(" " + getEntidade().getNumeroPregao()); planilha.addMergedRegion(new CellRangeAddress(1, 1, 2, 6)); HSSFRow linha2 = planilha.createRow(2); linha2.createCell(0).setCellValue("Numero do Processo:"); planilha.addMergedRegion(new CellRangeAddress(2, 2, 0, 1)); linha2.createCell(2).setCellValue(" " + getEntidade().getNumeroProcesso()); planilha.addMergedRegion(new CellRangeAddress(2, 2, 2, 6)); HSSFRow linha3 = planilha.createRow(3); linha3.createCell(0).setCellValue("Empresa Licitante:"); planilha.addMergedRegion(new CellRangeAddress(3, 3, 0, 1)); linha3.createCell(2).setCellValue("Preencha com o nome de sua Empresa"); planilha.addMergedRegion(new CellRangeAddress(3, 3, 2, 6)); HSSFRow linha4 = planilha.createRow(4); //Nova coluna para a empresas adicionarem seus valores HSSFRow linha5 = planilha.getRow(5); HSSFCell celula5 = linha5.createCell(5); celula5.setCellValue("Valor do Licitante"); //for para ajustar automaticamente o tamnho das colunas for (int i = 0; i < 6; i++) { planilha.autoSizeColumn(i); } //Cor da linha de titulos da tabela HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); for (int i = 0; i < linha5.getPhysicalNumberOfCells(); i++) { HSSFCell cell = linha5.getCell(i); cell.setCellStyle(cellStyle); } CellStyle unlockedCellStyle = wb.createCellStyle(); unlockedCellStyle.setLocked(false); HSSFCell celula2 = linha3.getCell(2); celula2.setCellStyle(unlockedCellStyle); }
From source file:Calendar.Calendario.java
private void crearExcel(double[][] excel, String name) { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet(); HSSFRow fila; HSSFCell celda;//from w ww. j a v a 2s.com fila = hoja.createRow(2); celda = fila.createCell(3); HSSFRichTextString texto = new HSSFRichTextString("prueba"); celda.setCellValue(texto); celda = fila.createCell(4); celda.setCellValue("prueba2"); /* for (int i = 0; i < modelo.getColumnCount(); i++) { celda = fila.createCell(i); HSSFRichTextString texto = new HSSFRichTextString((String) (modelo.getColumnName(i))); celda.setCellValue(texto); } for (int i = 0; i < modelo.getRowCount(); i++) { fila = hoja.createRow(i + 1); for (int k = 0; k < modelo.getColumnCount(); k++) { celda = fila.createCell(k); HSSFRichTextString texto = new HSSFRichTextString((String) (modelo.getValueAt(i, k))); celda.setCellValue(texto); } }*/ FileOutputStream elFichero; try { elFichero = new FileOutputStream(name + ".xls"); libro.write(elFichero); elFichero.close(); JOptionPane.showMessageDialog(null, "Se genero la planilla correctamente"); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error al crear la planilla de Excel. Recuerde que el nombre del archivo no puede contener ninguno de los siguientes caracteres: \\ / : * ? \"< > | Intentelo nuevamente y si el problema persiste contacte con el administrador."); System.out.println(ex); System.exit(0); } }
From source file:ch.javasoft.metabolic.generate.ExcelGenerator.java
License:BSD License
protected static HSSFCell getCell(HSSFSheet sheet, int row, int col, boolean create) { HSSFRow xlsRow = sheet.getRow(row); if (xlsRow == null) { if (!create) return null; xlsRow = sheet.createRow(row);/* w ww.j ava2 s.co m*/ } HSSFCell xlsCell = xlsRow.getCell((short) col); if (xlsCell == null) { if (!create) return null; xlsCell = xlsRow.createCell((short) col); } return xlsCell; }
From source file:chocanproject.ServiceDetailsGUI.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/*from w w w. ja v a 2 s . c o m*/ Connection con = DriverManager.getConnection(connectionUrl); Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = "ChocAn.dbo.GetProviderDirectory_Select"; ResultSet rs = st.executeQuery(sql); //Create a blank workbook and sheet HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("NewSheet"); HSSFRow rowhead = sheet.createRow((short) 0); rowhead.createCell((short) 0).setCellValue("CellHeadName1"); rowhead.createCell((short) 1).setCellValue("CellHeadName2"); rowhead.createCell((short) 2).setCellValue("CellHeadName3"); int i = 1; while (rs.next()) { HSSFRow row = sheet.createRow((short) i); row.createCell((short) 0).setCellValue(rs.getString("ServiceDesc")); row.createCell((short) 1).setCellValue(Integer.toString(rs.getInt("ServiceID"))); row.createCell((short) 2).setCellValue(rs.getString("Cost")); i++; } String ProviderDirectory = "D:/Excel/ProviderDirectory.xls"; FileOutputStream fileOut = new FileOutputStream(ProviderDirectory); workbook.write(fileOut); JOptionPane.showMessageDialog(null, "Directory file has been sent to your email address successfully and saved a .xlsx file at local path D:/Excel/"); fileOut.close(); } catch (SQLException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:citibob.reports.PoiXlsWriter.java
License:Open Source License
/** Only copies formatting from col0 to col1, non-inclusive. */ void copyRow(HSSFRow r0, HSSFRow r1, int col0, int col1) { // Clear r1//from www. j a v a2 s . c o m int pcells = r1.getPhysicalNumberOfCells(); int pc = 0; for (int c = 0; pc < pcells; ++c) { HSSFCell c1 = r1.getCell((short) c); if (c1 == null) continue; ++pc; r1.removeCell(c1); } // Copy over cells from r0 pcells = r0.getPhysicalNumberOfCells(); pc = 0; for (int c = 0; pc < pcells; ++c) { HSSFCell c0 = r0.getCell((short) c); if (c0 == null) continue; ++pc; HSSFCell c1 = r1.createCell((short) c); if (c >= col0 && c < col1) copyCellFormatting(c0, c1); else copyCell(c0, c1); } }
From source file:citibob.reports.PoiXlsWriter.java
License:Open Source License
int replaceOneHolder(HSSFSheet sheet, int row, int col, Map<String, Object> models, String rsname) { // Do the replacement Object mod = (models.size() == 1 ? models.values().iterator().next() : models.get(rsname)); if (mod == null) return NOROWCHANGE; if (mod instanceof TableModel) return replaceOneHolder(sheet, row, col, (TableModel) mod); // It's just a simple item; put it in HSSFRow row0 = sheet.getRow(row); HSSFCell c0 = row0.getCell((short) col); HSSFComment comment = c0.getCellComment(); HSSFCellStyle style = c0.getCellStyle(); row0.removeCell(c0);/* w w w . j av a 2 s .c o m*/ HSSFCell c1 = row0.createCell((short) col); if (comment != null) c1.setCellComment(comment); if (style != null) c1.setCellStyle(style); setValue(c1, mod); return NOROWCHANGE; }