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

@SuppressWarnings("resource") 
public HSSFWorkbook(InputStream s, boolean preserveNodes) throws IOException 

Source Link

Document

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

Usage

From source file:br.com.tiagods.model.Arquivo.java

public Workbook validarWorkbook(Workbook workbook, File file, String ext, InputStream inputStream) {
    switch (ext) {
    case "xls":
        try {//w  ww.j a va2  s .c  om
            if (file.getName().equals("Cadastro.xls")) {//formula para abrir arquivo com senha
                Biff8EncryptionKey.setCurrentUserPassword("PLKCONTRATOS");
                NPOIFSFileSystem fs = new NPOIFSFileSystem(file, true);
                return workbook = new HSSFWorkbook(fs.getRoot(), true);
            } else {
                POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
                return workbook = new HSSFWorkbook(fileSystem);
            }
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
    case "xlsx":
        try {
            return workbook = new XSSFWorkbook(inputStream);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
    default:
        JOptionPane.showMessageDialog(null, "Formato de arquivo no permitido!");
        return null;
    }
}