Skip to main content
Question

Dynamic Excel Writer datatype

  • Sep 26, 2017 2:24 PM UTC
  • 8 replies
  • 107 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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

david_r
Celebrity
  • Sep 26, 2017 2:29 PM UTC
Unfortunately the screenshot doesn't show.

erik_jan
Contributor
Forum|alt.badge.img+26
  • Contributor
  • Sep 26, 2017 2:32 PM UTC

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
  • Sep 26, 2017 2:32 PM UTC
Unfortunately the screenshot doesn't show.
Sorry - the screenshot should be there now.

 


Forum|alt.badge.img
  • Author
  • Sep 26, 2017 2:34 PM UTC

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
  • Sep 26, 2017 2:40 PM UTC

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
  • Sep 26, 2017 2:50 PM UTC

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
  • Sep 26, 2017 2:57 PM UTC

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
  • Sep 27, 2017 2:13 PM UTC

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.