Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

abap2xlsx - How to edit xlsx template from OAOR?

alessandroieva
Active Participant
0 Kudos
1,599

Hi experts, I would like know if is possible to read a template xlsx from OAOR and edit it with abap2xlsx in background mode.

I have need to change single cells and insert new rows into my template being careful not to damage the images.

Best Regards,

AI

7 REPLIES 7

Sandra_Rossi
Active Contributor
0 Kudos
390

OAOR gives access to the documents in the Business Document Services (BDS). The API to get a document is the class CL_BDS_DOCUMENT_SET (can be called in background).

abap2xlsx can be called in background too.

0 Kudos
390

Thank you Sandra for your reply, I use abap2xlsx for read the file in background but I would like know how convert it for change value in a cell or insert new row with abap2xlsx. After change i need to save it in xlsx format in a folder on application server.

Do you have a example code?

Regards,

AI

0 Kudos
390

abap2xlsx is supplied with many examples. The classes to instantiate ZCL_EXCEL from an Excel XSTRING implement ZIF_EXCEL_READER~LOAD, and the classes to get the XSTRING from an instance of ZCL_EXCEL implement ZIF_EXCEL_WRITER~WRITE_FILE.

0 Kudos
390

Can you please provide any ABAP2XLSX demo example for this? I have the same requirement to modify the template from OAOR and it should run in background mode.

0 Kudos
390

Search the web, there are so many examples. If you have an issue, then post a question in the forum.

0 Kudos
390

Hi Sandra,

I didn't found any solution or demo about it. I drew the template directly with abap2xlsx.

AI

390
DATA file_table TYPE filetable.
DATA rc TYPE i.
DATA user_action TYPE i.
cl_gui_frontend_services=>file_open_dialog(
CHANGING
file_table = file_table
rc = rc
user_action = user_action
EXCEPTIONS
OTHERS = 1
).
CHECK sy-subrc = 0.
CHECK user_action = cl_gui_frontend_services=>action_ok.
DATA data_tab TYPE TABLE OF x255.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = CONV #( file_table[ 1 ]-filename )
filetype = 'BIN'
IMPORTING
filelength = DATA(filelength)
CHANGING
data_tab = data_tab
EXCEPTIONS
OTHERS = 1
).
CHECK sy-subrc = 0.
DATA(reader) = NEW zcl_excel_reader_2007( ).
DATA(excel) = reader->zif_excel_reader~load( i_excel2007 = CONV #(
substring( val = REDUCE string( INIT x TYPE xstring FOR <x> IN data_tab NEXT x = x && <x> )
len = filelength * 2 ) ) ).