Sidebar

Is it possible for Qvera to process an XLSX source file?

0 votes
649 views
asked Dec 9, 2016 by wendy-l-4419 (230 points)
We would like to extract discrete data from an XLSX file but is this something that can be processed by QIE?

1 Answer

+1 vote
 
Best answer

This can be done using a 3rd party jar.  Apache POI is a set of open source libraries that will allow you to consume or create XLSX files using java.  Information on this project can be found at https://poi.apache.org or you could find another library if needed.  This example uses apache POI v3.9, it can be found here: https://archive.apache.org/dist/poi/release/bin/

NOTE: The latest version of apache POI has a conflict with the appache commons library that QIE uses natively.  You will need to download apache POI v3.9 to be compatable.  The archive copies can be found here: https://archive.apache.org/dist/poi/release/bin/

Information on installing the jar for use in QIE can be found here: https://www.qvera.com/kb/index.php/256

Once the jar files have been downloaded and installed, then you can use them like this:

// this formatter is used to get a string output from the cell regardless of the cell content
var oDataFormatter = new org.apache.poi.ss.usermodel.DataFormatter();

// convert message to input stream for POI to use
// if you need to read this directly from disk instead of the source
// you could do:
// var excelFile = new java.io.File("C:\\\\HL7\\Example.xlsx");
// var inputStream = new java.io.FileInputStream(excelFile);
var inputStream = new java.io.ByteArrayInputStream(source.getBytes());

// now we have POI read the excel file and convert it to a workbook object
var book = new org.apache.poi.xssf.usermodel.XSSFWorkbook(inputStream);

// next we extract the first sheet from the workbook
var sheet = book.getSheetAt(0);

// finally we cycle the rows of the sheet
var itterator = sheet.iterator();
var rowCount = 0;

// iterating over the file
while (itterator.hasNext()) {
   var row = itterator.next();
   
   // now itterate over each column in the row
   var cellItterator = row.cellIterator();
   while (cellItterator.hasNext()) {
      var cell = cellItterator.next();
      
      qie.debug('Cell Type: ' + cell.getCellType());
      qie.debug('Cell Value: ' + oDataFormatter.formatCellValue(cell));
   }
   rowCount++;
}

qie.debug('Rows Processed: ' + rowCount);
 

The debug output of this sample would output all of the cells in the first sheet.

Here is a sample channel.

answered Dec 9, 2016 by ben-s-7515 (12,640 points)
edited Jun 4, 2020 by michael-h-5027
commented Dec 12, 2016 by wendy-l-4419 (230 points)
Was it a typo that you said I would need apache commons 3.9 if I use POI 3.0.44 or EARLIER? The current POI patch is 3.15, so does that work with QIE's version of the commons library?
commented Jan 10, 2017 by ben-s-7515 (12,640 points)
Sorry about that.  I have edited the original message to make it clear.  3.0.44 is referencing the QIE version, but you need to use apache POI 3.9 to be compatible with the 3.0.44 version of QIE.
...