03-21-2022 11:44 AM
Greetings,
I'm trying to upload an xlsx file using the following code,
my excel has 3 rows 3 columns ,the last column has a long text and is empty in gt_data.,it does not get populated.only the last column.
Can someone help me?
DATA : lo_excel_ref TYPE REF TO cl_fdt_xl_spreadsheet .
TRY .
lo_excel_ref = NEW cl_fdt_xl_spreadsheet(<br>
document_name = l_filename<br>
xdocument = lv_headerxstring ) .<br>
CATCH cx_fdt_excel_core.<br>
"Implement suitable error handling here<br>
ENDTRY .<br><br>
"Get List of Worksheets<br>
lo_excel_ref->if_fdt_doc_spreadsheet~get_worksheet_names(<br>
IMPORTING<br>
worksheet_names = DATA(lt_worksheets) )
.<br><br><br> IF NOT lt_worksheets IS INITIAL.<br>
READ TABLE lt_worksheets INTO DATA(lv_woksheetname) INDEX 1.<br><br>
DATA(lo_data_ref) =<br>
lo_excel_ref->if_fdt_doc_spreadsheet~get_itab_from_worksheet(<br>
lv_woksheetname ).<br>
"now you have excel work sheet data in dyanmic internal table<br>
ASSIGN lo_data_ref->* TO <gt_data>.<br>
ENDIF.
03-21-2022 11:58 AM
I've tried to use alsm_excel_to_internal_table it also gives me upload_ole error
03-21-2022 12:25 PM
Can you try to display the data actually read by the class
ASSIGN lo_data_ref->* TO FIELD-SYMBOL(<fs_worksheet_data>).
cl_demo_output=>write_data( <fs_worksheet_data> ).
DATA(lv_html) = cl_demo_output=>get( ).
cl_abap_browser=>show_html( EXPORTING
title = 'Excel-Worksheet' ##NO_TEXT
html_string = lv_html
container = cl_gui_container=>default_screen ).
03-21-2022 1:43 PM
03-21-2022 1:51 PM
raymond.giuseppi when I try to upload usong ALSM_EXCEL_TO_INTERNAL_TABLE
it gives me the upload_ole error.I am calling it from my fiori app. Can you help me with a solution?
03-21-2022 1:58 PM
that function will NOT work in background, since it needs a connection to the GUI (hence the OLE error)
You could try using abap2xlsx for reading.
03-21-2022 2:04 PM
andreaborgia what about the oo aproach as above? the only problem it doest read the long text in my third column.as you can see in the picture.
03-21-2022 2:19 PM
I have no idea what your code does, since it is now one long line and I can't read it 🙂
That said, abap2xlsx is as OO as it gets... the demo for reading is ZDEMO_EXCEL15
03-21-2022 2:32 PM
03-21-2022 2:56 PM
I've seem that when I remove the formating of that column,simple text now,its okay. somehow when its formated it doesnt work
03-21-2022 3:02 PM
Ok, at the moment in abap2xlsx there is no method to extract a table from the worksheet, you'll have to do it row by row, column by column as in the example I gave you but it's being planned for a future release.
03-21-2022 3:22 PM
It is therefore a limitation of the class. (Read also 2468709 - Usage of standard class CL_FDT_XL_SPREADSHEET, it's not a generic tool but was intended for decision table in BRFplus workbench)
03-21-2022 12:51 PM
03-21-2022 1:07 PM
03-21-2022 2:14 PM
03-21-2022 2:16 PM
By the way, not your fault (thanks to SAP Community), the formatting of your code is gone with your edit.
03-21-2022 2:18 PM
If it's a bug from cl_fdt_xl_spreadsheet, then you should look at SAP notes, or contact SAP support.
Otherwise, you can use abap2xlsx (at least it works).
03-21-2022 3:16 PM
sandra.rossi thank you ,I too just found it out.do you know another class to use apart abap2xls?