Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook.

Prototype

public HSSFWorkbook(InputStream s) throws IOException 

Source Link

Document

Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your InputStream , including all nodes.

Usage

From source file:ch.elexis.core.importer.div.importers.ExcelWrapper.java

License:Open Source License

/**
 * Load a specific page of the given Excel Spreadsheet
 * //from www  .  j a  va2 s  .c  o  m
 * @param file
 *            filename of the Excel file
 * @param page
 *            page to use
 * @return true on success
 * @deprecated use load(InputStream) instead
 */
@Deprecated
public boolean load(final String file, final int page) {
    try {
        fs = new POIFSFileSystem(new FileInputStream(file));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        sheet = wb.getSheetAt(page);
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:ch.elexis.core.importer.div.importers.ExcelWrapper.java

License:Open Source License

/**
 * Load a specific page of the given Excel Spreadsheet
 * //from   www  .j av a2  s .  c o m
 * @param bytes
 *            Excel content as byte array
 * @param page
 *            page to use
 * @return true on success
 */
public boolean load(final InputStream inputStream, final int page) {
    try {
        fs = new POIFSFileSystem(inputStream);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        sheet = wb.getSheetAt(page);
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:ch.javasoft.metabolic.parse.ExcelParser.java

License:BSD License

/**
 * /*  w w  w . java2 s .  c om*/
 * @param file                  the excel file to parse
 * @param sheetIndex            0 based index of the worksheet
 * @throws FileNotFoundException   if the specified file does not exist
  * @throws IOException         if an i/o exception occurs, for instance 
  *                         caused by file access
 */
public ExcelParser(File file, int sheetIndex) throws FileNotFoundException, IOException {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    mWorkbook = new HSSFWorkbook(fs);
    mSheet = mWorkbook.getSheetAt(sheetIndex);
    mFile = file;
    if (mSheet == null)
        throw new IOException("no sheet " + sheetIndex + " in excel file '" + file.getAbsolutePath() + "'");
    mSheetName = mWorkbook.getSheetName(sheetIndex);
}

From source file:ch.javasoft.metabolic.parse.ExcelParser.java

License:BSD License

protected ExcelParser(File file, String worksheet) throws FileNotFoundException, IOException {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    mWorkbook = new HSSFWorkbook(fs);
    mSheet = worksheet == null ? mWorkbook.getSheetAt(0) : mWorkbook.getSheet(worksheet);
    mFile = file;/*from  w  w w. j  a va2 s .  com*/
    if (mSheet == null)
        throw new IOException("no sheet " + (worksheet == null ? "0" : "'" + worksheet + "'")
                + " in excel file '" + file.getAbsolutePath() + "'");
    mSheetName = worksheet == null ? mWorkbook.getSheetName(0) : worksheet;
}

From source file:ch.oakmountain.tpa.parser.TpaParser.java

License:Apache License

public TpaParser(Properties applicationProps, String fileName) throws IOException {
    this.applicationProps = applicationProps;
    Set<String> stringPropertyNames = applicationProps.stringPropertyNames();
    for (tpaProps tpaProp : tpaProps.values()) {
        if (!stringPropertyNames.contains(tpaProp.name())) {
            throw new IllegalArgumentException("Property \"" + tpaProp.name()
                    + "\" has not been set in the the tpa configuration properties");
        }//from  ww  w.jav a  2s .c  o  m
    }

    FileInputStream fin = new FileInputStream(fileName);
    wb = new HSSFWorkbook(fin);
    mapping = readNodeAbbrMapping(wb);
    timestyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    timestyle.setDataFormat(df.getFormat("hh:mm:ss"));

}

From source file:cliente.ReclamoPiezas.GUINuevoReclamoFabrica.java

License:Open Source License

protected void llenarFormulario() {
    String archivo = "Formulario_SRC.xls";
    Date hoy = new Date();
    String nombre_archivo = pedido_pieza.getPedido().getReclamo().getReclamante().getNombre_apellido()
            + "_pedido_" + pedido_pieza.getNumero_pedido();
    Boolean inmovilizado = pedido_pieza.getPedido().getReclamo().getInmovilizado();
    String vin = pedido_pieza.getPedido().getReclamo().getVehiculo().getVin();
    String dominio = pedido_pieza.getPedido().getReclamo().getVehiculo().getDominio();
    String nombre_cliente = pedido_pieza.getPedido().getReclamo().getReclamante().getNombre_apellido();
    String telefono = mediador.obtenerTelefono(pedido_pieza);
    try {// www  . j  a va 2 s. c o  m

        InputStream ExcelFileToRead = new FileInputStream("Formulario_SRC.xls");

        HSSFWorkbook formulario_src = new HSSFWorkbook(ExcelFileToRead);

        HSSFSheet sheet = formulario_src.getSheetAt(0);

        HSSFRow row;
        HSSFCell cell;
        //tipo reclamo
        row = sheet.getRow(10);
        cell = row.getCell(4);
        cell.setCellValue("Repuestos");
        //inmovilizado
        if (inmovilizado) {
            row = sheet.getRow(11);
            cell = row.getCell(4);
            cell.setCellValue("Si");
        } else {
            row = sheet.getRow(11);
            cell = row.getCell(4);
            cell.setCellValue("No");
        }
        //garantia
        row = sheet.getRow(12);
        cell = row.getCell(4);
        cell.setCellValue("Si");
        //Vin
        row = sheet.getRow(15);
        cell = row.getCell(4);
        cell.setCellValue(vin);
        //dominio
        row = sheet.getRow(16);
        cell = row.getCell(4);
        cell.setCellValue(dominio);
        //modelo
        LinkedList<String> modelos = new LinkedList<String>();
        modelos.add("FLUENCE");
        modelos.add("CLIO");
        modelos.add("KANGOO");
        modelos.add("SYMBOL");
        modelos.add("LOGAN");
        modelos.add("SANDERO");
        modelos.add("MASTER");
        modelos.add("KOLEOS");
        modelos.add("MEGANE III");
        modelos.add("DUSTER");
        modelos.add("LATITUDE");
        if (modelos.contains(pedido_pieza.getPedido().getReclamo().getVehiculo().getModelo().getNombre_modelo()
                .toUpperCase())) {
            row = sheet.getRow(17);
            cell = row.getCell(4);
            cell.setCellValue(pedido_pieza.getPedido().getReclamo().getVehiculo().getModelo().getNombre_modelo()
                    .toUpperCase());
        } else {
            row = sheet.getRow(17);
            cell = row.getCell(4);
            cell.setCellValue("OTROS");
        }
        //nombre cliente
        row = sheet.getRow(11);
        cell = row.getCell(8);
        cell.setCellValue(nombre_cliente);
        //telefono
        row = sheet.getRow(12);
        cell = row.getCell(8);
        cell.setCellValue(telefono);
        //motivo
        row = sheet.getRow(21);
        cell = row.getCell(2);
        cell.setCellValue(ePMotivo.getText());
        //pieza
        row = sheet.getRow(33);
        cell = row.getCell(3);
        cell.setCellValue(pedido_pieza.getPieza().getNumero_pieza());
        row = sheet.getRow(33);
        cell = row.getCell(4);
        cell.setCellValue(pedido_pieza.getPieza().getDescripcion());
        row = sheet.getRow(33);
        cell = row.getCell(7);
        cell.setCellValue("1");
        row = sheet.getRow(33);
        cell = row.getCell(8);
        cell.setCellValue(pedido_pieza.getNumero_pedido());

        //write this workbook to an Outputstream.
        int i = 0;
        String aux = nombre_archivo;
        File formulario_guardado = new File(RootAndIp.getPath_reportes() + aux + ".xls");
        while (formulario_guardado.exists()) {
            aux = nombre_archivo + "_" + i;
            formulario_guardado = new File(RootAndIp.getPath_reportes() + aux + ".xls");
            i++;
        }

        FileOutputStream fileOut = new FileOutputStream(formulario_guardado);
        formulario_src.write(fileOut);
        fileOut.flush();
        fileOut.close();

        Desktop.getDesktop().open(formulario_guardado);

        formulario = formulario_guardado.getPath();
        btnVerFormulario.setEnabled(true);
        btnEnviarFormulario.setEnabled(true);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:cn.bzvs.excel.imports.ExcelImportServer.java

License:Apache License

/**
 * Excel  field  Integer,Long,Double,Date,String,Boolean
 * /* ww w . j  av  a  2s  . co m*/
 * @param inputstream
 * @param pojoClass
 * @param params
 * @return
 * @throws Exception
 */
public ExcelImportResult importExcelByIs(InputStream inputstream, Class<?> pojoClass, ImportParams params)
        throws Exception {
    List<T> result = new ArrayList<T>();
    Workbook book = null;
    boolean isXSSFWorkbook = true;
    if (!(inputstream.markSupported())) {
        inputstream = new PushbackInputStream(inputstream, 8);
    }
    if (POIFSFileSystem.hasPOIFSHeader(inputstream)) {
        book = new HSSFWorkbook(inputstream);
        isXSSFWorkbook = false;
    } else if (POIXMLDocument.hasOOXMLHeader(inputstream)) {
        book = new XSSFWorkbook(OPCPackage.open(inputstream));
    }
    createErrorCellStyle(book);
    Map<String, PictureData> pictures;
    for (int i = params.getStartSheetIndex(); i < params.getStartSheetIndex() + params.getSheetNum(); i++) {
        if (isXSSFWorkbook) {
            pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i), (XSSFWorkbook) book);
        } else {
            pictures = PoiPublicUtil.getSheetPictrues03((HSSFSheet) book.getSheetAt(i), (HSSFWorkbook) book);
        }
        result.addAll(importExcel(result, book.getSheetAt(i), pojoClass, params, pictures));
    }
    if (params.isNeedSave()) {
        saveThisExcel(params, pojoClass, isXSSFWorkbook, book);
    }
    return new ExcelImportResult(result, verfiyFail, book);
}

From source file:cn.fql.template.poi.MergeInvoiceSheet.java

License:Open Source License

private static void writeMonth(String inputFile, String outputFile) {
    FileOutputStream oos = null;// w  ww.ja v  a  2s.  c om
    FileInputStream fis = null;
    try {
        oos = new FileOutputStream(outputFile);
        fis = new FileInputStream(inputFile);
        templateWbk = new HSSFWorkbook(fis);
        percentageStyle = templateWbk.createCellStyle();
        percentageStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        percentageStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        percentageStyle.setDataFormat((short) 9);
        writeIndividualTime();
        writeSubActivityTime();
        templateWbk.write(oos);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            fis.close();
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:cn.fql.template.poi.MergeInvoiceSheet.java

License:Open Source License

private static void writeInvoice(String inputFile, String outputFile) {
    FileOutputStream oos = null;/*  w w w .  j ava2s  .c o  m*/
    FileInputStream fis = null;
    try {
        oos = new FileOutputStream(outputFile);
        fis = new FileInputStream(inputFile);
        templateWbk = new HSSFWorkbook(fis);
        percentageStyle = templateWbk.createCellStyle();
        percentageStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        percentageStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        percentageStyle.setDataFormat((short) 9);
        writeEffort(1, "Effort Summary by Type");
        writeEffortSummary();
        writeEffortTotal();
        templateWbk.write(oos);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            fis.close();
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:cn.fql.template.poi.PoiTest.java

License:Open Source License

private static void writeInvoice(String inputFile, String outputFile) {
    FileOutputStream oos = null;//  w ww .  j av a  2  s . c o  m
    FileInputStream fis = null;
    try {
        oos = new FileOutputStream(outputFile);
        fis = new FileInputStream(inputFile);
        templateWbk = new HSSFWorkbook(fis);
        writeEffort(2, "report");
        writeEffort(3, "report");
        writeEffort(4, "report");
        writeEffort(5, "report");
        templateWbk.write(oos);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            fis.close();
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}