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

Changing font color using ole

Former Member
0 Likes
1,374

Hello,

I have created the report which downloads data in two excel sheets using OLE.

I want to change the font color to red when value is negative.

Can any one tell me how to change the color and font size of value using OLE.

Regards,

Neelambari

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
953
*&----------------------------------------------------*
*&      Form  create_excel                            *
*&----------------------------------------------------*
FORM create_excel.

  w_line = 1.

  CREATE OBJECT e_appl 'EXCEL.APPLICATION'.
  SET PROPERTY OF e_appl 'VISIBLE' = 1.

  CALL METHOD OF e_appl 'WORKBOOKS' = e_work.
  CALL METHOD OF e_work 'Add' = e_work.

  GET PROPERTY OF e_appl 'ActiveSheet' = e_activesheet.
  SET PROPERTY OF e_activesheet 'Name' = 'Flights'.

  LOOP AT t_spfli ASSIGNING <fs_spfli>.
    w_tabix = sy-tabix.
    w_line = w_line + 1.

    LOOP AT t_titles ASSIGNING <fs_titles>.
      w_titles = sy-tabix.
      CALL METHOD OF e_appl 'Cells' = e_cell
        EXPORTING
        #1 = 1
        #2 = w_titles.
      SET PROPERTY OF e_cell 'Value' =  <fs_titles>-title.
      GET PROPERTY OF e_cell 'Interior' = e_color.
      SET PROPERTY OF e_color 'ColorIndex' = 35.

      GET PROPERTY OF e_cell 'Font' = e_bold.
      SET PROPERTY OF e_bold 'Bold' = 1.

      CALL METHOD OF e_appl 'Cells' = e_cell
        EXPORTING
        #1 = w_line
        #2 = w_titles.

      CONCATENATE '<fs_spfli>-' <fs_titles>-field
      INTO w_field.
      ASSIGN (w_field) TO <fs>.

      SET PROPERTY OF e_cell 'Value' = <fs>. """<<check here and use a diff color
      GET PROPERTY OF e_cell 'Interior' = e_color.
      SET PROPERTY OF e_cell 'ColumnWidth' = 20.
      SET PROPERTY OF e_color 'ColorIndex' = 0.
      GET PROPERTY OF e_cell 'Font' = e_bold.
      SET PROPERTY OF e_bold 'Bold' = 0.
    ENDLOOP.
  ENDLOOP.

  CALL METHOD OF e_work 'SAVEAS'
    EXPORTING
    #1 = p_file.

  CALL METHOD OF e_work 'close'.
  CALL METHOD OF e_appl 'QUIT'.
  FREE OBJECT e_appl.

ENDFORM.                    " create_excel

Hello,

I have created the report which downloads data in two excel sheets using OLE.

I want to change the font color to red when value is negative.

Can any one tell me how to change the color and font size of value using OLE.

Regards,

Neelambari

4 REPLIES 4
Read only

Former Member
0 Likes
953

Hi Neelambari,

Please chk the link for changing colors and font using OLE.

Hope it will be useful .

Regards,

Lakshman.

Read only

former_member156446
Active Contributor
0 Likes
954
*&----------------------------------------------------*
*&      Form  create_excel                            *
*&----------------------------------------------------*
FORM create_excel.

  w_line = 1.

  CREATE OBJECT e_appl 'EXCEL.APPLICATION'.
  SET PROPERTY OF e_appl 'VISIBLE' = 1.

  CALL METHOD OF e_appl 'WORKBOOKS' = e_work.
  CALL METHOD OF e_work 'Add' = e_work.

  GET PROPERTY OF e_appl 'ActiveSheet' = e_activesheet.
  SET PROPERTY OF e_activesheet 'Name' = 'Flights'.

  LOOP AT t_spfli ASSIGNING <fs_spfli>.
    w_tabix = sy-tabix.
    w_line = w_line + 1.

    LOOP AT t_titles ASSIGNING <fs_titles>.
      w_titles = sy-tabix.
      CALL METHOD OF e_appl 'Cells' = e_cell
        EXPORTING
        #1 = 1
        #2 = w_titles.
      SET PROPERTY OF e_cell 'Value' =  <fs_titles>-title.
      GET PROPERTY OF e_cell 'Interior' = e_color.
      SET PROPERTY OF e_color 'ColorIndex' = 35.

      GET PROPERTY OF e_cell 'Font' = e_bold.
      SET PROPERTY OF e_bold 'Bold' = 1.

      CALL METHOD OF e_appl 'Cells' = e_cell
        EXPORTING
        #1 = w_line
        #2 = w_titles.

      CONCATENATE '<fs_spfli>-' <fs_titles>-field
      INTO w_field.
      ASSIGN (w_field) TO <fs>.

      SET PROPERTY OF e_cell 'Value' = <fs>. """<<check here and use a diff color
      GET PROPERTY OF e_cell 'Interior' = e_color.
      SET PROPERTY OF e_cell 'ColumnWidth' = 20.
      SET PROPERTY OF e_color 'ColorIndex' = 0.
      GET PROPERTY OF e_cell 'Font' = e_bold.
      SET PROPERTY OF e_bold 'Bold' = 0.
    ENDLOOP.
  ENDLOOP.

  CALL METHOD OF e_work 'SAVEAS'
    EXPORTING
    #1 = p_file.

  CALL METHOD OF e_work 'close'.
  CALL METHOD OF e_appl 'QUIT'.
  FREE OBJECT e_appl.

ENDFORM.                    " create_excel
Read only

0 Likes
953

Hello,

I have already tried

GET PROPERTY OF e_cell 'Interior' = e_color.

SET PROPERTY OF e_color 'ColorIndex' = 3.

This is changing the cell color I want to change the color of the field the value I am passing.

Thanks

Regards,

Neelambari

Read only

0 Likes
953

Thanks