Class WorkbookFactory
- java.lang.Object
-
- org.apache.poi.ss.usermodel.WorkbookFactory
-
public final class WorkbookFactory extends Object
Factory for creating the appropriate kind of Workbook (be itHSSFWorkbook
or XSSFWorkbook), by auto-detecting from the supplied input.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addProvider(WorkbookProvider provider)
static Workbook
create(boolean xssf)
Create a new empty Workbook, either XSSF or HSSF depending on the parameterstatic Workbook
create(File file)
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable.static Workbook
create(File file, String password)
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protectedstatic Workbook
create(File file, String password, boolean readOnly)
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protectedstatic Workbook
create(InputStream inp)
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream.static Workbook
create(InputStream inp, String password)
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream, which may be password protected.static Workbook
create(DirectoryNode root)
Creates a Workbook from the given DirectoryNode.static Workbook
create(DirectoryNode root, String password)
Creates a Workbook from the given DirectoryNode, which may be password protected.static Workbook
create(POIFSFileSystem fs)
Creates a Workbook from the given POIFSFileSystem.static void
removeProvider(Class<? extends WorkbookProvider> provider)
-
-
-
Method Detail
-
create
public static Workbook create(boolean xssf) throws IOException
Create a new empty Workbook, either XSSF or HSSF depending on the parameter- Parameters:
xssf
- If an XSSFWorkbook or a HSSFWorkbook should be created- Returns:
- The created workbook
- Throws:
IOException
- if an error occurs while creating the objectsIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(POIFSFileSystem fs) throws IOException
Creates a Workbook from the given POIFSFileSystem.Note that in order to properly release resources the Workbook should be closed after use.
- Parameters:
fs
- ThePOIFSFileSystem
to read the document from- Returns:
- The created workbook
- Throws:
IOException
- if an error occurs while reading the dataIllegalStateException
- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(DirectoryNode root) throws IOException
Creates a Workbook from the given DirectoryNode.Note that in order to properly release resources the Workbook should be closed after use.
- Parameters:
root
- TheDirectoryNode
to start reading the document from- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataIllegalStateException
- a number of other exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(DirectoryNode root, String password) throws IOException
Creates a Workbook from the given DirectoryNode, which may be password protected.Note that in order to properly release resources the Workbook should be closed after use.
- Parameters:
root
- TheDirectoryNode
to start reading the document frompassword
- The password that should be used or null if no password is necessary.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataIllegalStateException
- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(InputStream inp) throws IOException, EncryptedDocumentException
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream.Your input stream MUST either support mark/reset, or be wrapped as a
BufferedInputStream
! Note that using anInputStream
has a higher memory footprint than using aFile
.Note that in order to properly release resources the Workbook should be closed after use. Note also that loading from an InputStream requires more memory than loading from a File, so prefer
create(File)
where possible.- Parameters:
inp
- TheInputStream
to read data from.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataEncryptedDocumentException
- If the Workbook given is password protectedEmptyFileException
- If the given data is emptyIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(InputStream inp, String password) throws IOException, EncryptedDocumentException
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream, which may be password protected.Your input stream MUST either support mark/reset, or be wrapped as a
BufferedInputStream
! Note that using anInputStream
has a higher memory footprint than using aFile
.Note that in order to properly release resources the Workbook should be closed after use. Note also that loading from an InputStream requires more memory than loading from a File, so prefer
create(File)
where possible.- Parameters:
inp
- TheInputStream
to read data from.password
- The password that should be used or null if no password is necessary.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataEncryptedDocumentException
- If the wrong password is given for a protected fileEmptyFileException
- If the given data is emptyIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(File file) throws IOException, EncryptedDocumentException
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable.Note that in order to properly release resources the Workbook should be closed after use.
- Parameters:
file
- The file to read data from.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataEncryptedDocumentException
- If the Workbook given is password protectedEmptyFileException
- If the given data is emptyIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(File file, String password) throws IOException, EncryptedDocumentException
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protectedNote that in order to properly release resources the Workbook should be closed after use.
- Parameters:
file
- The file to read data from.password
- The password that should be used or null if no password is necessary.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataEncryptedDocumentException
- If the wrong password is given for a protected fileEmptyFileException
- If the given data is emptyIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
create
public static Workbook create(File file, String password, boolean readOnly) throws IOException, EncryptedDocumentException
Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protectedNote that in order to properly release resources the Workbook should be closed after use.
- Parameters:
file
- The file to read data from.password
- The password that should be used or null if no password is necessary.readOnly
- If the Workbook should be opened in read-only mode to avoid writing back changes when the document is closed.- Returns:
- The created Workbook
- Throws:
IOException
- if an error occurs while reading the dataEncryptedDocumentException
- If the wrong password is given for a protected fileEmptyFileException
- If the given data is emptyIllegalStateException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
addProvider
public static void addProvider(WorkbookProvider provider)
-
removeProvider
public static void removeProvider(Class<? extends WorkbookProvider> provider)
-
-