Comments (3)
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.
Yes It works, Great
from abap2xlsx.
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)
- Making Date as blank instead of '00.00.0000' in CSV export HOT 9
- Sometimes values of referenced Filed are empty HOT 1
- CX_SY_CONVERSION_NO_NUMBER because of conversion exit EXCRT HOT 6
- ZCL_EXCEL_WORKSHEET -> CONVERT_TO_TABLE drops initial excel lines HOT 8
- CX_SY_CONVERSION_NO_NUMBER exception in ZCL_EXCEL_READER_2007 method LOAD_WORKSHEET for multiple row spans HOT 1
- Use of Column Formula (zdemo_excel47) generates corrupted Excel HOT 10
- ZCL_EXCEL_WORKSHEET -> CONVERT_TO_TABLE wrong results if empty lines HOT 2
- Incorrect cell value when generating Excel using write_file and digits with data type "s" HOT 4
- CONVT_NO_NUMBER in ZCL_EXCEL_READER_2007=>LOAD_WORKSHEET HOT 4
- convert_to_table may produce zcx_excel/invalid time with some time values
- Reorganize zcl_excel_common unit tests, one method per test and define several test classes instead of one
- -
- Encrypt with Password HOT 1
- Position drawing in middle of a cell HOT 2
- Reading Smart Tables HOT 8
- Header/footer images and comments together make corrupted Excel file HOT 1
- Corrupted XLSX with BIND_TABLE and numeric column in TOP_LEFT_COLUMN
- Using abap2xlsx to read Excel with Excel open HOT 5
- Writer_xlsm and Writer_2007 not fully aligned again HOT 5
- Size of comments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abap2xlsx.