Read Excel Using Mirth
Read and parse Excel Spreadsheet value using Mirth core JAVA
Table of contents
No headings in the article.
Hi Folks,
Today I’m gonna share a solution Mirth Custom Excel Reader which reads the excel file and get the contents in a string delimited text format.
You can find the full code of this in this blog
For this we mainly using apache poi jar which is standard jar even used for java solutions for parsing excel files
Pre-requisites:
- MirthConnect : Above 3.3
Custom Jars:
- dom4j-1.6.jar
- poi-3.9.jar
- poi-ooxml-3.8.jar
- poi-ooxml-schemas-3.7.jar
- xmlbeans-2.5.0.jar
Code & Solution:
function ExtractExcelContent(fileDirectory, originalFilename, billingEntity) {
var path = fileDirectory + '/' + originalFilename;
// Call file with path
var fileF = new java.io.File(path);
var inputstream = new java.io.FileInputStream(fileF);
// String Builder for excelData
var excelData = new java.lang.StringBuilder();
var workBook = new org.apache.poi.ss.usermodel.WorkbookFactory.create(inputstream);
var dataFormatter = new org.apache.poi.ss.usermodel.DataFormatter();
// Create Empty String separator
var sep = "";
var sep2 = "";
// Create ArrayList()
var excelheaders = new java.util.ArrayList();
var get_Entity = '';
var get_Number = '';
var exitExcelReader = '';
var isEAIserviceNotification = false;
var r = org.apache.poi.ss.usermodel.Row;
var cell = org.apache.poi.ss.usermodel.Cell;
var sheet = Packages.org.apache.poi.ss.usermodel.Sheet;
try {
// Your logic goes here
} catch (e) {
logger.debug("catch Block : " + e);
getErrorMailContent(" file did not process successfully");
} finally {
//workBook.close();
inputstream.close();
channelMap.put('isEAIServiceNotification', isEAIserviceNotification);
}
return d;
}