List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook
public HSSFWorkbook()
From source file:br.sp.telesul.service.ExportServiceImpl.java
@Override public void singleReport(Long id, HttpServletRequest request, HttpServletResponse response) { HSSFWorkbook workbook = new HSSFWorkbook(); writeExcelSingle(id, workbook);// w ww .j av a2 s .c o m downloadExcel(request, response, workbook); }
From source file:br.ufal.cideei.util.count.MetricsTable.java
License:Open Source License
public MetricsTable(File output) throws FileNotFoundException, IOException, InvalidFormatException { MAX_SIZE = Integer.MAX_VALUE; this.output = output; if (output.exists()) { workBook = WorkbookFactory.create(new FileInputStream(output)); } else {/* w w w.j av a2s .co m*/ workBook = new HSSFWorkbook(); } this.sheet = workBook.createSheet(); }
From source file:br.ufal.cideei.util.count.SummaryBuilder.java
License:Open Source License
public static void buildSummary(String splShortName) throws InvalidFormatException, FileNotFoundException, IOException { // final String userHomeFolder = System.getProperty("user.home").substring(3); String userHomeFolder = "C:\\tst"; final String output = userHomeFolder + File.separator + "summ.xls"; File outputFile = new File(output); Workbook outputWorkbook;/*from w w w.j a v a 2 s . c om*/ if (!outputFile.exists()) { outputFile.createNewFile(); outputWorkbook = new HSSFWorkbook(); } else { FileInputStream inputFileStream = new FileInputStream(outputFile); outputWorkbook = WorkbookFactory.create(inputFileStream); } { List<String> referencesForRDA3 = new ArrayList<String>(); List<String> referencesForUVA3 = new ArrayList<String>(); List<String> referencesForRDA2 = new ArrayList<String>(); List<String> referencesForUVA2 = new ArrayList<String>(); String fileName = "fs-" + splShortName + ".xls"; String filePath = userHomeFolder + File.separator; String fullFileName = filePath + File.separator + "fs-" + splShortName + ".xls"; Workbook workbook = WorkbookFactory.create(new FileInputStream(new File(fullFileName))); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); Row headerRow = sheet.getRow(0); for (Cell cell : headerRow) { String stringCellValue = cell.getStringCellValue(); if (stringCellValue.equals("rd")) { Row sumRow = sheet.getRow(sheet.getLastRowNum() - 1); Cell sumCell = sumRow.getCell(i); CellReference sumCellRef = new CellReference(sumCell); String cellRefForAnotherSheet = "\'" + filePath + "[" + fileName + "]Sheet" + i + "\'!" + sumCellRef.formatAsString(); referencesForRDA2.add(cellRefForAnotherSheet); } else if (stringCellValue.equals("uv")) { Row sumRow = sheet.getRow(sheet.getLastRowNum() - 1); Cell sumCell = sumRow.getCell(i); CellReference sumCellRef = new CellReference(sumCell); String cellRefForAnotherSheet = "\'" + filePath + "[" + fileName + "]Sheet" + i + "\'!" + sumCellRef.formatAsString(); referencesForUVA2.add(cellRefForAnotherSheet); } else if (stringCellValue.equals("rd (a3)")) { Row sumRow = sheet.getRow(sheet.getLastRowNum() - 1); Cell sumCell = sumRow.getCell(i); CellReference sumCellRef = new CellReference(sumCell); String cellRefForAnotherSheet = "\'" + filePath + "[" + fileName + "]Sheet" + i + "\'!" + sumCellRef.formatAsString(); referencesForRDA3.add(cellRefForAnotherSheet); } else if (stringCellValue.equals("uv (a3)")) { Row sumRow = sheet.getRow(sheet.getLastRowNum() - 1); Cell sumCell = sumRow.getCell(i); CellReference sumCellRef = new CellReference(sumCell); String cellRefForAnotherSheet = "\'" + filePath + "[" + fileName + "]Sheet" + i + "\'!" + sumCellRef.formatAsString(); referencesForUVA3.add(cellRefForAnotherSheet); } } } if (outputWorkbook.getSheet(splShortName) != null) { outputWorkbook.removeSheetAt(outputWorkbook.getSheetIndex(splShortName)); } Sheet outputSheet = outputWorkbook.createSheet(splShortName); Row RDA2Row = outputSheet.createRow(0); RDA2Row.createCell(0).setCellValue("RD A2"); for (int i = 0; i < referencesForRDA2.size(); i++) { Cell createdCell = RDA2Row.createCell(i + 1); System.out.println(referencesForRDA2.get(i)); createdCell.setCellType(Cell.CELL_TYPE_FORMULA); createdCell.setCellValue(referencesForRDA2.get(i)); } Row UVA2Row = outputSheet.createRow(1); UVA2Row.createCell(0).setCellValue("UV A2"); for (int i = 0; i < referencesForUVA2.size(); i++) { Cell createdCell = UVA2Row.createCell(i + 1); createdCell.setCellFormula(referencesForUVA2.get(i)); } Row RDA3Row = outputSheet.createRow(2); RDA3Row.createCell(0).setCellValue("RD A3"); for (int i = 0; i < referencesForRDA3.size(); i++) { Cell createdCell = RDA3Row.createCell(i + 1); createdCell.setCellFormula(referencesForRDA3.get(i)); } Row UVA3Row = outputSheet.createRow(3); UVA3Row.createCell(0).setCellValue("UV A3"); for (int i = 0; i < referencesForUVA3.size(); i++) { Cell createdCell = UVA3Row.createCell(i + 1); createdCell.setCellFormula(referencesForUVA3.get(i)); } } FileOutputStream fileOutputStream = new FileOutputStream(outputFile); outputWorkbook.write(fileOutputStream); fileOutputStream.close(); }
From source file:br.ufpa.psi.comportamente.labgame.mbeans.RelatoriosMB.java
License:Open Source License
public StreamedContent geraRelatorioJogadasExperimento() throws ParsePropertyException, IOException, InvalidFormatException { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Relatrio das Jogadas"); sheet.setColumnWidth(sheet.getFirstRowNum(), (14 * 256) + 200); sheet.setColumnWidth(1, (14 * 256) + 200); sheet.setColumnWidth(4, (17 * 256) + 200); sheet.setColumnWidth(5, (16 * 256) + 200); HSSFCellStyle cs1 = workbook.createCellStyle(); cs1.setDataFormat(HSSFDataFormat.getBuiltinFormat("d-mmm-yy")); HSSFCellStyle cs2 = workbook.createCellStyle(); cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("h:mm:ss")); JogadaDAO jogadaDAO = new JogadaDAO(); jogadaDAO.beginTransaction();// w w w. java2s . com List<Jogada> jogadas = jogadaDAO.encontrarPorExperimento(experimentoSelecionado.getId()); int countRow = 0; Row row1 = sheet.createRow(countRow++); Cell cell = row1.createCell(0); cell.setCellValue("Experimento: " + experimentoSelecionado.getNome()); Row row = sheet.createRow(countRow++); row.createCell(0).setCellValue("Data da Jogada"); row.createCell(1).setCellValue("Hora da Jogada"); row.createCell(2).setCellValue("Coluna"); row.createCell(3).setCellValue("Linha"); row.createCell(4).setCellValue("Pontuacao Individual"); row.createCell(5).setCellValue("Pontuacao Coletiva"); row.createCell(6).setCellValue("Participante"); row.createCell(7).setCellValue("Condio"); for (Jogada jogada : jogadas) { Row nrow = sheet.createRow(countRow++); //Data Cell ncell0 = nrow.createCell(0); ncell0.setCellValue(jogada.getMomento()); ncell0.setCellStyle(cs1); //Hora Cell ncell1 = nrow.createCell(1); ncell1.setCellValue(jogada.getMomento()); ncell1.setCellStyle(cs2); //Coluna Cell ncell2 = nrow.createCell(2); ncell2.setCellValue(jogada.getColunaSelecionada()); //Linha Cell ncell3 = nrow.createCell(3); ncell3.setCellValue(jogada.getLinhaSelecionada()); //Pontuao Individual Cell ncell4 = nrow.createCell(4); ncell4.setCellValue(jogada.getPontuacaoIndividual()); //Pontuao Coletiva Cell ncell5 = nrow.createCell(5); ncell5.setCellValue(jogada.getPontuacaoCultural()); //Jogador Cell ncell6 = nrow.createCell(6); ncell6.setCellValue(jogada.getJogador().getNome()); //Id da Condio Cell ncell7 = nrow.createCell(7); ncell7.setCellValue(jogada.getIdCondicao()); } jogadaDAO.stopOperation(false); byte[] bytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { workbook.write(out); bytes = out.toByteArray(); } InputStream ioStream = new ByteArrayInputStream(bytes); file = new DefaultStreamedContent(ioStream, "application/vnd.ms-excel", "Relatrio_Jogadas.xls"); return file; }
From source file:br.ufpa.psi.comportamente.labgame.relatorios.RelatorioGrafico.java
License:Open Source License
public InputStream estatisticaJogadas(List<Jogada> jogadas) throws ParsePropertyException, IOException, InvalidFormatException { TipoJogada jogadaPontCult = new TipoJogada("Pontuao Cultural", 0); TipoJogada jogadaPontIndiv = new TipoJogada("Pontuao Individual", 0); TipoJogada jogadaSemPont = new TipoJogada("Sem Pontuao", 0); for (Jogada jogada : jogadas) { int cont = 0; if (jogada.getPontuacaoCultural() > 0) { cont++;/* w w w .j av a 2s.c o m*/ jogadaPontCult.total++; } if (jogada.getPontuacaoIndividual() > 0) { cont++; jogadaPontIndiv.total++; } if (cont == 0) { jogadaSemPont.total++; } } HSSFWorkbook workbook = new HSSFWorkbook(); List<TipoJogada> listaTipoJogadas = new ArrayList<>(); listaTipoJogadas.add(jogadaSemPont); listaTipoJogadas.add(jogadaPontCult); listaTipoJogadas.add(jogadaPontIndiv); Map beans = new HashMap(); beans.put("jogadas", listaTipoJogadas); XLSTransformer transformer = new XLSTransformer(); InputStream ioStream = RelatorioGrafico.class.getClassLoader().getResourceAsStream( "br/ufpa/psi/comportamente/labgame/relatorios/templates/Template_Chart_Pontuacao.xls"); transformer.markAsFixedSizeCollection("jogadas"); byte[] bytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { workbook = (HSSFWorkbook) transformer.transformXLS(ioStream, beans); workbook.write(out); bytes = out.toByteArray(); } InputStream in = new ByteArrayInputStream(bytes); return in; }
From source file:bs.global.util.ExcelFactory.java
public ExcelFactory(ResultSet resultSet, FormatType[] formatTypes, String sheetName) { workbook = new HSSFWorkbook(); this.resultSet = resultSet; sheet = workbook.createSheet(sheetName); boldFont = workbook.createFont();//from w ww . j a va2 s . co m boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); format = workbook.createDataFormat(); this.formatTypes = formatTypes; }
From source file:Calendar.Calendario.java
private void crearExcel(double[][] excel, String name) { HSSFWorkbook libro = new HSSFWorkbook(); HSSFSheet hoja = libro.createSheet(); HSSFRow fila;// w w w . ja v a 2s.co m HSSFCell celda; 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:campmanager.CampUI.java
public void exportToExcel() { JFrame parentFrame = new JFrame(); File fileToSave = null;/*www . j av a 2 s . c o m*/ ; JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Export to Excel"); int userSelection = fileChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { fileToSave = fileChooser.getSelectedFile(); // System.out.println("Save as file: " + fileToSave.getAbsolutePath()); } if (fileToSave != null) { String fileName = fileToSave.getAbsolutePath(); if (!fileName.endsWith(".xls")) fileName += ".xls"; try { DefaultTableModel dtm = (DefaultTableModel) jTable_records.getModel(); Workbook wb = new HSSFWorkbook(); CreationHelper createhelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet("new sheet"); Row row = null; Cell cell = null; row = sheet.createRow(0); HSSFFont font = (HSSFFont) wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle style = (HSSFCellStyle) wb.createCellStyle(); style.setFont(font); for (int t = 0; t < dtm.getColumnCount() - 1; t++) { cell = row.createCell(t); cell.setCellStyle(style); cell.setCellValue(dtm.getColumnName(t)); } HSSFCellStyle style_gray = (HSSFCellStyle) wb.createCellStyle(); style_gray.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); // style_gray.setFillPattern(CellStyle.ALT_BARS); for (int i = 1; i <= dtm.getRowCount(); i++) { row = sheet.createRow(i); for (int j = 0; j < dtm.getColumnCount() - 1; j++) { cell = row.createCell(j); if (i % 2 == 0) cell.setCellStyle(style_gray); cell.setCellValue(dtm.getValueAt(i - 1, j).toString()); } } FileOutputStream out = new FileOutputStream(fileName); wb.write(out); out.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:ch.dbs.actions.reports.HoldingsReport.java
License:Open Source License
private HSSFWorkbook getXLSContent(final Konto k) { final Text cn = new Text(); final Workbook wb = new HSSFWorkbook(); final Sheet s = wb.createSheet(); try {/*from w w w. j a v a 2 s. c o m*/ // add header for XLS initXLS(wb, s); // internal holdings are visible final List<Bestand> stock = new Bestand().getAllKontoBestand(k.getId(), true, cn.getConnection()); short rowNr = 0; for (final Bestand b : stock) { rowNr++; // add holdings getXLSLine(wb, s, b, rowNr); } // adjust all columns in size short columnNr = 0; while (columnNr < 21) { s.autoSizeColumn(columnNr); columnNr++; } } finally { cn.close(); } return (HSSFWorkbook) wb; }
From source file:ch.dbs.actions.reports.KbartReport.java
License:Open Source License
private HSSFWorkbook getXLSContent(final Konto k) { final Text cn = new Text(); final Workbook wb = new HSSFWorkbook(); final Sheet s = wb.createSheet(); try {//from w w w .j a va2 s .c o m // add header for XLS initXLS(wb, s); // internal holdings are visible final List<Bestand> stock = new Bestand().getAllKontoBestand(k.getId(), true, cn.getConnection()); // transform to KbartForm final KbartForm kbf = new KbartForm(); final List<KbartForm> kbarts = kbf.createKbartForms(stock, cn.getConnection()); short rowNr = 0; for (final KbartForm kbart : kbarts) { rowNr++; // add holdings getXLSLine(wb, s, kbart, rowNr); } // adjust all columns in size short columnNr = 0; while (columnNr < 16) { s.autoSizeColumn(columnNr); columnNr++; } } finally { cn.close(); } return (HSSFWorkbook) wb; }