Combine several Excel sheets on Knime
Today, we are going to approach a particular scenario that can appear boring but becomes simple to solve once we settled our logic.
Let’s suppose that we must analyze the sailing evolution of a company on the last three years.
The sailing’s historic is to find on an Excel file, that combines over 36 sheets (each sheet contains the sailings of a given month or year).
To start the analyze, we must then group our different sheets into a unique one.
Doing it manually, is an option but when the number of sheets is as high as it is in our case, it is more judicious to use KNIME’s functionalities. Let’s continue!
You’ll receive this Excel sheet as to proceed to our analyze.
It contains 36 sheets grouping sailings from 01-2020 to 12-2022.
How to proceed?
To combine our different sheets, 4 steps are necessary:
- Supply an Excel file, containing sheets/tabs that we want to combine.
- Convert the Excel sheets into variables and create a loop.
- Read the sheet corresponding to the actual variable.
- Keep data of the sheet that had just been read and skip to the next variable.
The loop arrives to its end when all the variables had been browsed.
Step by step:
Now that we have incorporated the logic behind our method, it is time to build our workflow:
Double-click on the node Read Excel Sheet Names to give the location and the file which we are working with. That node will have 2 output columns: Path ( location of the sheet ) and Sheet ( appellation of the sheet ).
Yet it is the Sheet column that is important since it will be converted in the next step, into a variable.
The configuration of the node Table row to variable loop starts :
The green box is the location where we insert the columns that we want to convert into variable.
In our case, we want to extract data for each sheet’s name in the file. We then need the sheet’s name, in that case Sheet, to be in the green box to be the variable that leads to the loop. Now that we are configured, we can execute the loop.
Now, we are going to configure the Excel Reader loop.
First, we are going to supply the file from which we want to extract data, then we are going to give the variable that contains the names of the sheets we are trying to combine. To do so, we need to click on the Flow Variables tab.
Click on Settings then select sheet in sheet_name as it is shown:
Last, and easiest step, it is now about configuring the Loop End according to your preferences.
Now that all our nodes are configured, we can execute our workflow.
Once the loop done, the final table should look like this:
The transformation of the sheets’ name into variable and the creation of a loop are the solution when you end up working with that kind of data. Your time is too precious to waste it on repetitive and tedious tasks when Knime offers functionalities that allows to automate them!