Class ExcelWorkbook
java.lang.Object
io.github.mbenincasa.javaexcelutils.model.excel.ExcelWorkbook
ExcelWorkbook
is the Workbook
wrapper class of the Apache POI library- Since:
- 0.3.0
- Author:
- Mirko Benincasa
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close a workbookvoid
close
(com.opencsv.CSVWriter writer) Close a workbookvoid
close
(InputStream inputStream) Close a workbookvoid
close
(OutputStream outputStream) Close a workbookvoid
close
(OutputStream outputStream, com.opencsv.CSVReader reader) Close a workbookvoid
close
(OutputStream outputStream, InputStream inputStream) Close a workbookThe amount of Sheets in the Workbookstatic ExcelWorkbook
create()
Create a new workbookstatic ExcelWorkbook
Create a new workbookstatic ExcelWorkbook
Create a new workbookCreate a new Sheet inside the WorkbookcreateSheet
(String sheetName) Create a new Sheet inside the Workbookorg.apache.poi.ss.usermodel.FormulaEvaluator
Create a new FormulaEvaluatorgetSheet()
Retrieve the Sheet with index 0Retrieve the Sheet with the requested nameRetrieve the Sheet with the requested indexgetSheetOrCreate
(String sheetName) Retrieve the Sheet with the required name otherwise create itThe list of Sheets related to the WorkbookisSheetNull
(Integer index) Check if the sheet is not presentisSheetNull
(String sheetName) Check if the sheet is not presentisSheetPresent
(Integer index) Check if the sheet is presentisSheetPresent
(String sheetName) Check if the sheet is presentstatic ExcelWorkbook
of
(org.apache.poi.ss.usermodel.Workbook workbook) Get to an ExcelWorkbook instance from Apache POI Workbookstatic ExcelWorkbook
Opens the workbookstatic ExcelWorkbook
open
(InputStream inputStream) Opens the workbookvoid
removeSheet
(Integer index) Remove the Sheetvoid
writeAndClose
(OutputStream outputStream) Writes the OutputStream to the Workbook and then closes them
-
Method Details
-
of
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
public static ExcelWorkbook open(File file) throws ExtensionNotValidException, IOException, OpenWorkbookException 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 fileIOException
- If an I/O error has occurredOpenWorkbookException
- If an error occurred while opening the workbook
-
open
Opens the workbook- Parameters:
inputStream
- TheInputStream
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
Create a new workbookIf not specified the XLSX extension will be used
- Returns:
- A ExcelWorkbook
-
create
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
Create a new workbook- Parameters:
extension
- The extension of the file. Select an extension withtype
EXCEL- Returns:
- A ExcelWorkbook
-
close
Close a workbook- Throws:
IOException
- If an I/O error has occurred
-
close
Close a workbook- Parameters:
inputStream
- TheInputStream
to close- Throws:
IOException
- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream
- TheOutputStream
to close- Throws:
IOException
- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream
- TheOutputStream
to closeinputStream
- TheInputStream
to close- Throws:
IOException
- If an I/O error has occurred
-
close
Close a workbook- Parameters:
writer
- TheCSVWriter
to close- Throws:
IOException
- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream
- TheOutputStream
to closereader
- TheCSVReader
to close- Throws:
IOException
- If an I/O error has occurred
-
countSheets
The amount of Sheets in the Workbook- Returns:
- The number of Sheets present
-
getSheets
The list of Sheets related to the Workbook- Returns:
- A list of Sheets
-
createSheet
Create a new Sheet inside the Workbook- Returns:
- The newly created Sheet
-
createSheet
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
Retrieve the Sheet with index 0- Returns:
- The Sheet requested
- Throws:
SheetNotFoundException
- If the sheet to open is not found
-
getSheet
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
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
Retrieve the Sheet with the required name otherwise create it- Parameters:
sheetName
- The name of the sheet- Returns:
- The Sheet requested
-
removeSheet
Remove the Sheet- Parameters:
index
- The index of the Sheet in the workbook that will be removed- Since:
- 0.4.1
-
isSheetPresent
Check if the sheet is present- Parameters:
sheetName
- The name of the sheet- Returns:
true
if is present
-
isSheetPresent
Check if the sheet is present- Parameters:
index
- The index in the workbook- Returns:
true
if is present
-
isSheetNull
Check if the sheet is not present- Parameters:
sheetName
- The name of the sheet- Returns:
true
if is not present
-
isSheetNull
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
Writes the OutputStream to the Workbook and then closes them- Parameters:
outputStream
- TheOutputStream
to close- Throws:
IOException
- If an I/O error has occurred- Since:
- 0.4.0
-