Loop for Excel writer

Hi everyone,
I am new to KNIME and I have tried everything for the following:
image

How to create a new excel file based on the country. The new file will have each country name on new worksheet and contain data only related from that country. For example sheet1-“Canada” will have 5 entries from Canada, sheet2- “USA” will have 4 entries and so on.
Thank you

Could you upload your input file so potential helpers don’t have to manually create it.

1 Like

Hi and welcome to the forum.

Have you tried the forum search? There are many very similar question like yours.

It can be done easliy with the group loop start, excel writer combo:

image

  • Select Country as group identifier

  • set the Excel Writer options to append data if the files exists:

And add the variable “country” as sheet name:

You can find my example here:

3 Likes

Thank you for the solution, I tried it workflow. I was using end instead of variable loop. However, this workflow great on table but not for excel file, I tried it but it did not worked, I have uploaded mine workflow and excel file as well.
Book1.xlsx (9.0 KB)
Excel sheet loop.knwf (1.8 KB)

Hi @SatwinderGill , the workflow you uploaded was empty, so I’ll have to guess at what your problem is when using an excel file as you don’t actually tell us what error you are seeing.

My suspicion is that you ran the workflow supplied by @ActionAndi and then replaced the Table Creator with your spreadsheet. On running again, it then failed because the worksheet already existed.

If that was the problem, simply edit the Excel Writer so that where it says “fail” if sheet exists, you set it to “overwrite” i.e. on the line in @ActionAndi 's earlier screenshot that I have marked with the red boxes.

If that then resolves the problem, please mark @ActionAndi 's post as the solution :slight_smile:

1 Like

Sorry for the empty file, I am new to KNIME.

I have created this on community hub the work flow.
I did changed the file name but the problem I am facing is the output excel file creates only one country sheet for Example “Canada” and all the data from Canada. The loop work only once, I can’t make the loop iterate again to create other sheet. I used append write to excel file option every time I execute this workflow with new excel file name.

Hi SatwinderGill,

You may try the workflow below:

  1. Your data was not sorted, so I adjusted the configuration within the Group Loop Start node to ensure proper sorting.
  2. This is the approach I typically use when working with the Excel Writer node for similar tasks:

Best,

Alpay

Excelsheetloop.AZ.knwf (14.2 KB)

1 Like

Hi @SatwinderGill , I think the problem you have is as @alpayzeybek has said.

For some additional background on how to find out what is going on… when your Group Loop Start node has the red (x) on it, you can hover your mouse over that to get an idea of why it has failed.

The Group Loop Start node requires that the items that you are grouping by all appear together in contiguous groups. If they are not, you either need to sort them prior to the Group Loop Start (e.g. using a Row Sorter) or else as already mentioned, you need to configure the Group Loop Start node to do the sorting for you.

Configuring the Group Loop Start node, you’ll find the option under “Advanced Settings”. I have no idea why that is considered “advanced” since it appears to be fairly fundamental to the correct operation, but anyway that’s where it is!
image

Welcome to the KNIME community! :slight_smile:

4 Likes