Skip to main content

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

Unfortunately the screenshot doesn't show.

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


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

 


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.

 


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.


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.

 


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.


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