List of usage examples for org.apache.poi.hpsf HPSFException HPSFException
public HPSFException(final Throwable reason)
Creates a new HPSFException with a reason.
From source file:Console.java
static public void exportToExcel(String sheetName, ArrayList headers, ArrayList data, File outputFile) throws HPSFException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(sheetName); int rowIdx = 0; short cellIdx = 0; // Header//from w ww. j av a 2 s . com HSSFRow hssfHeader = sheet.createRow(rowIdx); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); for (Iterator cells = headers.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfHeader.createCell(cellIdx++); hssfCell.setCellStyle(cellStyle); hssfCell.setCellValue((String) cells.next()); } // Data rowIdx = 1; for (Iterator rows = data.iterator(); rows.hasNext();) { ArrayList row = (ArrayList) rows.next(); HSSFRow hssfRow = sheet.createRow(rowIdx++); cellIdx = 0; for (Iterator cells = row.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfRow.createCell(cellIdx++); Object o = cells.next(); if ("class java.lang.Double".equals(o.getClass().toString())) { hssfCell.setCellValue((Double) o); } else { hssfCell.setCellValue((String) o); } } } wb.setSheetName(0, sheetName); try { FileOutputStream outs = new FileOutputStream(outputFile); wb.write(outs); outs.close(); // System.out.println("Archivo creado correctamente en " + outputFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); throw new HPSFException(e.getMessage()); } }
From source file:org.ddt.listener.dsi.HeadingPairVector.java
License:Apache License
/** * Populate the HeadingPairVector from the byte array. * * @param data byte array to read from * @param offset offset into byte array to start at. *//*w ww.ja va 2 s . co m*/ private void read(byte[] data, int offset) throws HPSFException, UnsupportedEncodingException { int off = offset; count = (int) LittleEndian.getUInt(data, off); if ((count % 2) != 0) { throw new HPSFException("The count of a HeadingPairVector must be even."); } count = count / 2; off += LittleEndian.INT_SIZE; log.log(Level.FINE, "{0} headers found", count); props = new HeadingPairProperty[count]; int docOffset = 0; for (int i = 0; i < count; i++) { props[i] = new HeadingPairProperty(data, off, docOffset); docOffset += props[i].getPartsCount(); off += props[i].getSize(); } }
From source file:support.Library.java
public void exportToExcel(String sheetName, ArrayList headers, ArrayList data, String fileName) throws HPSFException { final JFileChooser jfc = new JFileChooser(hms.HMS101.currentDirectory); final JTextField jf = new JTextField(); jfc.addActionListener(new ActionListener() { @Override//w ww . java 2s . c om public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equalsIgnoreCase("ApproveSelection")) { jf.setText(jfc.getSelectedFile().getAbsolutePath()); } else { jf.setText(""); return; } } }); jfc.setCurrentDirectory(new File(hms.HMS101.currentDirectory)); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Select Destination Folder"); jfc.setApproveButtonText("Select"); jfc.showOpenDialog(null); if (!jf.getText().isEmpty()) { File f1 = new File(jf.getText() + File.separatorChar + sheetName.replaceAll(".jasper", "") + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(sheetName); int rowIdx = 0; short cellIdx = 0; // Header HSSFRow hssfHeader = sheet.createRow(rowIdx); HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); for (Iterator cells = headers.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfHeader.createCell(cellIdx++); hssfCell.setCellStyle(cellStyle); hssfCell.setCellValue((String) cells.next()); } // Data rowIdx = 1; for (Iterator rows = data.iterator(); rows.hasNext();) { ArrayList row = (ArrayList) rows.next(); HSSFRow hssfRow = sheet.createRow(rowIdx++); cellIdx = 0; for (Iterator cells = row.iterator(); cells.hasNext();) { HSSFCell hssfCell = hssfRow.createCell(cellIdx++); hssfCell.setCellValue(cells.next() + ""); } } wb.setSheetName(0, sheetName); try { FileOutputStream outs = new FileOutputStream(f1); wb.write(outs); outs.close(); confirmDialog(f1.getAbsolutePath() + " has been generated successfully."); if (type) { Desktop.getDesktop().open(f1); } } catch (IOException e) { throw new HPSFException(e.getMessage()); } } }