Skip to main content
Solved

Set cell width in dynamic Excel writer


Forum|alt.badge.img

Hello, is it possible to set the cell/column width in a dynamic Excel Writer. I can imagine to precalculate the width for each column or to use a auto mode. Hendrik

Best answer by helmoet

Hi @hendrik​ @xiaomengatsafe​ @gio​ @krisvesweco​ , I faced the same problem writing a dynamic feature type on an Excel writer, and this is the solution I came up with:

DynamicExcelAndColumnWidthThe warnings do not show up anymore and Excel is generating correct column widths. No post processing needed.

View original
Did this help you find an answer to your question?

10 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • June 9, 2017

if you have the python module

"xlsxwriter" then you can use the PythonCaller.

Its easy, look for examples on stack exchange (for instance)


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • June 12, 2017

..bad advise?


Forum|alt.badge.img
  • Author
  • June 12, 2017

Hi gio,

i could use this to edit the Excel file in a post process. In my opinion this isn't the optimal solution but i assume that there is no direkt FME function.

Hendrik


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • June 12, 2017

There is no fme solution, though I think they could provide it.

But you can use the pythoncaller with the xlsxwriter python module which you can download to do it.

I fail to see why this would invoke negative reactions...that's all. (thanks for the deduction in negatives though..;)

You can also use windows api to make the columns fit the content hwne writing, also using python (or tcl, or java)


krisvesweco
Contributor
Forum|alt.badge.img+4
  • Contributor
  • April 24, 2019

Did you find a better solution rather than postprocessing?


xiaomengatsafe
Safer
Forum|alt.badge.img+3
krisvesweco wrote:

Did you find a better solution rather than postprocessing?

Hi @krisvewsp, than you for your interest in this scenario. This other post has a potential solution suggested by David_r (April 12th). Although it might be a slow translation, if you are working with a large dataset. There is also an idea tracking the interest for an easier solution for this problem. Please add your vote and comment to let us know of your interest! Thank you!


krisvesweco
Contributor
Forum|alt.badge.img+4
  • Contributor
  • April 26, 2019
xiaomengatsafe wrote:

Hi @krisvewsp, than you for your interest in this scenario. This other post has a potential solution suggested by David_r (April 12th). Although it might be a slow translation, if you are working with a large dataset. There is also an idea tracking the interest for an easier solution for this problem. Please add your vote and comment to let us know of your interest! Thank you!

Thanks! Not sure how that would help setting the column width's in the excel writer? In the log I can see that I get errors like this: 

Excel Writer: Invalid column width 'width' specified for column 'M2_RevAvser5' of sheet 'd_y_n'. Value must be numeric. Using Excel default column width

Is there an existing column attribute to specify the column width for the excel writer? 


xiaomengatsafe
Safer
Forum|alt.badge.img+3
krisvesweco wrote:

Thanks! Not sure how that would help setting the column width's in the excel writer? In the log I can see that I get errors like this: 

Excel Writer: Invalid column width 'width' specified for column 'M2_RevAvser5' of sheet 'd_y_n'. Value must be numeric. Using Excel default column width

Is there an existing column attribute to specify the column width for the excel writer? 

Hi @krisvewsp, my initial idea was that david_r's method can be used in combination with a dynamic workflow where destination schema is derived from a schema feature. This method in theory should allow us to take the max string length and set the schema feature with that number. e.g. fme_data_type fme_varchar(14), where 14 is the result of the max string length calculation.  

But in my test, this didn't seem to change how wide the column that displays in MS Excel. I still needed to double click on the column boarder to have it fit the width of the text in that column. So, it didn't work as I expected. 

I'm out of ideas at the moment... 


helmoet
Forum|alt.badge.img+8
  • Best Answer
  • November 17, 2020

Hi @hendrik​ @xiaomengatsafe​ @gio​ @krisvesweco​ , I faced the same problem writing a dynamic feature type on an Excel writer, and this is the solution I came up with:

DynamicExcelAndColumnWidthThe warnings do not show up anymore and Excel is generating correct column widths. No post processing needed.


oscarwillems
Contributor
Forum|alt.badge.img+13
  • Contributor
  • April 15, 2022
helmoet wrote:

Hi @hendrik​ @xiaomengatsafe​ @gio​ @krisvesweco​ , I faced the same problem writing a dynamic feature type on an Excel writer, and this is the solution I came up with:

DynamicExcelAndColumnWidthThe warnings do not show up anymore and Excel is generating correct column widths. No post processing needed.

This works great! But depending on your language setting of Excel its either ; or , in the "width,x" part (Dutch is ; while English Excel is ,) the way it works in your functions in Excel


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