Skip to main content
Question

Dynamic Excel Writer datatype

  • September 26, 2017
  • 8 replies
  • 7 views

Forum|alt.badge.img

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

david_r
Celebrity
  • September 26, 2017
Unfortunately the screenshot doesn't show.

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • September 26, 2017

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


Forum|alt.badge.img
  • Author
  • September 26, 2017
david_r wrote:
Unfortunately the screenshot doesn't show.
Sorry - the screenshot should be there now.

 


Forum|alt.badge.img
  • Author
  • September 26, 2017
erik_jan wrote:

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.

 


david_r
Celebrity
  • September 26, 2017

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.


Forum|alt.badge.img
  • Author
  • September 26, 2017
david_r wrote:

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.

 


david_r
Celebrity
  • September 26, 2017

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.


Forum|alt.badge.img
  • Author
  • September 27, 2017
david_r wrote:

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. 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings