# Read Excel Tables

**URL:** <https://forum.knime.com/t/read-excel-tables/27607>\
**Category:** KNIME Analytics Platform\
**Tags:** excel\
**Created:** [September 24, 2020, 9:08am UTC](https://forum.knime.com/t/read-excel-tables/27607 "2020-09-24T09:08:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmor](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/9fc29f/32.png) [@cmor](https://forum.knime.com/u/cmor)\
**Post date:** [September 24, 2020, 9:08am UTC](https://forum.knime.com/t/read-excel-tables/27607/1 "2020-09-24T09:08:58Z")

</div>

Hello!

how can I read tables from Excel files? I mean formatted tables (the usual CTRL+T).  
I have a bunch of Excel files, from which I should read a single table, which has the same exact name in all files.  
Is there a connector that allows that?

Thanks!

---

<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 24, 2020, 9:23am UTC](https://forum.knime.com/t/read-excel-tables/27607/2 "2020-09-24T09:23:32Z")

</div>

Hello @cmor,

welcome to KNIME Community!

To my knowledge this is not possible with KNIME native nodes. Probably Python can be used as a workaround. See this topic for example on how to write Table to Excel:

> [@Write KNIME table to Excel as table (proposal)](https://forum.knime.com/t/write-knime-table-to-excel-as-table-proposal/14044/10):
>
> OK I think now I get what you want. Yes it is possible to first save a table as a ‘pure’ excel file and then define a range as a table object “All” which you can later use to refer to it. In my example the no of lines that the object would have is assigned dynamically while the columns are fixed but one might also be able to change that to a dynamic setting. After the ‘raw’ KNIME export: After openpyxl got to work: (cf. [https://openpyxl.readthedocs.io/en/stable/…](https://openpyxl.readthedocs.io/en/stable/worksheet_tables.html)

Br,  
Ivan

---

<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 24, 2020, 9:26am UTC](https://forum.knime.com/t/read-excel-tables/27607/3 "2020-09-24T09:26:50Z")

</div>

We had a recent discussion about this. Here is an example where you would identify tables by a keyword and then import them. You might have adapt that to your current format and see if there are regularities in the data that you can identify and use.

> [@Loop on the basis of single Excel sheet data](https://forum.knime.com/t/loop-on-the-basis-of-single-excel-sheet-data/26510/7):
>
> OK it was slightly more complicated than I initially thought. But I hope it does work now: give each line a unique ID to identify them later identify the ‘heads’ of the tables (“FORMNAME”) like you already did use moving aggregate to give the heads unique numbers bring these numbers back to the data fill the intermediate (empty) cells with the head’s number use a group loop on the blocks identified by the head numbers extract the first line as column names make sure empty columns that would ju…

@ipazin is refering to the possibility of creating Excel-Tables with the help of Python.

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [September 24, 2020, 5:29pm UTC](https://forum.knime.com/t/read-excel-tables/27607/4 "2020-09-24T17:29:41Z")

</div>

What about reading the whole sheet and remove missing rows and columns?

---

<div class="post-metadata">

**Author:** ![cmor](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/9fc29f/32.png) [@cmor](https://forum.knime.com/u/cmor)\
**Post date:** [September 25, 2020, 5:57am UTC](https://forum.knime.com/t/read-excel-tables/27607/5 "2020-09-25T05:57:42Z")

</div>

Thank you all for your replies!  
@ipazin Thank you! I would hope for a quicker solution for such a simple task though.  
@Daniel_Weikert and @mlauber71 I think this is the right direction! I cannot remove the empty rows below, because they’re not empty (meaning I have a table above and another table below).  
However, the table I need occupies the same cell range in all files, always in the first sheet.

I can definitely exploit this! I guess I must just learn how to store the first sheet name as a variable to be able to read from the first sheet no matter the name (the first sheet’s name is not always the same in all files).

It wouldn’t be bad to be able to exploit the fact that tables are named ranges though…that would make everything way faster!

---

<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 25, 2020, 6:54am UTC](https://forum.knime.com/t/read-excel-tables/27607/6 "2020-09-25T06:54:42Z")

</div>

@cmor I am notexactly sure what you mean by ‘simple task’ - if you know where your table is and know the line of the head you could just tell the Excel Reader what to read

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/6/f6cc7de08481bd8235884e3e399e5b7078ff9acf.png)

If you want to identify the formatted tables you might have to resort to Python

> <https://stackoverflow.com/questions/43941365/openpyxl-read-tables-from-existing-data-book-example>

> **[Access Excel Tables with Python](https://samukweku.github.io/data-wrangling-blog/spreadsheet/python/pandas/openpyxl/2020/05/19/Access-Tables-In-Excel.html)**
>
> Extract data from a defined table in a spreadsheet

* * *

If you want to explore further options how to deal with Excel (import) I have a collection for that prepared. The identification of formatted tables would be a new feature for sure 🙂

> **[Import EXCEL - a meta workflow trying to answer questions about importing...](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_excel_import_meta_workflow?u=mlauber71)**
>
> Import EXCEL - This workflow will act as a meta workflow trying to answer questions about importing data from Excel files One of the most frequently asked ques…

And then if you could provide us with examples that cover your whole challenge one might be able to further explore possible solutions.

---

<div class="post-metadata">

**Author:** ![cmor](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/9fc29f/32.png) [@cmor](https://forum.knime.com/u/cmor)\
**Post date:** [September 25, 2020, 7:14am UTC](https://forum.knime.com/t/read-excel-tables/27607/7 "2020-09-25T07:14:49Z")

</div>

Thank you very much for your quick and detailed reply!

I’m indeed using the Excel reader in the end 👍🏻

I’ll try to provide more detail:

I need to read several excel files from a folder. (Excel reader is fine here)  
I need to read the same (one-row + header) table from each file, irrespective in which sheet it is (here is Excel reader no longer enough, because it doesn’t allow me to identify a named range)

Since the table I need is always in the first sheet and always occupies the same range of cells, I can use the Excel reader, choosing the first sheet option.  
(Note that I’m just lucky here, because technically the table could be in any other sheet after the first one)

All I need to do now is learn how to store the first sheet name as a variable, so the loop doesn’t fail as soon as it finds an Excel file that has a different name for the first sheet.

---

<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 25, 2020, 1:58pm UTC](https://forum.knime.com/t/read-excel-tables/27607/8 "2020-09-25T13:58:15Z")

</div>

Hello @cmor,

> [@cmor](#):
>
> All I need to do now is learn how to store the first sheet name as a variable, so the loop doesn’t fail as soon as it finds an Excel file that has a different name for the first sheet.

Don’t understand this cause Excel Reader will not fail if configured to always read first sheet.

Also seems to me you can use option _Read files in folder_ in order to avoid loop. (It will work only if you have same structure in each file)

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![cmor](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/c/9fc29f/32.png) [@cmor](https://forum.knime.com/u/cmor)\
**Post date:** [September 25, 2020, 2:15pm UTC](https://forum.knime.com/t/read-excel-tables/27607/9 "2020-09-25T14:15:07Z")

</div>

Hello @ipazin!  
I though so too and that was exactly my first try. However, it throws an error as soon as it gets to the second file, saying it cannot find a sheet named like the first sheet of the first file ☹

Note that the table I need occupies the same range of cells, but not always in a sheet with the same name.

That’s why I thought storing the sheet names may solve the issue…

---

<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 25, 2020, 3:19pm UTC](https://forum.knime.com/t/read-excel-tables/27607/10 "2020-09-25T15:19:34Z")

</div>

You could list the sheets of all excel files and proceed only those that match criteria

> **[Read an XLS file – scottF](https://hub.knime.com/knime/spaces/Examples/latest/01_Data_Access/01_Common_Type_Files/07_Reading_Excel_Files)**
>
> This workflow demonstrates how to read an XLS file using the XLS Reader node. It contains three workflows. The goal of each workflow is to read accounting data…

In this example also all sheets are listed and you can adapt how the files should be processed

> **[m\_001\_import\_r\_excel\_unite\_fields – mlauber71](https://hub.knime.com/mlauber71/spaces/Public/latest/kn_example_r_excel_find_united_fields/m_001_import_r_excel_unite_fields)**
>
> use R to list excel sheet names, extract the data and keep only columns that are present in all sheets use R package readxl to list all sheets of excel files f…

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [September 25, 2020, 5:02pm UTC](https://forum.knime.com/t/read-excel-tables/27607/11 "2020-09-25T17:02:18Z")

</div>

the read files option also does not work if the datatype for a column is different. So I think the loop is still the better option

---

<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 28, 2020, 11:39am UTC](https://forum.knime.com/t/read-excel-tables/27607/12 "2020-09-28T11:39:55Z")

</div>

Hello @cmor,

ok. I see now. As @mlauber71 pointed out you can use [Read Excel Sheet Names (XLS)](https://kni.me/n/5OfjoFliwz1jssNV) node to get sheet names and then [Row Filter](https://kni.me/n/jd2U-FYTI8jCbQls) to leave only first row which has the name of first sheet. Use [Table Row to Variable](https://kni.me/n/_pUeaJb6ZvLqcV7X) node and control sheet name with newly created flow variable.

@Daniel_Weikert you are right, currently to use that option one must be sure that data structure is the same.

Br,  
Ivan

---

<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:** [March 29, 2021, 11:40pm UTC](https://forum.knime.com/t/read-excel-tables/27607/13 "2021-03-29T23:40:54Z")

</div>

Closed on March 29, 2021, 11:40pm UTC

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