# Excel Reader Sheet name in loop does not change

**URL:** <https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119>\
**Category:** KNIME Analytics Platform\
**Tags:** excel, bug\
**Created:** [September 16, 2021, 12:34pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119 "2021-09-16T12:34:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Till\_H](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@Till\_H](https://forum.knime.com/u/Till_H)\
**Post date:** [September 16, 2021, 12:34pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/1 "2021-09-16T12:34:33Z")

</div>

Hello everyone,

I am experiencing a bug when reading various worksheets from an Excel file. The data is read in per sheet depending on its line position and then processed further. For this purpose, I use a loop, which first lists all sheets in the file and then imports the desired sections via an Excel reader. Using rules engines, I then get my flow variables, which I put into the reader. The first iteration works fine, but on the second the  
sheet does not change (despite the flow variable changing). Is this something someone has experienced before?

 ![flowvariables](https://forum-cdn.knime.com/uploads/default/original/3X/4/e/4eea69fde82acb545a7bf00cb75331df7815b88b.jpeg)  
 ![reader1](https://forum-cdn.knime.com/uploads/default/original/3X/6/7/67662a3dfcbeea47d7f916188b5658675e3a2552.jpeg)  
 ![reader2](https://forum-cdn.knime.com/uploads/default/original/3X/0/9/09ae2ec6d7fdf5892bf299c3256b06428f7e6a35.jpeg)

(Some things are blackened due to confidentiality)

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 16, 2021, 1:39pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/2 "2021-09-16T13:39:16Z")

</div>

Hi @Till_H , when you say that the sheet name does not change, are you referring to what you are showing in your 2nd screenshot, that is the configuration window of the Excel Reader? If that is the case, this is how Knime behaves, it will not change the name there, it will simply overwrite it at runtime with the value of the flow variable.

Also, you can compare with your 1st screenshot where it’s at the 2nd iteration, the Sheet value is DE3M30, while the first sheet as you mentioned it in the 2nd screenshot is DE2540.

---

<div class="post-metadata">

**Author:** ![elsamuel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@elsamuel](https://forum.knime.com/u/elsamuel)\
**Post date:** [September 16, 2021, 2:17pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/3 "2021-09-16T14:17:38Z")

</div>

This process works fine for me.  
Do you get any error messages?

> [@Till\_H](#):
>
> For this purpose, I use a loop, which first lists all sheets in the file and then imports the desired sections via an Excel reader. Using rules engines, I then get my flow variables, which I put into the reader

I’m having a hard time picturing this workflow. Can you share it? We’d really need to see how the nodes are all configured.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [September 16, 2021, 3:41pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/4 "2021-09-16T15:41:26Z")

</div>

@Till_H maybe you can check this example and see if it does work on your machine and maybe you can adapt it to your needs or use it to demonstrate your problem.

> **[This workflow demonstrates how to use the new Excel Reader and path variables...](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_excel_new_node_list_sheets~qMKBYi5-YsStXUsl)**
>
> This workflow demonstrates how to use the new Excel Reader and path variables and read Excel sheets There seems to be some questions about how to use the new E…

---

<div class="post-metadata">

**Author:** ![Till\_H](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@Till\_H](https://forum.knime.com/u/Till_H)\
**Post date:** [September 17, 2021, 7:48am UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/5 "2021-09-17T07:48:38Z")

</div>

This is part of my workflow where the error happens:  
 ![overview1](https://forum-cdn.knime.com/uploads/default/original/3X/e/c/ec5558ab5db113f69064a5cdd97407d715422121.jpeg)  
Both Excel Readers read in the same file ( the bottem one with correct the values). All is encapsulated in a loop. So the first iteration (DE2540) is read in and the loop continues, but does not read the values for the next sheet (DE3M30) in the next iteration, but the values from the first (DE2540). The metanode (“Formatting for reading in data”) does give out the value DE3M30, which you can see in the picture above. I tried switching the Sheet selection from “Select sheet with name” to the two other possibilities, but with no result.

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [September 17, 2021, 10:41am UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/6 "2021-09-17T10:41:42Z")

</div>

Hello @Till_H,

it would be helpful if you can create and share workflow with above described behavior that uses dummy data. Otherwise we can only guess and one guess would be something goes wrong when reading same Excel file at the same time with two Excel Reader nodes.

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 17, 2021, 2:32pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/7 "2021-09-17T14:32:36Z")

</div>

Hi @Till_H , this option works only if you choose the “Select sheet with name”, so for sure it won’t work with the other 2 options.

Instead of waiting for your workflow, which would still be good to have, I put together a demo that works, so perhaps you can compare with your workflow if it’s easier.

The sample file has 5 sheets, with simple data (this is not meant to do data manipulation or any operation, but only to demo reading through all the sheets of the file), and I’ve renamed the sheets so that there is no pattern in the names:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/5/f/5fbbaca38e7ca7ccb3e14738962b03b22b1ecccc.png)  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/8/3/836ae44187c1bfb0c40639a43196113ee5a93dd2.png)  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/c/3ccc965aad13ec7560628091574382b812b7d70b.png)  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/e/1e096d4fc1c4bb1c90d8ea55b800f503a44c189c.png)  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/a/3/a38b372475dfdac5b6c48e4dd349a3c73a3bf62e.png)

Workflow looks like this:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/b/3ba590ff883e357db31fd53a9e99d0174f45fdba.png)

From the first node, I extract the file path and the sheets. Results:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/6/c65a521f4e7f124b0d286eee40b97822750f9347.png)

I then loop through each row which will produce the variable `Path` using the value from the column `Path`, and a variable `Sheet` using the value from the column `Sheet`

In the Excel Reader’s Flow Variables, you just use the Path and Sheet variables as follows:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/1/2/12564d2ea1349c7f021f94788de6b4b9ecfe2174.png)

In the Settings tab, you just need to make sure that you are using the “Select sheet with name” option, and that’s it. The name is controlled by the flow variables:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/4/e42eaa08c4dcf103777b6135587028cf0b25abdc.png)

Don’t mind the name from the drop down. This is a bit of an inconsistency from Knime where it greys out/disables the “Read from” drop down and the file field in the Input location when the path is controlled by a flow variable, but does not grey out/disable the drop down of the “Select sheet with name” when the sheet name is controlled by a flow variable. As I said, ignore it, it will be overwritten at runtime.

As an additional test, I’m adding the name of the sheet as a new column called Source inside the loop so we can capture the sheet name at each iteration.

Here’s the final results:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/6/061c49f3fb9089f432fb72d40e2f275035d15b12.png)

So, it’s working fine as expected.

Here’s my demo workflow if you want to compare with yours (the Excel file is included): [Excel read multiple sheets.knwf](https://forum.knime.com/uploads/short-url/lqhZhVOE8EbVpSjEZiFm5juNnXh.knwf) (23.0 KB)

---

<div class="post-metadata">

**Author:** ![Till\_H](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@Till\_H](https://forum.knime.com/u/Till_H)\
**Post date:** [September 20, 2021, 12:43pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/8 "2021-09-20T12:43:24Z")

</div>

Hi @bruno29a , thanks for the detailed solution. My workflow looks like yours ( a bit more complex), but did not work. I scraped everything and rebuild it, now i don’t have any more problems. Not quiet sure what the error was.

---

<div class="post-metadata">

**Author:** ![bruno29a](https://forum-cdn.knime.com/user_avatar/forum.knime.com/bruno29a/32/28802_2.png) [@bruno29a](https://forum.knime.com/u/bruno29a)\
**Post date:** [September 20, 2021, 12:58pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/9 "2021-09-20T12:58:37Z")

</div>

Hi @Till_H , no problem. It was probably a config setting. I’m glad that your issue is solved.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [September 27, 2021, 12:59pm UTC](https://forum.knime.com/t/excel-reader-sheet-name-in-loop-does-not-change/36119/10 "2021-09-27T12:59:10Z")

</div>

Closed on September 27, 2021, 12:59pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
