org.apache.poi.ss.usermodel

## Class WorkbookFactory

- java.lang.Object
- - org.apache.poi.ss.usermodel.WorkbookFactory

- Direct Known Subclasses:
    HSSFWorkbookFactory, XSSFWorkbookFactory

      public abstract class WorkbookFactory
      extends java.lang.Object

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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static interface` | `WorkbookFactory.CreateWorkbook0`
    `protected static interface` | `WorkbookFactory.CreateWorkbook1<T>`
    `protected static interface` | `WorkbookFactory.CreateWorkbook2<T,U>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static WorkbookFactory.CreateWorkbook1<DirectoryNode>` | `createHssfByNode`
    `protected static WorkbookFactory.CreateWorkbook0` | `createHssfFromScratch`
    `protected static WorkbookFactory.CreateWorkbook2<java.io.File,java.lang.Boolean>` | `createXssfByFile`
    `protected static WorkbookFactory.CreateWorkbook1<java.lang.Object>` | `createXssfByPackage`
    `protected static WorkbookFactory.CreateWorkbook1<java.io.InputStream>` | `createXssfByStream`
    `protected static WorkbookFactory.CreateWorkbook0` | `createXssfFromScratch`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WorkbookFactory()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Workbook` | `create(boolean xssf)` Create a new empty Workbook, either XSSF or HSSF depending on the parameter
    `static Workbook` | `create(DirectoryNode root)` Creates a Workbook from the given DirectoryNode.
    `static Workbook` | `create(DirectoryNode root, java.lang.String password)` Creates a Workbook from the given DirectoryNode, which may be password protected
    `static Workbook` | `create(java.io.File file)` Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable.
    `static Workbook` | `create(java.io.File file, java.lang.String password)` Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protected
    `static Workbook` | `create(java.io.File file, java.lang.String password, boolean readOnly)` Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable, and may be password protected
    `static Workbook` | `create(java.io.InputStream inp)` Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream.
    `static Workbook` | `create(java.io.InputStream inp, java.lang.String password)` Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given InputStream, which may be password protected.
    `static Workbook` | `create(java.lang.Object pkg)` Deprecated. use `create(File)`, `create(InputStream)` or XSSFWorkbookFactory.create(OPCPackage) instead.
    `static Workbook` | `create(POIFSFileSystem fs)` Creates a HSSFWorkbook from the given POIFSFileSystem

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### createHssfFromScratch

          protected static WorkbookFactory.CreateWorkbook0 createHssfFromScratch

    - #### createHssfByNode

          protected static WorkbookFactory.CreateWorkbook1<DirectoryNode> createHssfByNode

    - #### createXssfFromScratch

          protected static WorkbookFactory.CreateWorkbook0 createXssfFromScratch

    - #### createXssfByStream

          protected static WorkbookFactory.CreateWorkbook1<java.io.InputStream> createXssfByStream

    - #### createXssfByPackage

          protected static WorkbookFactory.CreateWorkbook1<java.lang.Object> createXssfByPackage

    - #### createXssfByFile

          protected static WorkbookFactory.CreateWorkbook2<java.io.File,java.lang.Boolean> createXssfByFile

  - ### Constructor Detail

    - #### WorkbookFactory

          public WorkbookFactory()

  - ### Method Detail

    - #### create

          public static Workbook create(boolean xssf)
                                 throws java.io.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:
        `java.io.IOException` - if an error occurs while creating the objects

    - #### create

          public static Workbook create(POIFSFileSystem fs)
                                 throws java.io.IOException

      Creates a HSSFWorkbook from the given POIFSFileSystem

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

      Parameters:
        `fs` - The `POIFSFileSystem` to read the document from
      Returns:
        The created workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data

    - #### create

          public static Workbook create(DirectoryNode root)
                                 throws java.io.IOException

      Creates a Workbook from the given DirectoryNode.
      Parameters:
        `root` - The `DirectoryNode` to start reading the document from
      Returns:
        The created Workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data

    - #### create

          public static Workbook create(DirectoryNode root,
                                        java.lang.String password)
                                 throws java.io.IOException

      Creates a Workbook from the given DirectoryNode, which may be password protected
      Parameters:
        `root` - The `DirectoryNode` to start reading the document from
        `password` - The password that should be used or null if no password is necessary.
      Returns:
        The created Workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data

    - #### create

          @Deprecated
           @Removal(version="4.2.0")
          public static Workbook create(java.lang.Object pkg)
                                                                        throws java.io.IOException

      Deprecated. use `create(File)`, `create(InputStream)` or XSSFWorkbookFactory.create(OPCPackage) instead.
      Creates a XSSFWorkbook from the given OOXML Package. As the WorkbookFactory is located in the POI module, which doesn't know about the OOXML formats, this can be only achieved by using an Object reference to the OPCPackage.

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

      Parameters:
        `pkg` - The org.apache.poi.openxml4j.opc.OPCPackage opened for reading data.
      Returns:
        The created Workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data

    - #### create

          public static Workbook create(java.io.InputStream inp)
                                 throws java.io.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` - The `InputStream` to read data from.
      Returns:
        The created Workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data
        `EncryptedDocumentException` - If the Workbook given is password protected

    - #### create

          public static Workbook create(java.io.InputStream inp,
                                        java.lang.String password)
                                 throws java.io.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` - The `InputStream` to read data from.
        `password` - The password that should be used or null if no password is necessary.
      Returns:
        The created Workbook
      Throws:
        `java.io.IOException` - if an error occurs while reading the data
        `EncryptedDocumentException` - If the wrong password is given for a protected file

    - #### create

          public static Workbook create(java.io.File file)
                                 throws java.io.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:
        `java.io.IOException` - if an error occurs while reading the data
        `EncryptedDocumentException` - If the Workbook given is password protected

    - #### create

          public static Workbook create(java.io.File file,
                                        java.lang.String password)
                                 throws java.io.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` - 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:
        `java.io.IOException` - if an error occurs while reading the data
        `EncryptedDocumentException` - If the wrong password is given for a protected file

    - #### create

          public static Workbook create(java.io.File file,
                                        java.lang.String password,
                                        boolean readOnly)
                                 throws java.io.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` - 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:
        `java.io.IOException` - if an error occurs while reading the data
        `EncryptedDocumentException` - If the wrong password is given for a protected file

Copyright 2020 The Apache Software Foundation or its licensors, as applicable.