Code: Alles auswählen.
*---------------------------------------------------------------------*
* Form send_excel
*---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IT_EXCEL text
*----------------------------------------------------------------------*
FORM send_excel TABLES it_excel.
TYPE-POOLS: abap.
DATA: mailto TYPE ad_smtpadr VALUE 'XXX'.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_worksheet TYPE REF TO zcl_excel_worksheet.
DATA: ls_table_settings TYPE zexcel_s_table_settings.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
DATA: lv_title TYPE zexcel_sheet_title,
lt_carr TYPE TABLE OF scarr,
row TYPE zexcel_cell_row VALUE 2,
lo_range TYPE REF TO zcl_excel_range.
DATA: lo_data_validation TYPE REF TO zcl_excel_data_validation.
DATA c_col(21) VALUE 'BCDEFGHIJKLMNOPQRSTU'.
DATA l_col TYPE zexcel_cell_column_alpha.
DATA i TYPE i.
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 main_text TYPE bcsy_text.
DATA binary_content TYPE solix_tab.
DATA size TYPE so_obj_len.
DATA sent_to_all TYPE os_boolean.
" create active sheet
CREATE OBJECT lo_excel.
" get active sheet
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->set_title( ip_title = 'Logbuch').
ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium3.
ls_table_settings-show_row_stripes = abap_true.
ls_table_settings-nofilters = abap_true.
lo_worksheet->bind_table( ip_table = it_excel[]
is_table_settings = ls_table_settings ).
" write to Excel 2007
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).
" 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 with text
APPEND 'Hello world!' TO main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test' ). "#EC NOTEXT
* add the spread sheet as attachment to document object
size = lv_bytecount.
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'SpreadSheet' "#EC NOTEXT
i_attachment_size = size
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 ).
TRY.
send_request->set_send_immediately( i_send_immediately = 'X' ).
CATCH cx_send_req_bcs. " BCS: Ausnahmen von Sendeaufträgen
ENDTRY.
* 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 ----------------------------------
CATCH cx_bcs INTO @DATA(bcs_exception).
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.
ENDFORM. "send_excel
Hallo, die Fehlermeldung bekomme ich, wenn ich in Outlook die Datei öffne.
Code: Alles auswählen.
* add the spread sheet as attachment to document object
size = lv_bytecount.
document->add_attachment(
i_attachment_type = 'xls' "'xlsx' don work here "#EC NOTEXT
i_attachment_subject = 'SpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = lt_file_tab ).
Code: Alles auswählen.
DATA sood_bytecount TYPE sood-objlen.
DATA lt_attachement TYPE solix_tab.
DATA lt_att_head TYPE soli_tab.
DATA lv_xdata TYPE xstring.
DATA lv_filename TYPE string. "soll xlxs am Ende enthalten
sood_bytecount = CONV #( xstrlen( lv_xdata ) ).
lt_att_head = VALUE #( ( '&SO_FILENAME=' && lv_filename ) )
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'XLS'
i_attachment_subject = lv_attachement_subject
i_attachment_size = sood_bytecount
i_att_content_hex = lt_attachement
i_attachment_header = lt_att_head ).
Folgende Benutzer bedankten sich beim Autor sap_enthusiast für den Beitrag:
der_neuling
Hallo, das funktioniert leider noch nicht. Könntest du mal den ganzen Code Schnipsel zeigen? Z.B. ist anhand des Ausschnittes auch der Wert für lv_attachement_subject oder lv_filename nicht ersichtlichsap_enthusiast hat geschrieben: ↑17.03.2022 10:15so funktioniert bei mir
Code: Alles auswählen.
DATA sood_bytecount TYPE sood-objlen. DATA lt_attachement TYPE solix_tab. DATA lt_att_head TYPE soli_tab. DATA lv_xdata TYPE xstring. DATA lv_filename TYPE string. "soll xlxs am Ende enthalten sood_bytecount = CONV #( xstrlen( lv_xdata ) ). lt_att_head = VALUE #( ( '&SO_FILENAME=' && lv_filename ) ) lo_document->add_attachment( EXPORTING i_attachment_type = 'XLS' i_attachment_subject = lv_attachement_subject i_attachment_size = sood_bytecount i_att_content_hex = lt_attachement i_attachment_header = lt_att_head ).
Folgende Benutzer bedankten sich beim Autor Thomas R. für den Beitrag (Insgesamt 2):
sap_enthusiast • der_neuling
Code: Alles auswählen.
*** Create output
lcl_output=>output( lo_excel ).
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag (Insgesamt 2):
sap_enthusiast • Icke0801
Code: Alles auswählen.
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Excel\Security" /v ExtensionHardening /t REG_DWORD /d 0 /f