Skip to Content
author's profile photo Former Member
Former Member

Sending Email with excel attachment having coloured headers.


I have a requirement wherein I have to send an email with an excel attachment containing data from an internal table.The attachment should contain the headers with the corresponding values.I have created a program for the above functionality but the problem is that the header must appear in red and some other colours.

I searched the forum but did not find anything which was helpful to me.

Could you please help me to attain the functionality mentioned above?It's urgent.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 02, 2008 at 12:41 PM

    Hi ,

    Use below code as reference:

    PARAMETERS: p_mail TYPE ad_smtpadr OBLIGATORY.

    DATA: i_mara TYPE STANDARD TABLE OF mara. " MARA Entries

    DATA: l_text TYPE char255. " Text

    DATA: l_lines TYPE i,

    l_size TYPE sood-objlen.

    " Size of Attachment

    • Mail related*

    DATA: i_content TYPE soli_tab, " Mail content

    i_attach TYPE soli_tab. " Attachment

    DATA: l_send_request TYPE REF TO cl_bcs,

    " E-Mail Send Request

    l_document TYPE REF TO cl_document_bcs,

    " E-Mail Attachment

    l_recipient TYPE REF TO if_recipient_bcs,

    " Distribution List

    l_sender TYPE REF TO if_sender_bcs,

    " Address of Sender

    l_uname TYPE salrtdrcpt,

    " Sender Name(SY-UNAME)

    l_bcs_exception TYPE REF TO cx_document_bcs,

    " BCS Exception

    l_addr_exception TYPE REF TO cx_address_bcs,

    " Address Exception

    l_send_exception TYPE REF TO cx_send_req_bcs.

    " E-Mail sending Exception





    CONSTANTS: c_tab(1) TYPE c VALUE


    " Tab Character

    c_cr(1) TYPE c VALUE cl_abap_char_utilities=>cr_lf,

    " Line Feed for End-Of_line

    c_ext TYPE soodk-objtp VALUE 'XLS'. " XLS Extension


    *SELECT * FROM mara INTO TABLE i_mara UP TO 20 ROWS.*

    • Preparing body of the Mail*

    MOVE 'Mail Body' TO l_text.

    APPEND l_text TO i_content.

    • Preparing contents of attachment with Change Log*

    PERFORM prepare_attachment.

    • Creates persistent send request*


    l_send_request = cl_bcs=>create_persistent( ).

    • Creating Document*

    l_document = cl_document_bcs=>create_document(

    i_type = 'RAW'

    i_text = i_content[]

    i_subject = 'Material Details' ).

    DESCRIBE TABLE i_mara LINES l_lines.

    • Size to multiplied by 2 for UNICODE enabled systems*

    *l_size = l_lines * 2 * 255.*

    • Adding Attachment*

    CALL METHOD l_document->add_attachment


    i_attachment_type = c_ext

    i_attachment_size = l_size

    i_attachment_subject = 'Material Details'

    i_att_content_text = i_attach[].

    • Add document to send request*

    CALL METHOD l_send_request->set_document( l_document ).

    • Get Sender Object*

    l_uname = sy-uname.

    l_sender = cl_sapuser_bcs=>create( l_uname ).

    CALL METHOD l_send_request->set_sender


    i_sender = l_sender.

    • E-Mail*


    l_recipient = cl_cam_address_bcs=>create_internet_address( p_mail )


    CALL METHOD l_send_request->add_recipient


    i_recipient = l_recipient

    i_express = 'U'

    i_copy = ' '

    i_blind_copy = ' '

    i_no_forward = ' '.

    *Trigger E-Mail immediately

    l_send_request->set_send_immediately( 'X' ).

    CALL METHOD l_send_request->send( ).


    CATCH cx_document_bcs INTO l_bcs_exception.

    CATCH cx_send_req_bcs INTO l_send_exception.

    CATCH cx_address_bcs INTO l_addr_exception.







    FORM prepare_attachment .

    FIELD-SYMBOLS: <lfs_table>, " Internal table structure

    <lfs_con>. " Field Content

    DATA: l_text TYPE char1024. " Text content for mail attachment

    DATA: l_con(50) TYPE c. " Field Content in character format

    • Columns to be tab delimeted*

    LOOP AT i_mara ASSIGNING <lfs_table>.


    ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>

    TO <lfs_con>.

    IF sy-subrc NE 0.

    CONCATENATE c_cr l_text INTO l_text.

    APPEND l_text TO i_attach.



    CLEAR: l_con.

    MOVE <lfs_con> TO l_con.

    CONDENSE l_con.

    IF sy-index = 1.

    CLEAR: l_text.

    MOVE l_con TO l_text.


    CONCATENATE l_text l_con INTO l_text

    SEPARATED BY c_tab.






    For more info go through the link:

    send excel attachment as email



    Edited by: Rama Chary on Jul 2, 2008 6:12 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 02, 2008 at 12:49 PM


    The above code just sends a mail with an excel attachement which I have already done...I need to display the headers in different colours.Could you please help me to understand how we can do this?



    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member


      U can achieve this using OLE2 objects. For this u need to download the file to the local system and do the excel formatting and upload the file contents for email attachmnet. hope this helps

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2009 at 10:11 AM


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.