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 TypeMethodDescriptionvoidclose()Close a workbookvoidclose(com.opencsv.CSVWriter writer) Close a workbookvoidclose(InputStream inputStream) Close a workbookvoidclose(OutputStream outputStream) Close a workbookvoidclose(OutputStream outputStream, com.opencsv.CSVReader reader) Close a workbookvoidclose(OutputStream outputStream, InputStream inputStream) Close a workbookThe amount of Sheets in the Workbookstatic ExcelWorkbookcreate()Create a new workbookstatic ExcelWorkbookCreate a new workbookstatic ExcelWorkbookCreate a new workbookCreate a new Sheet inside the WorkbookcreateSheet(String sheetName) Create a new Sheet inside the Workbookorg.apache.poi.ss.usermodel.FormulaEvaluatorCreate 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 ExcelWorkbookof(org.apache.poi.ss.usermodel.Workbook workbook) Get to an ExcelWorkbook instance from Apache POI Workbookstatic ExcelWorkbookOpens the workbookstatic ExcelWorkbookopen(InputStream inputStream) Opens the workbookvoidremoveSheet(Integer index) Remove the SheetvoidwriteAndClose(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- TheInputStreamof 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 withtypeEXCEL- Returns:
- A ExcelWorkbook
-
close
Close a workbook- Throws:
IOException- If an I/O error has occurred
-
close
Close a workbook- Parameters:
inputStream- TheInputStreamto close- Throws:
IOException- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream- TheOutputStreamto close- Throws:
IOException- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream- TheOutputStreamto closeinputStream- TheInputStreamto close- Throws:
IOException- If an I/O error has occurred
-
close
Close a workbook- Parameters:
writer- TheCSVWriterto close- Throws:
IOException- If an I/O error has occurred
-
close
Close a workbook- Parameters:
outputStream- TheOutputStreamto closereader- TheCSVReaderto 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:
trueif is present
-
isSheetPresent
Check if the sheet is present- Parameters:
index- The index in the workbook- Returns:
trueif is present
-
isSheetNull
Check if the sheet is not present- Parameters:
sheetName- The name of the sheet- Returns:
trueif is not present
-
isSheetNull
Check if the sheet is not present- Parameters:
index- The index in the workbook- Returns:
trueif 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- TheOutputStreamto close- Throws:
IOException- If an I/O error has occurred- Since:
- 0.4.0
-