abap2xlsx icon indicating copy to clipboard operation
abap2xlsx copied to clipboard

Column width optimization doesn't work without calling "calculate_column_widths"

Open blackmail24 opened this issue 1 year ago • 5 comments

In former versions (I can't tell exactly, it seems to have been installed in 2014) of abap2xlsx it used to work calling "set_auto_size" on the object "ColumnDimension": 1

In newer version (installed in november 22) column optimization has to be done on a column object e. g. by using a column iterator. But in comparison to the former version, column width optimization does not work without explicitly calling "calculate_column_widths" (worksheet object). 2

I also checked some example programs e. g. ZDEMO_TECHED9. "calculate_column_widths" is not called within this program and as a result the generated Excel file doesn't have optimized columns.

In my opinion "calculate_column_widths" should be called internally before generating an Excel file if at least one column has the autosize property set.

blackmail24 avatar Mar 21 '23 12:03 blackmail24

Yes this feature was changed few years ago, I can't say how it was working before that change, what was done and why, so I trust you. Do you think you can propose a fix/pull request? Thank you.

sandraros avatar Mar 21 '23 12:03 sandraros

NB: there is this discussion how it works now, especially code and demo program (in my comment): #646

sandraros avatar Mar 21 '23 12:03 sandraros

Unfortunately I can't support at the moment due to our infrastructure. I don't e. g. have a connection to github via abapGit. Currently I'm also not that familiar with abab2xlsx and I don't know your deploying process (how to test ...). If I could get some help, maybe I'm able to contribute in the future ...

blackmail24 avatar Mar 21 '23 13:03 blackmail24

Thanks, no problem, just asking for help :) If in the future you have the possibility to contribute, we'll try to help our best.

sandraros avatar Mar 21 '23 14:03 sandraros

I ran into the same problem

doing following works,

        DO lo_worksheet->get_highest_column( ) TIMES.
          lo_worksheet->get_column( zcl_excel_common=>convert_column2alpha( sy-index ) )->set_auto_size( abap_true ).
        ENDDO.
        lo_worksheet->calculate_column_widths( ).

larshp avatar Dec 12 '23 07:12 larshp