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

How to adjust excel column width

Former Member
0 Likes
3,860

Hi Expert,

I need to write data into excel sheet using Excel OLE object, And now I've face the problem that I need to adjust column width of the excel sheet but I don't know how to work with Excel column.

I've record Excel Macro and got below code ..

Sub Macro2()

'

' Macro2 Macro

' Macro recorded 20/7/2009 by AA

'

'

Range("B1").Select

Columns("B:B").ColumnWidth = 21.57

End Sub

How to convert 'Columns("B:B").ColumnWidth = 21.57' to ABAP Code ?

Please give me an advice

Thanks in advance.

Nattapash

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,893

Hi Nattapash Changpant,

Try this Code :

DATA : columns TYPE ole2_object.

     CALL METHOD OF excel 'Range' = columns
      EXPORTING
      #1 = 'A1'
      #2 = 'B1'.

    set PROPERTY OF columns 'ColumnWidth' = '100'.

Regards,

Suneel G

Hi Expert,

I need to write data into excel sheet using Excel OLE object, And now I've face the problem that I need to adjust column width of the excel sheet but I don't know how to work with Excel column.

I've record Excel Macro and got below code ..

Sub Macro2()

'

' Macro2 Macro

' Macro recorded 20/7/2009 by AA

'

'

Range("B1").Select

Columns("B:B").ColumnWidth = 21.57

End Sub

How to convert 'Columns("B:B").ColumnWidth = 21.57' to ABAP Code ?

Please give me an advice

Thanks in advance.

Nattapash

3 REPLIES 3
Read only

Former Member
0 Likes
1,894

Hi Nattapash Changpant,

Try this Code :

DATA : columns TYPE ole2_object.

     CALL METHOD OF excel 'Range' = columns
      EXPORTING
      #1 = 'A1'
      #2 = 'B1'.

    set PROPERTY OF columns 'ColumnWidth' = '100'.

Regards,

Suneel G

Read only

0 Likes
1,893

Thank you very much Suneel G.

for singel column I use


call METHOD of gs_excel 'Cells' = gs_cell1
    exporting
      #1 = row_number
      #2 = column_number.

  call METHOD of gs_excel 'Range' = gs_column
    EXPORTING
      #1 = gs_cell1
      #2 = gs_cell1.

  SET PROPERTY OF gs_column 'ColumnWidth' = column_width.

I found ratio of column width of excel is about 5:1 for cm.

So if I want to adjust the width of column to 1 cm, I need to send column_width = 5.

Regards,

Nattapash C.

Edited by: Nattapash Changpant on Jul 20, 2009 7:09 AM

Read only

0 Likes
1,893

Hi Suneel,

Can you please help me to convert this below Macro into ABAP code?

ActiveSheet.CheckBoxes.Add(180, 123.5, 33.5, 17.5).Select

Range("B10").Select

Your help will be appreciated!!

Thank you.