apache POI utility methods.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.poi.ss.usermodel.WorkbookcreateWorkbookWithSheet(String sheetName) Creates new workbook with adding sheet of namesheetName.voidevaluateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook) CatchesExceptions which are thrown whenworkbook.getCreationHelper().createFormulaEvaluator().evaluateAll()is called and changes it to aBizLogicAppExceptionwith an appropriate message.voidevaluateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook, String fileInfo) CatchesExceptions which are thrown whenworkbook.getCreationHelper().createFormulaEvaluator().evaluateAll()is called and changes it to aBizLogicAppExceptionwith an appropriate message.voidgetReadyToEvaluateFormula(org.apache.poi.ss.usermodel.Cell cell, boolean changesNumberString, boolean changesDateString, boolean changesCellsWithTextDataFormat, String[] dateFormats) There are patterns where excel can evaluate formulas but POI cannot.getReadyToWriteTableData(ExcelTableWriter<T> writer, org.apache.poi.ss.usermodel.Workbook workbook, String sheetName, int tableStartColumnNumber) Gets ready to write table data.openForOutput(String filePath) Opens the excel file and returnsWorkbookobject.org.apache.poi.ss.usermodel.WorkbookopenForWrite(String filePath) Opens the excel file and returnsWorkbookobject.voidsaveToFile(org.apache.poi.ss.usermodel.Workbook workbook, FileOutputStream out) Opens the excel file and returnsWorkbookobject.<T> voidwriteTableLine(ExcelTableWriter<T> writer, ExcelTable.ContextContainer context, int rowNumber, List<T> columnList) Provides common procedure for write one line of a table.
-
Constructor Details
-
ExcelWriteUtil
public ExcelWriteUtil()
-
-
Method Details
-
createWorkbookWithSheet
Creates new workbook with adding sheet of namesheetName.- Parameters:
sheetName- sheetName- Returns:
- Workbook
-
openForWrite
public org.apache.poi.ss.usermodel.Workbook openForWrite(String filePath) throws org.apache.poi.EncryptedDocumentException, IOException Opens the excel file and returnsWorkbookobject.- Parameters:
filePath- filePath- Returns:
- workbook
- Throws:
org.apache.poi.EncryptedDocumentException- EncryptedDocumentExceptionIOException- IOException
-
openForOutput
public FileOutputStream openForOutput(String filePath) throws org.apache.poi.EncryptedDocumentException, IOException Opens the excel file and returnsWorkbookobject.- Parameters:
filePath- filePath- Returns:
- workbook
- Throws:
org.apache.poi.EncryptedDocumentException- EncryptedDocumentExceptionIOException- IOException
-
saveToFile
public void saveToFile(org.apache.poi.ss.usermodel.Workbook workbook, FileOutputStream out) throws org.apache.poi.EncryptedDocumentException, IOException Opens the excel file and returnsWorkbookobject.- Throws:
org.apache.poi.EncryptedDocumentExceptionIOException
-
getReadyToWriteTableData
public <T> ExcelTable.ContextContainer getReadyToWriteTableData(ExcelTableWriter<T> writer, org.apache.poi.ss.usermodel.Workbook workbook, String sheetName, int tableStartColumnNumber) throws jp.ecuacion.lib.core.exception.checked.BizLogicAppException Gets ready to write table data.- Throws:
jp.ecuacion.lib.core.exception.checked.BizLogicAppException
-
writeTableLine
public <T> void writeTableLine(ExcelTableWriter<T> writer, ExcelTable.ContextContainer context, int rowNumber, List<T> columnList) Provides common procedure for write one line of a table. -
getReadyToEvaluateFormula
public void getReadyToEvaluateFormula(org.apache.poi.ss.usermodel.Cell cell, boolean changesNumberString, boolean changesDateString, boolean changesCellsWithTextDataFormat, String[] dateFormats) There are patterns where excel can evaluate formulas but POI cannot. This method cares about it and let POI do the same evaluation as excel.Let's say
A1cell isCellType == STRINGand value ="2025/01/01", andA2cell is a formula cell with formula=A1+1.
Excel can evaluate A2 and shows45659(Serial number which expresses "2025/1/2"), butPOIcannot.
So it change a date format string value (like "2025/01/01") to number (like 45658) whenCellTypeisSTRINGand its value matches the date format.
But it won't change the value when thedataFormat == 49because 49 means format is "text" and that means a user clearly wants to treat the value as a string format.Number format is exactly the same case as the
datecase above. Data format allows comma.- Parameters:
cell- cellchangesNumberString- whether it changes number format stringchangesDateString- whether it changes number format stringchangesCellsWithTextDataFormat- That Data format is "text" means that a user seems explicitly to set it because the user wants to treat it as "text" format. By setting this valuetrue, the method applies the change even if the cell is "text" format.dateFormats- dateFormats likeyyyy/MM/dd(java.time.format.DateTimeFormatter format), which can benullwhenchangesDateStringisfalse. WhenchangesDateStringistrueit cannot benulland element length must be more than or equal to 1.
-
evaluateAllFormulas
public void evaluateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook) throws jp.ecuacion.lib.core.exception.checked.BizLogicAppException CatchesExceptions which are thrown whenworkbook.getCreationHelper().createFormulaEvaluator().evaluateAll()is called and changes it to aBizLogicAppExceptionwith an appropriate message.When an excel file is created and uploaded by users,
Exceptions according to the content of the file should be understandable to the users.- Parameters:
workbook- workbook- Throws:
jp.ecuacion.lib.core.exception.checked.BizLogicAppException- BizLogicAppException
-
evaluateAllFormulas
public void evaluateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook, String fileInfo) throws jp.ecuacion.lib.core.exception.checked.BizLogicAppException CatchesExceptions which are thrown whenworkbook.getCreationHelper().createFormulaEvaluator().evaluateAll()is called and changes it to aBizLogicAppExceptionwith an appropriate message.When an excel file is created and uploaded by users,
Exceptions according to the content of the file should be understandable to the users.- Parameters:
workbook- workbookfileInfo- filename or file path of the excel file to add to the message- Throws:
jp.ecuacion.lib.core.exception.checked.BizLogicAppException- BizLogicAppException
-