除了单文本,有时客户会要求类似下图表格样式,套用该代码模板即可实现
image.png
DATA:
lv_bytecount TYPE i,
lv_xdata TYPE xstring,
lv_result TYPE os_boolean,
lv_errortext TYPE string,
lv_address_string TYPE ad_smtpadr,
lv_worksheet_title TYPE zexcel_sheet_title,
lv_subject TYPE so_obj_des,
lv_attachment_size TYPE so_obj_len,
ls_attachment_header TYPE soli,
" ls_text TYPE soli,
ls_text TYPE string,
ls_table_settings TYPE zexcel_s_table_settings,
lt_text TYPE bcsy_text, "soli_tab,
lt_attachment_header TYPE soli_tab,
lt_att_content_hex TYPE solix_tab.
DATA:
lo_send_request TYPE REF TO cl_bcs,
lo_bcs_exception TYPE REF TO cx_bcs,
lo_document TYPE REF TO cl_document_bcs,
lo_sender TYPE REF TO if_sender_bcs,
lo_recipient TYPE REF TO if_recipient_bcs,
lo_excel TYPE REF TO zcl_excel,
lo_excel_worksheet TYPE REF TO zcl_excel_worksheet,
lo_excel_writer TYPE REF TO zif_excel_writer.
ls_table_settings-top_left_column = 'A'.
ls_table_settings-top_left_row = 1.
ls_table_settings-show_row_stripes = abap_true.
WRITE text-003 TO lv_worksheet_title. "Cancel Billing Automatic Cearing List
CONCATENATE text-003 sy-datum INTO lv_subject(50) SEPARATED BY space.
ls_text = '<p><span style="font-size:14px;">Dear Sir/Madam,</span></p>'.
APPEND ls_text TO lt_text[].
* ls_text = '<p><span style="font-size:14px;"> Waitting approve list can see as below:</span></p>'.
*
* APPEND ls_text TO lt_text[].
ls_text = '<table border="1" cellpadding="8" cellspacing="0" style="font-size:75%;white-space:nowrap" >'."width="100px"
APPEND ls_text TO lt_text[].
CLEAR ls_text.
ls_text = '<tr bgcolor="#DCDCDC"><td bgcolor="#DCDCDC" >Company</td>'.
APPEND ls_text TO lt_text[].
ls_text = '<td bgcolor="#DCDCDC" >Customers</td>'.
APPEND ls_text TO lt_text[].
ls_text = '<td bgcolor="#DCDCDC">Reason</td></tr>'.
APPEND ls_text TO lt_text[].
CLEAR ls_text.
" CONCATENATE '--' '--' '--' '--' '--' '--' '--' INTO ls_text.
LOOP AT gt_knb1 INTO gs_knb1 WHERE type = 'E'.
ls_text = '<tr><td>' && gs_knb1-bukrs && '</td><td>' && gs_knb1-kunnr && '</td><td>' && gs_knb1-mess && '</td>' .
APPEND ls_text TO lt_text[].
CLEAR ls_text.
CLEAR gs_knb1.
ENDLOOP.
" ls_text = '</tbody></table>'.
ls_text = '</table>'.
APPEND ls_text TO lt_text[].
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document( i_type = 'HTM' i_text = lt_text i_subject = lv_subject ).
" lo_sender ?= cl_sapuser_bcs=>create( sy-uname ).
lv_address_string = p_addr ."收件人
lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = lv_address_string ) .
lo_send_request->add_recipient( i_recipient = lo_recipient ) .
lo_send_request->set_document( lo_document ).
lo_send_request->set_sender( lo_sender ).
lv_result = lo_send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF lv_result IS INITIAL.
MESSAGE i500(sbcoms) WITH sy-uname.
ELSE.
MESSAGE s022(so).
ENDIF.
CATCH cx_bcs INTO lo_bcs_exception.
lv_errortext = lo_bcs_exception->if_message~get_text( ).
MESSAGE lv_errortext TYPE 'I'.
ENDTRY.
网友评论