java.lang.Object
io.github.mbenincasa.javaexcelutils.model.excel.ExcelWorkbook

public class ExcelWorkbook extends Object
ExcelWorkbook is the Workbook wrapper class of the Apache POI library
Since:
0.3.0
Author:
Mirko Benincasa
  • Method Details

    • of

      public static ExcelWorkbook of(org.apache.poi.ss.usermodel.Workbook workbook)
      Get to an ExcelWorkbook instance from Apache POI Workbook
      Parameters:
      workbook - The Workbook instance to wrap
      Returns:
      The ExcelWorkbook instance
      Since:
      0.5.0
    • open

      Opens the workbook
      Parameters:
      file - An Excel file
      Returns:
      An ExcelWorkBook that is represented in the Excel file
      Throws:
      ExtensionNotValidException - If the input file extension does not belong to an Excel file
      IOException - If an I/O error has occurred
      OpenWorkbookException - If an error occurred while opening the workbook
    • open

      public static ExcelWorkbook open(InputStream inputStream) throws OpenWorkbookException
      Opens the workbook
      Parameters:
      inputStream - The InputStream of the Excel file
      Returns:
      An ExcelWorkBook that is represented in the Excel file
      Throws:
      OpenWorkbookException - If an error occurred while opening the workbook
    • create

      public static ExcelWorkbook create()
      Create a new workbook

      If not specified the XLSX extension will be used

      Returns:
      A ExcelWorkbook
    • create

      public static ExcelWorkbook create(String extension) throws ExtensionNotValidException
      Create a new workbook
      Parameters:
      extension - The extension of the file. Provide the extension of an Excel file
      Returns:
      A ExcelWorkbook
      Throws:
      ExtensionNotValidException - If the extension does not belong to an Excel file
    • create

      public static ExcelWorkbook create(Extension extension)
      Create a new workbook
      Parameters:
      extension - The extension of the file. Select an extension with type EXCEL
      Returns:
      A ExcelWorkbook
    • close

      public void close() throws IOException
      Close a workbook
      Throws:
      IOException - If an I/O error has occurred
    • close

      public void close(InputStream inputStream) throws IOException
      Close a workbook
      Parameters:
      inputStream - The InputStream to close
      Throws:
      IOException - If an I/O error has occurred
    • close

      public void close(OutputStream outputStream) throws IOException
      Close a workbook
      Parameters:
      outputStream - The OutputStream to close
      Throws:
      IOException - If an I/O error has occurred
    • close

      public void close(OutputStream outputStream, InputStream inputStream) throws IOException
      Close a workbook
      Parameters:
      outputStream - The OutputStream to close
      inputStream - The InputStream to close
      Throws:
      IOException - If an I/O error has occurred
    • close

      public void close(com.opencsv.CSVWriter writer) throws IOException
      Close a workbook
      Parameters:
      writer - The CSVWriter to close
      Throws:
      IOException - If an I/O error has occurred
    • close

      public void close(OutputStream outputStream, com.opencsv.CSVReader reader) throws IOException
      Close a workbook
      Parameters:
      outputStream - The OutputStream to close
      reader - The CSVReader to close
      Throws:
      IOException - If an I/O error has occurred
    • countSheets

      public Integer countSheets()
      The amount of Sheets in the Workbook
      Returns:
      The number of Sheets present
    • getSheets

      public List<ExcelSheet> getSheets()
      The list of Sheets related to the Workbook
      Returns:
      A list of Sheets
    • createSheet

      public ExcelSheet createSheet()
      Create a new Sheet inside the Workbook
      Returns:
      The newly created Sheet
    • createSheet

      public ExcelSheet createSheet(String sheetName) throws SheetAlreadyExistsException
      Create a new Sheet inside the Workbook
      Parameters:
      sheetName - The name of the sheet to create
      Returns:
      The newly created Sheet
      Throws:
      SheetAlreadyExistsException - If you try to insert a Sheet that already exists
    • getSheet

      public ExcelSheet getSheet() throws SheetNotFoundException
      Retrieve the Sheet with index 0
      Returns:
      The Sheet requested
      Throws:
      SheetNotFoundException - If the sheet to open is not found
    • getSheet

      public ExcelSheet getSheet(Integer index) throws SheetNotFoundException
      Retrieve the Sheet with the requested name
      Parameters:
      index - The index in the workbook
      Returns:
      The Sheet requested
      Throws:
      SheetNotFoundException - If the sheet to open is not found
    • getSheet

      public ExcelSheet getSheet(String sheetName) throws SheetNotFoundException
      Retrieve the Sheet with the requested index
      Parameters:
      sheetName - The name of the sheet
      Returns:
      The Sheet requested
      Throws:
      SheetNotFoundException - If the sheet to open is not found
    • getSheetOrCreate

      public ExcelSheet getSheetOrCreate(String sheetName)
      Retrieve the Sheet with the required name otherwise create it
      Parameters:
      sheetName - The name of the sheet
      Returns:
      The Sheet requested
    • removeSheet

      public void removeSheet(Integer index)
      Remove the Sheet
      Parameters:
      index - The index of the Sheet in the workbook that will be removed
      Since:
      0.4.1
    • isSheetPresent

      public Boolean isSheetPresent(String sheetName)
      Check if the sheet is present
      Parameters:
      sheetName - The name of the sheet
      Returns:
      true if is present
    • isSheetPresent

      public Boolean isSheetPresent(Integer index)
      Check if the sheet is present
      Parameters:
      index - The index in the workbook
      Returns:
      true if is present
    • isSheetNull

      public Boolean isSheetNull(String sheetName)
      Check if the sheet is not present
      Parameters:
      sheetName - The name of the sheet
      Returns:
      true if is not present
    • isSheetNull

      public Boolean isSheetNull(Integer index)
      Check if the sheet is not present
      Parameters:
      index - The index in the workbook
      Returns:
      true if is not present
    • getFormulaEvaluator

      public org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()
      Create a new FormulaEvaluator
      Returns:
      A FormulaEvaluator
    • writeAndClose

      public void writeAndClose(OutputStream outputStream) throws IOException
      Writes the OutputStream to the Workbook and then closes them
      Parameters:
      outputStream - The OutputStream to close
      Throws:
      IOException - If an I/O error has occurred
      Since:
      0.4.0