Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Getting error pop up message while opening .xlsx attachment sent through mail.?

Hello,

I want to send .xlsx as attachment through mail,xlsx file attached to mail successfully but while opening xlsx file getting error pop up message as shown below:

Please provide me solution.


Code:

data lo_send_request type ref to cl_bcs.

data lo_document     type ref to cl_document_bcs.

data lt_doc_text     type bcsy_text.

data lt_att_text    type bcsy_text.

data lt_att_head    type soli_tab.

data lv_text_line    type soli.

data lv_filename    type string.

data: recipient          type ref to if_recipient_bcs.

data: send_request       type ref to cl_bcs.

data: sent_to_all        type os_boolean.

data: bcs_exception      type ref to cx_bcs.

try.

*   -------- create persistent send request ------------------------

     lo_send_request = cl_bcs=>create_persistent( ).

*  -------- create and set document with attachment ---------------

*  create document from internal table with text

     append 'Hello world!' to lt_doc_text.

     lo_document = cl_document_bcs=>create_document(

                                       i_type    = 'RAW'

                                       i_text    = lt_doc_text

                                       i_length  = '12'

                                       i_subject = 'Main Document'

                                     ).

*  add attachment to document

     append 'This is an attachment' to lt_att_text.

*  four character file extension '.text' is set

     lv_filename = 'AttachmentFilename.xlsx'.     concatenate '&SO_FILENAME='                lv_filename into lv_text_line.

     append lv_text_line to lt_att_head.

     lo_document->add_attachment( exporting

                                   i_attachment_type    = 'XLS'

                                   i_attachment_subject = 'Attachment'

                                   i_attachment_size    =  '21'

                                   i_att_content_text   = lt_att_text

                                   i_attachment_header  = lt_att_head

                                 ).

*  add document to send request

     lo_send_request->set_document( lo_document ).

*--------- add recipient (e-mail address) -----------------------

*     create recipient - please replace e-mail address !!!

       recipient = cl_cam_address_bcs=>create_internet_address(

                                         'mail@mail.com' ).

*     add recipient with its respective attributes to send request

       call method lo_send_request->add_recipient

         exporting

           i_recipient = recipient

           i_express   = 'X'.

*     ---------- send document ---------------------------------------

       call method lo_send_request->send(

         exporting

           i_with_error_screen = 'X'

         receiving

           result              = sent_to_all ).

       if sent_to_all = 'X'.

         write text-113.

       endif.

       commit work.

* -----------------------------------------------------------

* *                     exception handling

* -----------------------------------------------------------

* * replace this very rudimentary exception handling

* * with your own one !!!

* -----------------------------------------------------------

     catch cx_bcs into bcs_exception.

       write: text-111.

       write: text-112, bcs_exception->error_type.

       exit.

endtry.

Tags:
replied

Hello Gaurav,

Use CL_BCS,ZCL_EXCEL and ZCL_EXCEL_WORKSHEET class.

Its works fine.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question