Giter VIP home page Giter VIP logo

Comments (3)

ivanfemia avatar ivanfemia commented on May 23, 2024

Hi,

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.

from abap2xlsx.

ivanfemia avatar ivanfemia commented on May 23, 2024

Yes It works, Great

from abap2xlsx.

ivanfemia avatar ivanfemia commented on May 23, 2024

Hi Gregor,
With this change, the email file is saved with extension .EXT and not with .XLSX
The user will have to download this file, unzip it and save it as .XLSX format to view the contents.
Is it not possible to directly send it in .XLSX format so that the user will not have to change the document type or am I missing anything here?
Vinny

from abap2xlsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.