Solved

i would like to read the latest excel file in specific folder


Badge +13

i have read this article and it is useful for me ,what am i looking for but i am not sure ,how could i let feature reader to work .

 

https://community.safe.com/s/question/0D54Q000080hQidSAE/pick-up-latest-file-from-folder-location

 

i have found one latest file that i am looking to from sampler , but how could i open this file to check the data inside and extract attributes .

the file format is excel

 

1. As your source, use a Directory and File Pathnames reader.

 

2. A Sorter that sorts descending on path_modified_date.

 

3. A Sampler that only lets the first feature pass.

 

4. A FeatureReader where Dataset is set to path_windows.

 

this is parameters that i did for feature reader , should i change something ?

FeatureReader

icon

Best answer by nielsgerrits 6 April 2022, 15:33

View original

10 replies

Userlevel 6
Badge +33

This is how I do it, so I think you are doing it right. Now choose the Generic output port and use an AttributeExposer downstream of the FeatureReader. You can import the attribute names from a file in the AttributeExposer.

 

Exposing attributes can't be done dynamic. If you think about it, there is no use for this. If you can't predict that "AttributeA" will be in one of the next files, you can't configure transformers to process it.

 

If you need to write the file dynamic you can use the Schema Feature from the FeatureReader and a FeatureWriter set to Dynamic Schema Definition.

The SchemaScanner transformer can also be used to create a Schema Feature.

Userlevel 5
Badge +25

You're on the right track.

 

When you're developing your workspace FME doesn't know attribute values, so it doesn't know which file to pick for the FeatureReader. So, just for development, you can manually select a file. Make sure to pick the Generic output port option. Then when you've connected the rest of your workspace you can set the dataset value back to the path_windows attribute

Badge +13

This is how I do it, so I think you are doing it right. Now choose the Generic output port and use an AttributeExposer downstream of the FeatureReader. You can import the attribute names from a file in the AttributeExposer.

 

Exposing attributes can't be done dynamic. If you think about it, there is no use for this. If you can't predict that "AttributeA" will be in one of the next files, you can't configure transformers to process it.

 

If you need to write the file dynamic you can use the Schema Feature from the FeatureReader and a FeatureWriter set to Dynamic Schema Definition.

The SchemaScanner transformer can also be used to create a Schema Feature.

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

Userlevel 6
Badge +33

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

"how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id"

These records where id is missing are probably empty rows in the excelsheet?

 

The AttributeExposer will expose the field id for each feature. You can work around this by first exposing fme_feature_type, which is sheet name when reading Excel, use an AttributeFilter to split features on sheet name, then use different AttributeExposers for different sheets.

Badge +13

You're on the right track.

 

When you're developing your workspace FME doesn't know attribute values, so it doesn't know which file to pick for the FeatureReader. So, just for development, you can manually select a file. Make sure to pick the Generic output port option. Then when you've connected the rest of your workspace you can set the dataset value back to the path_windows attribute

Thanks ,it works great

Badge +13

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

i have tried your idea to expose only fme_feature_type but it fme_feature_type has only path output , it did not show me the sheets name.could you please upload small workspace with ur idea and thanks for help .

Userlevel 6
Badge +33

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

Sure. Added workspace template, data included, so you can reproduce it instantly.

2022-04-06_11h21_58

Badge +13

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

 

Thanks for help .but i have fme version 2020 so the workspace is not completed ,could you please save it to work at fme 2020 , and did you use at feature reader Directory and File Pathnames ,data set path windows or what did you use at each Feature reader ? pic.

Userlevel 6
Badge +33

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

I'm limited in time atm but yes, first featurereader is a directory and file pathnames reader, exposer is exposing path_windows and the second is an excelreader where it uses path_windows to read the file.

Badge +13

Thanks for reply ,

i have used AttributeExposer of Feature reader but i have more than one sheets at each excel file .

say sheet 1 includes 5 attributes and sheet 2 includes 8 attributes and so on but in each sheet includes same attribute name called id .

how will feature reader recognize if i need to read id from sheet 1 or sheet 2 ?

because i found the output of feature reader is missing at attribute id

 

i know the attributes names that i will get from the excel file but i have five sheets and each sheet includes different attributes names

what is the best solution at my case to read the excel file ?

Thanks ,it works

Reply