Question

Dynamic Excel Writer datatype

  • 26 September 2017
  • 8 replies
  • 7 views

Badge

Hello, i try to create dynamic Excel data i a german environment and have a problem with the datatype.

As you see fme detects the same value as utf-8 and 64 bit real. Real values generate correct output in excel as number but utf is put out as string with dot as decimal limitter.

Is there any way to force the datatype to real?

Hendrik


8 replies

Userlevel 5
Unfortunately the screenshot doesn't show.
Userlevel 2
Badge +17

Could you use a template for the output? In that case you can format the cells to the numeric format you desire.

Badge
Unfortunately the screenshot doesn't show.
Sorry - the screenshot should be there now.

 

Badge

Could you use a template for the output? In that case you can format the cells to the numeric format you desire.

I don't think so. Because the attributes are dynamically merged form the input features.

 

Userlevel 5

Sounds like it could be an issue with locale settings.

Try using a StringReplacer to replace "." with "," on your numeric attributes just before the writer.

Badge

Sounds like it could be an issue with locale settings.

Try using a StringReplacer to replace "." with "," on your numeric attributes just before the writer.

This is my current solution but this brings two problems.

 

1. You need to convert the data in excel from string to number.

 

2. I can't do this just before the writer because of the dynamic attributes i can't edit.

 

 

I hope there is a more comfortable solution.

 

Userlevel 5

Try the following in a PythonCaller:

import fmeobjects
def CastToFloat(feature):
    for attr in feature.getAllAttributeNames():
        value = feature.getAttribute(attr)
        if value:
            try:
                feature.setAttribute(attr, float(value))
            except ValueError:
                pass

Remember to set "Class or function to process features" as CastToFloat.

It will iterate over all the available attributes on each feature and convert them to float, whenever possible.

If you have huge datasets and/or a large amount of attributes this might not very efficient, however.

Badge

Try the following in a PythonCaller:

import fmeobjects
def CastToFloat(feature):
    for attr in feature.getAllAttributeNames():
        value = feature.getAttribute(attr)
        if value:
            try:
                feature.setAttribute(attr, float(value))
            except ValueError:
                pass

Remember to set "Class or function to process features" as CastToFloat.

It will iterate over all the available attributes on each feature and convert them to float, whenever possible.

If you have huge datasets and/or a large amount of attributes this might not very efficient, however.

Many thanks this works fine for me. 

 

Reply