Skip to main content

Hi all,

Recently, I've been trying to load an Excel file using Python Creator.

reader = fmeobjects.FMEUniversalReader('Excel', False)
reader.open(FME_MacroValuesF'SourceDataset_XLSXR'])
feature = reader.read()
while feature:
               attributes_list = feature.getAllAttributeNames()
               for attr in attributes_list:
                      attr_value = feature.getAttribute(attr)
                      feature.setAttribute(attr,attr_value)
               self.pyoutput(feature)
               feature = reader.read()
reader.close()

Unfortunately, the above reading process loses the feature schema.

Table of attributesIs it possible to use Python FME API to expose all attributes or load a feature schema from a source file?

Hi @kasobczyk​,

You cannot expose attributes within the workspace using the Python API, but you can create a schema feature to be used with a writer in dynamic mode.

 

The FMEUniversalReader.readSchema method will return the schema(s) for the source data as a feature. This is structured correctly for use with the FMEUniversalWriter addSchema method, but will need some manipulation before it can be used in workspace writer in Dynamic mode. To see the desired structure for Dynamic mode, add a FeatureReader pointing to the same file and examine the <schema> output feature.

 

The readSchema feature has the same attribute names as the data feature, but their contents are the fme data type. There is also a copy of each attribute prefaced with an asterisk, which contain the native data type. These will all need to be added to the attribute{}.name, attribute{}.fme_data_type and attribute{}.native_data_type lists needed for the dynamic schema.


Reply