I've tried your coding in my system. The main problem is that you've not specified the i_attachment_size parameter when attaching the binary to the mail. Here a complete test report. Hope that solves your issue and we can close it.
REPORT zdemo_excel_send_mail.
CONSTANTS:
gc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
gc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
DATA:
mailto TYPE ad_smtpadr.
CONCATENATE sy-uname '@GMAIL.COM' INTO mailto.
DATA send_request TYPE REF TO cl_bcs.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA bcs_exception TYPE REF TO cx_bcs.
DATA main_text TYPE bcsy_text.
DATA binary_content TYPE solix_tab.
DATA binary_content1 TYPE solix.
DATA size TYPE so_obj_len.
DATA sent_to_all TYPE os_boolean.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lv_filelen TYPE so_obj_len,
lt_file_tab TYPE solix_tab.
" Creates active sheet
CREATE OBJECT lo_excel.
" Get active sheet
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->title = 'Sheet1'.
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the first sheet' ).
lo_worksheet = lo_excel->add_new_worksheet( ).
lo_worksheet->title = 'Sheet2'.
lo_worksheet->set_cell( ip_column = 'B' ip_row = 2 ip_value = 'This is the second sheet' ).
lv_file = lo_excel->save_as( zcl_excel=>c_xlsx ).
" Convert to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_file
IMPORTING
output_length = lv_bytecount
TABLES
binary_tab = lt_file_tab.
TRY.
-
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-
-------- create and set document with attachment ---------------
-
create document object from internal table with text
APPEND 'Multiple worksheets!'
TO main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Mul_sheets.xlsx' ). "#EC NOTEXT -
add the spread sheet as attachment to document object
lv_filelen = lv_bytecount.
document->add_attachment(
i_attachment_type = 'EXT' "#EC NOTEXT
i_attachment_subject = 'MulSpreadSheet.xlsx' "#EC NOTEXT
i_attachment_size = lv_filelen
i_att_content_hex = lt_file_tab ). -
add document object to send request
send_request->set_document( document ).
-
--------- add recipient (e-mail address) -----------------------
-
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
-
add recipient object to send request
send_request->add_recipient( recipient ).
-
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF sent_to_all IS INITIAL.
MESSAGE i500(sbcoms) WITH mailto.
ELSE.
MESSAGE s022(so).
ENDIF. -
------------ exception handling ----------------------------------
-
replace this rudimentary exception handling with your own one !!!
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.