# Get data based on specific text

**URL:** <https://forum.knime.com/t/get-data-based-on-specific-text/61689>\
**Category:** KNIME Analytics Platform\
**Created:** [February 14, 2023, 2:53am UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689 "2023-02-14T02:53:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aalnabelsi](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@aalnabelsi](https://forum.knime.com/u/aalnabelsi)\
**Post date:** [February 14, 2023, 2:53am UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/1 "2023-02-14T02:53:04Z")

</div>

Hello everyone,

How can I extract data from multiple sheets if the table position is different sometimes, but I know that the column I need will contain a specific texts at the top and at the bottom, so I want to get the rows between them plus the data in next 3 columns.

---

<div class="post-metadata">

**Author:** ![ScottF](https://forum-cdn.knime.com/user_avatar/forum.knime.com/scottf/32/61316_2.png) [@ScottF](https://forum.knime.com/u/ScottF)\
**Post date:** [February 14, 2023, 4:53pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/2 "2023-02-14T16:53:17Z")

</div>

Hi @aalnabelsi and welcome to the forum.

For best results, please post an example of both your input data, and what you expect your output to look like. Your description is a bit vague. Also, if you have an example workflow showing what you’ve already tried, you could upload that as well.

This topic may be useful for you:

> [@How to Best Ask For Help on the Forum](https://forum.knime.com/t/how-to-best-ask-for-help-on-the-forum/60708):
>
> How to Best Ask for Help Before we go into this subject: first, and absolutely foremost: always search before posting your question. Your question may have already been posted and answered in the forum. Searching can help you save loads of time and effort! Ok, with that out of the way, let’s go: How can you write a post that is most likely to get the help you need? You might think that logically, a good title for your post would be “Help with an error”, right? Well… not exactly. Put yourself …

---

<div class="post-metadata">

**Author:** ![aalnabelsi](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@aalnabelsi](https://forum.knime.com/u/aalnabelsi)\
**Post date:** [February 14, 2023, 6:53pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/3 "2023-02-14T18:53:05Z")

</div>

Thanks @ScottF for your reply.

I will try to make it clear now with excel samples I uploaded in Excel (inputs/output). I have over 200 files and some files have multiple sheet from where I need to extract the data.

There is no standard format for those tables I am trying to consolidate . The only thing it might help is to identify some fixed titles (text) to use them as a reference to extract the data I need

**Input**  
[150. Bulk AAAAAA -DXXM050.xlsx](https://forum.knime.com/uploads/short-url/bP1awzOWvUTTPKsf6FeVPsA1wqg.xlsx) (51.4 KB)

In file DXXM050 I added some comments explaining what I need to get the result and the same will be implemented on the other files

[159. Bulk AAAAAA -DXXM030.xlsx](https://forum.knime.com/uploads/short-url/zGIMoJZSh1GyzksAkLQnVGb4PK3.xlsx) (51.7 KB)

**Output**  
[Result.xlsx](https://forum.knime.com/uploads/short-url/pW00TkIEOIpJHUjQOX7Sz1Mg44I.xlsx) (22.2 KB)

I used the module below to get the data between the rows I need, but I still have add manually the column number where my reference is exist, but I want to automate the full process, so KNIME can find the tables I need to extract the data. Plus I need to know how to duplicate one cell in a new column.

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

Sorry for the complexity and if I am still not clear, but I can provide more details if required, and if there is no solution let me know please.

Thank you

---

<div class="post-metadata">

**Author:** ![ScottF](https://forum-cdn.knime.com/user_avatar/forum.knime.com/scottf/32/61316_2.png) [@ScottF](https://forum.knime.com/u/ScottF)\
**Post date:** [February 20, 2023, 4:39pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/4 "2023-02-20T16:39:45Z")

</div>

Based on a quick scan of your problem, it seems quite complex - mostly because you can never be certain of the format of the incoming table. I realize that’s not your fault, but if possible I would encourage who ever is providing you the data to standardize their formatting.

If that can’t be done, you are likely going to need to do a bit of scripting using something like the OpenPxyl package in Python to search for and identify rows and columns of interest. @mlauber71 has several sample workflows dealing with that package on the KNIME Community Hub that may be of use to you. (Maybe you are already doing this data search in the Java Snippet above, but since you only provided a screenshot, I’m not sure.)

Sorry that I can’t provide more useful feedback for you.

---

<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:** [February 21, 2023, 6:49pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/5 "2023-02-21T18:49:18Z")

</div>

> [@ScottF](#):
>
> f that can’t be done, you are likely going to need to do a bit of scripting using something like the OpenPxyl

@aalnabelsi I think you could do this with KNIME nodes by identifying the ‘blocks’ in the Excel Sheet and then applying the rules you described. The secret is in marking the start and possible end of the table/bock and then filling the empty lines with the missing values node as described here:

> [@Move head rows to a column](https://forum.knime.com/t/move-head-rows-to-a-column/45094/2):
>
> @willy_oracle typically you would mark all lines with a [Counter](https://kni.me/n/pVT_aAQrO1Jkt9cG). Then identify the ‘headers’ with a rule engine [IF Col1 LIKE “Head\*” =\> Counter] and keep that (starting) row in a separate column. Then you [fill the missings with the previous value](https://forum.knime.com/t/replace-placeholder-with-values-from-above/38602/4) so a block would emerge marking the data table: [image] So now you have the blocks marked an can use a [Table Row to Variable Loop Start – KNIME Community Hub](https://kni.me/n/q7loejCZ1HWH5hUr) or [Group Loop Start – KNIME Community Hub](https://kni.me/n/7a8fxq51Z1jrgXeM) to do something with the blocks (export them delet…

Please also note the linked threads there.

The sheets themselves might be identified by reading the sheets and selecting the ones that have the name part you described.

> **[Read Excel Sheet Names](https://hub.knime.com/knime/extensions/org.knime.features.ext.poi/latest/org.knime.ext.poi3.node.io.filehandling.excel.sheets.ExcelSheetReaderNodeFactory)**
>
> This node reads an Excel file and provides the contained sheet names at its output port. The performance of the reader node is limited (due to the underlying l…

Since these seem to be common questions I think about writing a blog about them.

---

<div class="post-metadata">

**Author:** ![aalnabelsi](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@aalnabelsi](https://forum.knime.com/u/aalnabelsi)\
**Post date:** [February 22, 2023, 10:05pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/6 "2023-02-22T22:05:07Z")

</div>

Thanks @ScottF. I am working to create a new template with standard format to simplify the process. For now I am trying to find a way to consolidate the old files (over 200 files)

---

<div class="post-metadata">

**Author:** ![aalnabelsi](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@aalnabelsi](https://forum.knime.com/u/aalnabelsi)\
**Post date:** [February 22, 2023, 10:15pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/7 "2023-02-22T22:15:30Z")

</div>

Thanks @willy_oracle for your help.

The start point will be finding the block contains “AA CONTRACT NO.” Java Snippet node I shared can find the first and last blocks but I still have to specify the column. I want it find the blocks without specifying the column. I will look at the details you shared and see if I can find a solution.

Here is what I included in Java Snippet

if (c\_B.equals(“AA CONTRACT NO.”)) {  
out\_start = ROWINDEX;  
} else {  
out\_start = null;  
}

if (c\_B.equals(“TOTAL AA UNIT COST”)) {  
out\_end = ROWINDEX;  
} else {  
out\_end = null;  
}

---

<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:** [May 23, 2023, 10:16pm UTC](https://forum.knime.com/t/get-data-based-on-specific-text/61689/8 "2023-05-23T22:16:22Z")

</div>

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