Excel to CSV #5429
joshmc82
started this conversation in
Show and tell
Excel to CSV
#5429
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
User "Amit Cudykier" in the Mirth Connect slack posted some great code on how to read an Excel spreadhsheet and convert it to CSV using Mirth Connect. Sample POC Channel is attached.
Prerequisites:
resources/poi
)Steps to Install:
resources/poi
)ooxml-lib
folder (and contents) from the local poi-bin folder to your remote folder from above.lib
folder (and contents) from the local poi-bin folder to your remove folder from above.In case this channel fails to load, here is the code extract from the source transformer:
importPackage(org.apache.xmlbeans); importPackage(org.apache.commons.io); importPackage(org.apache.poi); importPackage(org.apache.poi.ooxml); var iso = Packages(contextFactory.getIsolatedClassLoader()); var strByte = new java.io.ByteArrayInputStream(FileUtil.decode(connectorMessage.getRawData())); var wb = new iso.org.apache.poi.ss.usermodel.WorkbookFactory.create(strByte) var sheet = wb.getSheetAt(0); var rows = sheet.getLastRowNum(); var cols = sheet.getRow(0).getLastCellNum(); var xml = new XML(<delimited/>); for (var r=0;r<=rows;r++){ var row = sheet.getRow(r); var xmlRow = <row/>; for (var c=0;c<cols;c++){ var cell = row.getCell(c); var cellValue = cell.getStringCellValue(); var xmlCell = <column>{cellValue}</column>; xmlRow.appendChild(xmlCell); } xml.appendChild(xmlRow); } tmp=xml;
Excel to CSV.zip
Beta Was this translation helpful? Give feedback.
All reactions