Consolidate Multiple Excel Files into one -

I have two workflows which i created. The both output are saved in my local system (2 separate folders). Each folder comprises of 300 files.
My challenge is that I want to append one file in folder 1 with the another file in folder 2.
Note: Both files belongs to the same UserID. The difference is that they have different information. I also want to use loops to check in folder 1 and folder 2. If the both folder has the same userID. Then it should consolidate both files into one excel as sheet 1 and sheet 2.

Please i require an urgent help in order to save my job :cry:

Do you want to append the file (join sideways) or concatenate ( add more rows under)? Both can be done with either the Joiner node or the Concatenate node. Depending on how your userID is stored you can confirm that it matches before passing along both the names of the files to join using string manipulation or column expressions to compare the two strings before consolidating

Hope this helps, if I misunderstood or you have any extra details let me know and i can try again

Thanks for your swift response.

I believe my question was misunderstood.

I have 300 files both in folder 1 and folder 2.
The files are named according to userID.
Each files in folder 1 have almost 20 columns and over 200 rows.
Each files in folder 2 have almost 40 columns and over 400 rows.

Challenge:
I want to create a workflow using loops, that would check the filenames(by either userid) in both folders 1 and 2.
If the same naming condition is met. I mean, if they have same filenames. Therefore, it should append file one in folder 1 as sheet 1 and file two in folder 2 all into one excel file.

Okay thanks for clarifying, I think i get it now.

For that I would suggest using two list files/folders nodes to read all the names in both folders, then compare strings before loading into an excel reader to be printed into an excel writer which has multiple input nodes for each sheet. This can be done by having a loop once you have the lists generated and use a flow variable to store the matching ID’s, upon matching them you can have that pass along into the excel reader to print into the excel writer.

Only issue i foresee you running into is the excel writer node needs to be within the loop for this to execute as i understand it, you could maybe have it be off on a side branch so that it executes each time but you continue to have data passed along to keep the loop running.

Hope this was helpful, if i can try to answer any other questions feel free to let me know!
P

1 Like

You coul use list files/folder node to get all of the file paths from both folders together into one table in KNIME then group loop start based on file name (userid) then read the files and concatenate them together.
br

1 Like

Can you please help me with the procedures. I still can’t understand your solution.
My earlier solutions were as follows
I used two "List files/folders. Connected both folders to each "List files/folders.
Thereafter, i used two string manipulation (using the expression - regexReplace…)connected below
Thereafter, I used two Table row to variable loop start …connected it below
Thereafter, used two excel reader…connected it below
Thereafter, used two excel writer…connected it below
Finally, used two variable end.
However, i connected the first variable end variable loop end to the second “list files/folders”

Can you please help me with the procedures. I still can’t understand your solution
Do you mean i use a string manipulation??
Can you please help me with the procedures. I still can’t understand your solution
Here is my earlier solutions were as follows;
I used two "List files/folders. Connected both folders to each "List files/folders.
Thereafter, i used two string manipulation (using the expression - regexReplace…)
Thereafter, I used two Table row to variable loop start connected it below
Thereafter, used two excel reader
Thereafter, used two excel writer
Finally, used two variable end.
However, i connected the first variable end variable loop end to the second “list files/folders”

Could you take a screenshot of the layout of the workflow you’re working on? It could help clear up some confusion

Is the issue now that the loop isnt closing properly?

In my idea i had one single excel writer that i would then write file1 into sheet1 and file2 into sheet 2 but all within the same excel file. If you wanted them in the same sheet then you could concatenate before loading into the excel writer too

Okay youre very close to what I am thinking of as the solution

Everything looks right and if its executing properly thats great. I would rearrange it to have a single shared excel writer between the two groups of nodes and have it have two inputs which would print into respective sheets. In the excel writer node you can arrange this for multiple inputs to be steered towards specific sheets.

Im just not sure if it will allow the excel file to be written within two different loops, you’d also need a string of nodes to automatically name the files if it is able to handle everything

Exactly, it doesn’t allow the connection of two loops into one excel writer

@Bewaji2 it could look something like this:

The structure of the Files is like this. Folder1/File4.xlsx is deliberately missing checking the comparison:

Only the matching Excel Files will be imported and the be written to a new Excel file. You can adapt the elements and re-combine them. More examples with Excel here: Import EXCEL - a meta workflow trying to answer questions about importing data from Excel files – KNIME Community Hub

1 Like

Thanks for the solution.
I tried writing into "Base folder for the both excel writers but it results in an error.
Can you guide me from the “Table row to variable loop start”
Thanks

@Bewaji2 here you can see how to create a Path variable:

Also you could check out the “KNIME File Handling Guide” (yes it is long but maybe worth it :slight_smile: )

https://docs.knime.com/latest/analytics_platform_file_handling_guide/index.html#introduction

1 Like

Thanks for your help.

My question is still unfortunately opened. I haven’t gotten a solution.
The above workflow doesn’t seem to append sheet 1 and sheet 2

I want to achieve the following outcome

@Bewaji2 you can of course concatenate the two files and bring them into one. Your initial description suggested otherwise for me which is why it might be best to procure an example that represents your full challenge. Maybe you can adapt the one provided accordingly.

Sorry for the misunderstanding
Here is a detailed description of what I want to achieve

@Bewaji2 I always encourage planning since often only having a vague idea what to do makes things more complicated.

In your case I would encourage you to move to the practical side and check the example and see if it already does what you want or you can adapt it, or maybe come up with your set of sample files to explain what it is you want to do.

To make it add to a separate sheet is actually really simple. You can increase the number of input ports on the excel writer and by doing so you can route each input to a different sheet which you can name within the node.
If youre able to get the output you want and its just fitting into a single excel file is the last problem, this should deal with that

Screen Shot 2023-05-11 at 9.54.29 AM

It is actually not simple. I’ve got the solution from someone else not on the forum. I’ll share the solution later in the weekend.

Thanks for your contributions.

I do appreciate

1 Like