List of usage examples for org.apache.poi.ss.usermodel Workbook write
void write(OutputStream stream) throws IOException;
From source file:cartel.DynamicDegreeCalculation.java
License:Open Source License
public void compute(Graph graph) throws FileNotFoundException, IOException { Map<String, Integer> weightedDegreeForOneCountryfForOneYear; Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet("weighted degree"); Row row;//from ww w . j a v a2 s . c om Cell cell; Map<String, Integer> countryIndices = new TreeMap(); int index = 0; for (String country : CartelDynamic.europeanCountries) { index++; countryIndices.put(country, index); } //COLUMNS HEADER row = sheet.createRow((short) 0); index = 1; for (int i = 1948; i < 2009; i++) { cell = row.createCell(index); index++; cell.setCellValue(String.valueOf(i)); } //CREATING EMPTY CELLS FOR EACH ROW for (String country : countryIndices.keySet()) { row = sheet.createRow((countryIndices.get(country))); index = 0; for (int i = 1948; i <= 2009; i++) { row.createCell(index); index++; } } //FILLING FIRST COLUMN WITH COUNTRIES for (String country : countryIndices.keySet()) { row = sheet.getRow(countryIndices.get(country)); row.getCell(0).setCellValue(country); } int indexYear = 1; for (int i = 1948; i < 2009; i++) { weightedDegreeForOneCountryfForOneYear = new TreeMap(); for (Node node : graph.getNodes()) { String nodeLabel = node.getLabel(); int sumDegrees = 0; for (Edge edge : graph.getAllEdges()) { if (!edge.getSource().getLabel().equals(nodeLabel) & !edge.getTarget().getLabel().equals(nodeLabel)) { continue; } if (edge.getSource().getLabel().equals(edge.getTarget().getLabel())) { continue; } AttributeValueList attributeValueList = edge.getAttributeValues(); for (AttributeValue attributeValue : attributeValueList) { if (!attributeValue.getAttribute().getTitle().equals("freq")) { continue; } if (((Integer) attributeValue.getStartValue()) != i) { continue; } sumDegrees = sumDegrees + Integer.parseInt(attributeValue.getValue()); } } sumDegrees = sumDegrees / 2; row = sheet.getRow(countryIndices.get(nodeLabel)); cell = row.getCell(indexYear); cell.setCellValue(String.valueOf(sumDegrees)); } indexYear++; } String pathFile = "D:/workbook weighted degree.xlsx"; FileOutputStream fileOut = new FileOutputStream(pathFile); wb.write(fileOut); fileOut.close(); }
From source file:ch.bfh.lca._15h.library.export.ExportToExcel.java
/*** * Generate an Excel file based on a list of results. * Use the name of the fields described in the GenericResultRow to label the columns. * @param language Language of the label in the Excel file * @param sheetTitle Title of the sheet in the Excel file * @param tableTitle Title of the table in the Excel file * @param rows Arrays of rows to include in the listing * @param excelFilePath Path of the outputed file * @throws FileNotFoundException/* w ww.jav a 2s. c o m*/ * @throws IOException */ public static void exportToExcel(Translation.TRANSLATION_LANGUAGE language, String sheetTitle, String tableTitle, GenericResultRow[] rows, String excelFilePath) throws FileNotFoundException, IOException { //Workbook wb = new HSSFWorkbook(); //xls Workbook wb = new SXSSFWorkbook(); //xlsx //create new sheet Sheet sheet1 = wb.createSheet(sheetTitle); Row row; Cell cell; String translation; int rowIndex = 0; //add title row = sheet1.createRow((short) rowIndex); cell = row.createCell(0); cell.setCellValue(tableTitle); CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setFontHeightInPoints((short) 24); //font.setFontName("Courier New"); style.setFont(font); cell.setCellStyle(style); //add rows for (int i = 0; i < rows.length; i++) { //if first line, write col names if (i == 0) { row = sheet1.createRow((short) rowIndex + 2); for (int j = 0; j < rows[i].getColNames().length; j++) { cell = row.createCell(j); //look for translation translation = Translation.getForKey(language, rows[i].getColNames()[j]); if (translation == null) { translation = rows[i].getColNames()[j]; //if doesn't found a translation for the column take name of col } cell.setCellValue(translation); } } row = sheet1.createRow((short) (rowIndex + i + 3)); for (int j = 0; j < rows[i].getColNames().length; j++) { cell = row.createCell(j); cell.setCellValue(rows[i].getValueAt(j).toString()); } } //write to the file FileOutputStream fileOut = new FileOutputStream(excelFilePath); wb.write(fileOut); fileOut.close(); wb.close(); }
From source file:ch.emad.business.schuetu.xls.ToXLSDumper2.java
License:Apache License
protected byte[] convertModelToXLS(List<Mannschaft> mannschaftenIn, List<Spiel> spieleIn, List<Korrektur> korrekturenIn, List<DBAuthUser> usersIn, List<File> filesIn, List<Text> texteIn, List<Penalty> penaltyIn, List<Kontakt> kontakteIn) { List<Spiel> spiele = spieleIn; List<Mannschaft> mannschaften = mannschaftenIn; List<Korrektur> korrekturen = korrekturenIn; List<DBAuthUser> users = usersIn; List<File> file2s = filesIn; List<Text> texte = texteIn; List<Penalty> penaltys = penaltyIn; List<Kontakt> kontakte = kontakteIn; if (spiele == null) { spiele = new ArrayList(); } else {/*from ww w.j a va2 s . c o m*/ // setze dummy Mannschaften fuer das speichern der Finale Mannschaft m = new Mannschaft(); m.setId(0l); for (Spiel s : spiele) { if (s.getMannschaftA() == null) { s.setMannschaftA(m); } if (s.getMannschaftB() == null) { s.setMannschaftB(m); } } } Collections.sort(spiele, new SpielZeitComperator()); if (mannschaften == null) { mannschaften = new ArrayList(); } if (korrekturen == null) { korrekturen = new ArrayList(); } if (users == null) { korrekturen = new ArrayList(); } if (file2s == null) { file2s = new ArrayList(); } if (texte == null) { texte = new ArrayList(); } if (penaltys == null) { penaltys = new ArrayList(); } if (kontakte == null) { kontakte = new ArrayList(); } Map beans = new HashMap(); beans.put("mannschaften", mannschaften); beans.put("spiele", spiele); beans.put("korrekturen", korrekturen); beans.put("users", users); beans.put("attachements", file2s); beans.put("texte", texte); beans.put("penaltys", penaltys); beans.put("kontakte", kontakte); XLSTransformer transformer = new XLSTransformer(); byte[] arr = readFreshTemplate(); try { InputStream is = new ByteArrayInputStream(arr); Workbook wb = WorkbookFactory.create(is); transformer.transformWorkbook(wb, beans); ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); return out.toByteArray(); } catch (Exception e) { LOG.error(e.getMessage(), e); } return null; }
From source file:ch.scheduled.java
public void output() throws FileNotFoundException, IOException { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("Schedule"); int count = 0; for (int i = 0; i < Courses.size(); ++i) { Course temp = Courses.get(i);//w ww . j a v a 2 s . co m if (temp.isScheduled() == true) { Row row = sheet.createRow((short) count); row.createCell(0).setCellValue(temp.getNumber()); row.createCell(2).setCellValue(temp.getSession().getDay()); row.createCell(3).setCellValue(temp.getSession().getSlot()); ++count; } } FileOutputStream fileOut = new FileOutputStream("Final$Exam.xls"); wb.write(fileOut); fileOut.close(); }
From source file:chronostone.parser.ChronoStoneParser.java
public static void main(String[] args) throws FileNotFoundException, IOException { String rutaArchivo = System.getProperty("user.home") + "/ChronoStoneSheet.xls"; File archivoXLS = new File(rutaArchivo); if (archivoXLS.exists() == false) { try {//www . j a va 2 s . c o m archivoXLS.createNewFile(); } catch (IOException ex) { System.err.println("Error on creating XLS"); } } Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Chrono Stone Sheet"); /** * Codigo a remover o investigar como hacerlo funcionar de verdad */ int check = check_created(hoja); if (check == xls_index) { inicializar_celdas(hoja); } else { xls_index = check + 1; } String name = ""; System.out.println("Archivo creado: " + rutaArchivo); System.out.println("Introduzca nombre"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); name = br.readLine(); while (!name.equalsIgnoreCase("exit")) { try { tenmakun = new Character(name); name = name.replace(" ", "_"); URLConnection connection = null; connection = new URL(root + name).openConnection(); BufferedReader bf = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = ""; while ((line = bf.readLine()) != null) { if (line.contains(ONE_STATS) || line.contains(TWO_STATS) || line.contains(AURA_HTML)) { //Primero los stats List<String> stats = new ArrayList<>(); for (int index = 0; index < 13; index++) { stats.add(bf.readLine()); } add_stats(stats); //Y ahora a por las habilidades //add_hissatsu(stats); } else if (line.contains("<a href=\"/wiki/Category:Midfielders\"")) { tenmakun.setPosition(MF); } else if (line.contains("<a href=\"/wiki/Category:Forwards\"")) { tenmakun.setPosition(FW); } else if (line.contains("<a href=\"/wiki/Category:Defenders\"")) { tenmakun.setPosition(DF); } else if (line.contains("<a href=\"/wiki/Category:Goalkeepers\"")) { tenmakun.setPosition(GK); } } } catch (Exception ex) { ex.printStackTrace(); } System.out.println(tenmakun.print_stats()); add_character_sheet(hoja); System.out.println("Personaje aadido al fichero"); System.out.println("Introduzca nombre"); name = br.readLine(); } libro.write(archivo); archivo.close(); libro.close(); }
From source file:cl.a2r.wsmicampov2.common.utils.Excel.java
public static void GenerateExcel(String fileUrl, String sheetName, List<Integer> dataList) { File archivo = new File(fileUrl); Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(sheetName); int rowNum = 1; for (Integer data : dataList) { Row row = sheet.createRow(rowNum++); row.createCell(0).setCellValue(data); }//from w w w .j a v a 2 s.c o m try { FileOutputStream salida = new FileOutputStream(archivo); workbook.write(salida); workbook.close(); } catch (FileNotFoundException ex) { AppLog.logInfo(ex.getMessage(), ex); } catch (IOException ex) { AppLog.logInfo(ex.getMessage(), ex); } catch (Exception ex) { AppLog.logInfo(ex.getMessage(), ex); } }
From source file:clases.Funciones.java
private String GenerateReporte_xls(JTable t, int open) { String rutaArchivo = ""; try {/*from w w w. j av a 2s . c o m*/ char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + rutaArchivo + "_" + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls"; } else { rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + rutaArchivo + "_" + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls"; } File archivoXLS = new File(rutaArchivo); if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet(ReturnDatosFisicos(this.Datos_Nombre)); for (int f = 0; f < t.getRowCount() + 1; f++) { Row fila = hoja.createRow(f); for (int c = 0; c < t.getColumnCount(); c++) { Cell celda = fila.createCell(c); if (f == 0) { celda.setCellValue(String.valueOf(t.getColumnName(c))); } else { celda.setCellValue(String.valueOf(t.getValueAt(f - 1, c))); } hoja.autoSizeColumn(c); } } libro.write(archivo); archivo.close(); if (open > 0) { Desktop.getDesktop().open(archivoXLS); } } catch (IOException ex) { Alert(ex.getMessage()); } return rutaArchivo; }
From source file:Clientes.editaCliente.java
private void bt_actualiza2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza2ActionPerformed // TODO add your handling code here: javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null;/*from w ww . j a va 2 s. com*/ if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { File archivoXLS = new File(ruta + ".xls"); try { if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Clientes"); for (int ren = 0; ren < (t_datos.getRowCount() + 1); ren++) { Row fila = hoja.createRow(ren); for (int col = 0; col < t_datos.getColumnCount(); col++) { Cell celda = fila.createCell(col); if (ren == 0) { celda.setCellValue(columnas[col]); } else { try { celda.setCellValue(t_datos.getValueAt(ren - 1, col).toString()); } catch (Exception e) { celda.setCellValue(""); } } } } libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte"); } } } }
From source file:cn.afterturn.easypoi.excel.imports.base.ImportBaseService.java
License:Apache License
public void saveThisExcel(ImportParams params, Class<?> pojoClass, boolean isXSSFWorkbook, Workbook book) throws Exception { String path = getSaveExcelUrl(params, pojoClass); File savefile = new File(path); if (!savefile.exists()) { savefile.mkdirs();/*from w w w. j a v a 2 s. c o m*/ } SimpleDateFormat format = new SimpleDateFormat("yyyMMddHHmmss"); FileOutputStream fos = new FileOutputStream(path + File.separator + format.format(new Date()) + "_" + Math.round(Math.random() * 100000) + (isXSSFWorkbook == true ? ".xlsx" : ".xls")); book.write(fos); IOUtils.closeQuietly(fos); }
From source file:cn.afterturn.easypoi.view.MiniAbstractExcelView.java
License:Apache License
public void out(Workbook workbook, String codedFileName, HttpServletRequest request, HttpServletResponse response) throws Exception { if (workbook instanceof HSSFWorkbook) { codedFileName += HSSF;//from w w w. j a va2 s .c o m } else { codedFileName += XSSF; } // ??RFC 5987??header, UA response.setHeader("content-disposition", WebFilenameUtils.disposition(codedFileName)); ServletOutputStream out = response.getOutputStream(); workbook.write(out); out.flush(); }