List of usage examples for org.apache.poi.openxml4j.opc OPCPackage open
public static OPCPackage open(InputStream in) throws InvalidFormatException, IOException
From source file:gob.osinergmin.inpsweb.service.business.impl.PlantillaResultadoServiceNegImpl.java
private XWPFDocument armarPlantilla(PlantillaResultadoDTO plantilla, Long idSupervision) throws PlantillaResultadoException { LOG.info("armarPlantilla"); XWPFDocument document = null;//from ww w .j av a2s. co m try { String direccion = RUTA_PLANTILLAS + plantilla.getCarpeta() + plantilla.getNombreDocumento(); FileInputStream fis = new FileInputStream(direccion); document = new XWPFDocument(OPCPackage.open(fis)); fis.close(); Map<String, Map<String, Object>> datos = null; if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_UNO)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaUno(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_DOS)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaDos(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_TRES)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaTres(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_CUATRO)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaCuatro(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_CINCO)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaCinco(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_SEIS)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaSeis(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_SIETE)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaSiete(idSupervision); } else if (plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_OCHO) || //mdiosesf - RSIS5 plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_NUEVE) || plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_DIEZ) || plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_ONCE) || plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_DOCE) || plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_TRECE) || plantilla.getIdentificadorPlantilla().equals(Constantes.IDENT_PLANTILLA_CATORCE)) { datos = datoPlantillaServiceNeg.obtenerDatosPlantillaNoSupervisada(idSupervision); } else { throw new PlantillaResultadoException("Plantilla no existe", null); } document = Utiles.Poi.actualizaPlantilla(document, datos); } catch (Exception ex) { LOG.error("armaPlantilla", ex); throw new PlantillaResultadoException(ex.getMessage(), ex); } return document; }
From source file:gospl.io.XlsxInputHandler.java
protected XlsxInputHandler(final String fileName, final int sheetNumber, int firstRowDataIndex, int firstColumnDataIndex, GSSurveyType dataFileType) throws FileNotFoundException, IOException, InvalidFormatException { super(fileName, firstRowDataIndex, firstColumnDataIndex, dataFileType); wb = new XSSFWorkbook(OPCPackage.open(new FileInputStream(fileName))); this.setCurrentSheet(wb.getSheetAt(sheetNumber)); }
From source file:gospl.io.XlsxInputHandler.java
protected XlsxInputHandler(final File file, int sheetNumber, int firstRowDataIndex, int firstColumnDataIndex, GSSurveyType dataFileType) throws FileNotFoundException, IOException { super(file.getPath(), firstRowDataIndex, firstColumnDataIndex, dataFileType); try {/*w ww. j a va 2 s.c o m*/ wb = new XSSFWorkbook(OPCPackage.open(new FileInputStream(file))); } catch (final InvalidFormatException e) { throw new RuntimeException(e.getMessage()); } this.setCurrentSheet(wb.getSheetAt(sheetNumber)); }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static String getCreator(File file) { String author = null;/*from ww w . java2 s .co m*/ try { OPCPackage pkg = OPCPackage.open(file); POIXMLProperties props = new POIXMLProperties(pkg); POIXMLProperties.CoreProperties core_properties = props.getCoreProperties(); author = core_properties.getCreator(); pkg.close(); } catch (Exception ex) { ex.printStackTrace(); } return author; }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static void setCreator(File file, String author) { try {//from w w w. ja va 2s . c o m OPCPackage pkg = OPCPackage.open(file); POIXMLProperties props = new POIXMLProperties(pkg); POIXMLProperties.CoreProperties core_properties = props.getCoreProperties(); core_properties.setCreator(author); pkg.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static String getPOISummaryData(String filename, String key) { String value = null;//from ww w . java 2 s . c o m OPCPackage pkg = null; try { pkg = OPCPackage.open(new File(filename)); POIXMLProperties props = new POIXMLProperties(pkg); POIXMLProperties.CoreProperties core_properties = props.getCoreProperties(); if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) { value = core_properties.getCreator(); } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) { value = core_properties.getKeywords(); } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) { value = core_properties.getTitle(); } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) { value = core_properties.getSubject(); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { pkg.close(); } catch (Exception ex) { ex.printStackTrace(); } } return value; }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static void setPOISummaryData(String filename, String key, String value) { OPCPackage pkg = null;/* w w w .j a v a 2 s. c o m*/ try { pkg = OPCPackage.open(new File(filename)); POIXMLProperties props = new POIXMLProperties(pkg); POIXMLProperties.CoreProperties core_properties = props.getCoreProperties(); if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) { core_properties.setCreator(value); } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) { core_properties.setKeywords(value); } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) { core_properties.setTitle(value); } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) { core_properties.setSubjectProperty(value); } } catch (Exception ex) { //ex.printStackTrace(); } finally { try { pkg.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java
License:Open Source License
public static void setPOISummaryData(String filename, String[] keys, String[] values) { OPCPackage pkg = null;//from w ww.ja va 2 s .com try { pkg = OPCPackage.open(new File(filename)); POIXMLProperties props = new POIXMLProperties(pkg); POIXMLProperties.CoreProperties core_properties = props.getCoreProperties(); for (int i = 0; i < keys.length; i++) { String key = keys[i]; String value = values[i]; if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) { core_properties.setCreator(value); } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) { core_properties.setKeywords(value); } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) { core_properties.setTitle(value); } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) { core_properties.setSubjectProperty(value); } } } catch (Exception ex) { ex.printStackTrace(); } finally { try { pkg.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:graphbuilder.ExcelParser.java
public static List<Map<String, Object>> loadExcelFile(File file) { List<Map<String, Object>> records = new LinkedList(); OPCPackage pkg = null;/* w w w. jav a2s. c o m*/ try { pkg = OPCPackage.open(file); XSSFWorkbook wb = new XSSFWorkbook(pkg); Sheet sheet = wb.getSheetAt(0); List<String> schema = null; for (Row row : sheet) { if (schema == null) { schema = new LinkedList(); for (Cell cell : row) { schema.add("" + loadCellData(cell)); } } else { Map<String, Object> record = new HashMap(); int index = 0; for (Cell cell : row) { String name = schema.get(index++); Object value = loadCellData(cell); if (value == null) { continue; } record.put(name, value); } if (record.size() > 0) { records.add(record); } } } } catch (Exception ex) { ex.printStackTrace(); } finally { } return records; }
From source file:javaapplication1.AnotherPOI.java
public static void replaceText(String findText, String replaceText) { try {// ww w.j a v a 2 s .co m XWPFDocument doc = new XWPFDocument(OPCPackage.open("D:\\template.docx")); for (XWPFParagraph p : doc.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String text = r.getText(0); if (text != null && text.contains(findText)) { text = text.replace(findText, replaceText); r.setText(text, 0); } } } } for (XWPFTable tbl : doc.getTables()) { for (XWPFTableRow row : tbl.getRows()) { for (XWPFTableCell cell : row.getTableCells()) { for (XWPFParagraph p : cell.getParagraphs()) { for (XWPFRun r : p.getRuns()) { String text = r.getText(0); if (text.contains(findText)) { text = text.replace(findText, replaceText); r.setText(text); } } } } } } doc.write(new FileOutputStream("D:\\result.docx")); } catch (IOException ex) { Logger.getLogger(AnotherPOI.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidFormatException ex) { Logger.getLogger(AnotherPOI.class.getName()).log(Level.SEVERE, null, ex); } }