Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Excel Cell's width

Former Member
0 Likes
820

I using Ole2 function Can i fixed Cell Width because they are some short.


Here is my code.

Thanks.


FIELD-SYMBOLS <f1>  TYPE any.

   DATA : h            TYPE ,

          lv_tabix(2)  TYPE ,

          lv_field(25) TYPE .

   lv_tabix = 1.

* start Excel

   CREATE OBJECT h_excel 'EXCEL.APPLICATION'.

*  PERFORM ERR_HDL.

   SET PROPERTY OF h_excel  'Visible' = 1      .

   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

     EXPORTING

       text   = text-008

     EXCEPTIONS

       OTHERS = 1.

   CALL METHOD OF

       h_excel

       'Workbooks' = h_mapl.

   CALL METHOD OF

       h_mapl

       'Add'  = h_map.

   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

     EXPORTING

       text   = text-009

     EXCEPTIONS

       OTHERS = 1.

   LOOP AT it_fieldcat.

     PERFORM fill_cell USING 1 lv_tabix 5 5 2 2

             it_fieldcat-scrtext_l .

     lv_tabix = lv_tabix + 1.

   ENDLOOP.

   CLEAR lv_tabix.

   LOOP AT <fs_table> ASSIGNING <fs_wa> .

     h = sy-tabix + 1.

     lv_tabix = 1.

     LOOP AT it_fieldcat.

       CONCATENATE  '<fs_wa>-' it_fieldcat-fieldname INTO lv_field.

       ASSIGN (lv_field) TO <f1> .

       CHECK <f1> IS ASSIGNED .

       PERFORM fill_cell USING h lv_tabix 1 0 2 2 <f1>.

       lv_tabix = lv_tabix + 1.

     ENDLOOP.

     CLEAR lv_tabix.

   ENDLOOP .

   CONCATENATE sy-repid '_' sy-datum+6(2) '_' sy-datum+4(2) '_'

               sy-datum(4) '_' sy-uzeit '.XLSX' INTO filename.

   CALL METHOD OF

       h_map

       'SAVEAS'

     EXPORTING

       #1       = filename.

   FREE OBJECT h_excel.

ENDFORM.

FORM fill_cell  USING i j bold col line fit val.

  CALL METHOD OF

         h_excel

         'Cells' = h_zl

       EXPORTING

         #1      = i

         #2      = j.

     SET PROPERTY OF h_zl 'Value'     = val  .

     GET PROPERTY OF h_zl 'Columns'   = h_d  .

     GET PROPERTY OF h_zl 'Font'      = h_f  .

     SET PROPERTY OF h_f  'Bold'      = bold .

     SET PROPERTY OF h_f  'ColorIndex'= col  .

ENDFORM.                    " FILL_CELL

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
747

Search tool can be used to find out the answer.

After selecting column, you have to set property ColumnWidth.

For futher info, read correct answer of

2 REPLIES 2
Read only

Former Member
0 Likes
748

Search tool can be used to find out the answer.

After selecting column, you have to set property ColumnWidth.

For futher info, read correct answer of

Read only

0 Likes
747

Thanks