How to read excel files using Java Compute Node

Sometimes, we need to read excel files and there is no native connector in IBM Integration Bus. So, the obvious solution is to read them using Java. The most commonly used library is Apache POI.

Here I’ve written a simple program which reads the sheets ( assuming it has a header and multiple rows) and attach them to Environment tree. The java code is

public class ReadExcel_JCN extends MbJavaComputeNode {

	public void evaluate(MbMessageAssembly inAssembly) throws MbException {
		MbOutputTerminal out = getOutputTerminal("out");

		MbMessage inMessage = inAssembly.getMessage();
		MbMessageAssembly outAssembly = null;
		try {
			// create new message as a copy of the input
			MbMessage outMessage = new MbMessage(inMessage);
			outAssembly = new MbMessageAssembly(inAssembly, outMessage);
			// ----------------------------------------------------------
			// Add user code below
			MbElement environment = inAssembly.getGlobalEnvironment().getRootElement();
			File excelFiles = new File((String) getUserDefinedAttribute("ExcelDir"));
			Workbook workbook = null;
			DataFormatter dataFormatter = new DataFormatter();
			List<String> headerNames = null;
			String cellValue = null;
			MbElement cellElm = null;
			for (File excel : excelFiles.listFiles()) {
				workbook = WorkbookFactory.create(excel); 
				for (Sheet sheet : workbook) {
						MbElement sheetElm = environment.createElementAsLastChild(MbElement.TYPE_NAME, sheet.getSheetName(), null);
						headerNames = new ArrayList<>();
						for (Row row : sheet) {
							if (row.getRowNum() != 0) {
								cellElm = sheetElm.createElementAsLastChild(MbElement.TYPE_NAME, "rows", null);
							for (Cell cell : row) {
								cellValue = dataFormatter.formatCellValue(cell);
								if (row.getRowNum() == 0) {
								} else {
									cellElm.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, headerNames.get(cell.getColumnIndex()), cellValue);
						if (sheetElm.getLastChild() == null) {

			// End of user code
			// ----------------------------------------------------------
		} catch (MbException e) {
			// Re-throw to allow Broker handling of MbException
			throw e;
		} catch (RuntimeException e) {
			// Re-throw to allow Broker handling of RuntimeException
			throw e;
		} catch (Exception e) {
			// Consider replacing Exception with type(s) thrown by user code
			// Example handling ensures all exceptions are re-thrown to be handled in the flow
			throw new MbUserException(this, "evaluate()", "", "", e.toString(),
		// The following should only be changed
		// if not propagating message to the 'out' terminal



If you’re looking for any support in IIB, please contact us

About the Author

He has worked for various clients and developed more than 800+ message flows. He is an expert in ESQL, Java Compute Node and DFDL. If you’ve any complex code to be written in ESQL, feel free to contact him at +1 6123058684.

2 thoughts on “How to read excel files using Java Compute Node

  • May 3, 2023 at 6:18 pm

    can we read excel file by using compute node. how to get those files from fileinput node

    • July 9, 2023 at 6:59 am

      ESQL doesn’t have any built-in facility to read excel files. But, if this is a CSV file, you can create a model to parse it in the file input node and then do the regular stuffs in compute node.

      If this is not CSV, then Java is the only option available.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.