Example usage for org.apache.poi.ss.usermodel WorkbookFactory create

List of usage examples for org.apache.poi.ss.usermodel WorkbookFactory create

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel WorkbookFactory create.

Prototype

public static Workbook create(File file, String password, boolean readOnly)
        throws IOException, EncryptedDocumentException 

Source Link

Document

Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protected

Note that in order to properly release resources the Workbook should be closed after use.

Usage

From source file:org.gephi.io.importer.plugin.file.spreadsheet.ImporterSpreadsheetExcel.java

License:Open Source License

private SheetParser createParser(boolean withFirstRecordAsHeader) throws IOException {
    try {/*from  www .jav  a  2  s .c o m*/
        boolean readOnly = true;
        Workbook workbook = WorkbookFactory.create(file, null, readOnly);
        Sheet sheet = workbook.getSheetAt(sheetIndex);

        return new ExcelSheetParser(sheet, withFirstRecordAsHeader);
    } catch (Exception ex) {
        //Control and report old excel files are unsupported:
        //Control and report excel file blocked by another process (normally excel itself):

        if (report != null) {
            SpreadsheetUtils.logError(report, ex.getMessage(), null);
            return EmptySheet.INSTANCE;
        } else {
            return new ErrorSheet(ex.getMessage());
        }
    }
}