Top Description Inners Fields Constructors Methods
org.apache.poi.ss.usermodel

public final Class WorkbookFactory

extends Object
Class Inheritance
Static Imports
org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE, org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY

Factory for creating the appropriate kind of Workbook (be it HSSFWorkbook or XSSFWorkbook), by auto-detecting from the supplied input.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class

Field Summary

Modifier and TypeField and Description
private final List<WorkbookProvider>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
public static Workbook

Returns:

The created workbook
create
(boolean
If an XSSFWorkbook or a HSSFWorkbook should be created
xssf
)

Create a new empty Workbook, either XSSF or HSSF depending on the parameter

public static Workbook

Returns:

The created workbook
create
(POIFSFileSystem
The POIFSFileSystem to read the document from
fs
)

Creates a Workbook from the given POIFSFileSystem.

private static Workbook

Returns:

The created Workbook
create
(final POIFSFileSystem
The POIFSFileSystem to read the document from
fs
,
String
The password that should be used or null if no password is necessary.
password
)

Creates a Workbook from the given POIFSFileSystem, which may be password protected.

public static Workbook

Returns:

The created Workbook
create
(final DirectoryNode
The DirectoryNode to start reading the document from
root
)

Creates a Workbook from the given DirectoryNode.

public static Workbook

Returns:

The created Workbook
create
(final DirectoryNode
The DirectoryNode to start reading the document from
root
,
String
The password that should be used or null if no password is necessary.
password
)

Creates a Workbook from the given DirectoryNode, which may be password protected.

public static Workbook

Returns:

The created Workbook
create
(InputStream
The InputStream to read data from.
inp
)

Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream.

public static Workbook

Returns:

The created Workbook
create
(InputStream
The InputStream to read data from.
inp
,
String
The password that should be used or null if no password is necessary.
password
)

Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream, which may be password protected.

public static Workbook

Returns:

The created Workbook
create
(File
The file to read data from.
file
)

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

public static Workbook

Returns:

The created Workbook
create
(File
The file to read data from.
file
,
String
The password that should be used or null if no password is necessary.
password
)

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.

public static Workbook

Returns:

The created Workbook
create
(File
The file to read data from.
file
,
String
The password that should be used or null if no password is necessary.
password
,
boolean
If the Workbook should be opened in read-only mode to avoid writing back changes when the document is closed.
readOnly
)

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.

public static void
removeProvider(Class<? extends WorkbookProvider> provider)

private static Workbook
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

providerback to summary
private final List<WorkbookProvider> provider

Constructor Detail

WorkbookFactoryback to summary
private WorkbookFactory()

Method Detail

addProviderback to summary
public static void addProvider(WorkbookProvider provider)
createback to summary
public static Workbook create(boolean xssf) throws IOException

Create a new empty Workbook, either XSSF or HSSF depending on the parameter

Parameters
xssf:boolean

If an XSSFWorkbook or a HSSFWorkbook should be created

Returns:Workbook

The created workbook

Exceptions
IOException:
if an error occurs while creating the objects
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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:POIFSFileSystem

The POIFSFileSystem to read the document from

Returns:Workbook

The created workbook

Exceptions
IOException:
if an error occurs while reading the data
IllegalStateException:
a number of runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
private static Workbook create(final POIFSFileSystem fs, String password) throws IOException

Creates a Workbook from the given POIFSFileSystem, which may be password protected.

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

Parameters
fs:POIFSFileSystem

The POIFSFileSystem to read the document from

password:String

The password that should be used or null if no password is necessary.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
IllegalStateException:
a number of runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
public static Workbook create(final 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:DirectoryNode

The DirectoryNode to start reading the document from

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
IllegalStateException:
a number of other exceptions can be thrown, especially if there are problems with the input format
createback to summary
public static Workbook create(final 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:DirectoryNode

The DirectoryNode to start reading the document from

password:String

The password that should be used or null if no password is necessary.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
IllegalStateException:
a number of runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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 an InputStream has a higher memory footprint than using a File.

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:InputStream

The InputStream to read data from.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
EncryptedDocumentException:
If the Workbook given is password protected
EmptyFileException:
If the given data is empty
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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 an InputStream has a higher memory footprint than using a File.

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:InputStream

The InputStream to read data from.

password:String

The password that should be used or null if no password is necessary.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
EncryptedDocumentException:
If the wrong password is given for a protected file
EmptyFileException:
If the given data is empty
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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:File

The file to read data from.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
EncryptedDocumentException:
If the Workbook given is password protected
EmptyFileException:
If the given data is empty
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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 protected

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

Parameters
file:File

The file to read data from.

password:String

The password that should be used or null if no password is necessary.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
EncryptedDocumentException:
If the wrong password is given for a protected file
EmptyFileException:
If the given data is empty
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
createback to summary
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 protected

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

Parameters
file:File

The file to read data from.

password:String

The password that should be used or null if no password is necessary.

readOnly:boolean

If the Workbook should be opened in read-only mode to avoid writing back changes when the document is closed.

Returns:Workbook

The created Workbook

Exceptions
IOException:
if an error occurs while reading the data
EncryptedDocumentException:
If the wrong password is given for a protected file
EmptyFileException:
If the given data is empty
IllegalStateException:
a number of other runtime exceptions can be thrown, especially if there are problems with the input format
removeProviderback to summary
public static void removeProvider(Class<? extends WorkbookProvider> provider)
wpback to summary
private static Workbook wp(FileMagic fm, WorkbookFactory.ProviderMethod fun) throws IOException
org.apache.poi.ss.usermodel back to summary

private Interface WorkbookFactory.ProviderMethod


Method Summary

Modifier and TypeMethod and Description
public Workbook

Method Detail

createback to summary
public Workbook create(WorkbookProvider prov) throws IOException
org.apache.poi.ss.usermodel back to summary

private Class WorkbookFactory.Singleton

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final WorkbookFactory

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final WorkbookFactory INSTANCE

Constructor Detail

Singletonback to summary
private Singleton()