1.因为是做建单的例子,所以没有做结果显示,在加了两个属性
DATESOURCE Type XSTRING
FILENAME Type STRING
2.在VIEW中新建element
FileUpload
给个按钮事件:UPLOAD
method ONACTIONUPLOAD . DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT. DATA LV_DATESOURCE TYPE WD_THIS->ELEMENT_CONTEXT-DATESOURCE. DATA FILE_DATA TYPE XSTRING. DATA FILE_NAME TYPE STRING. DATA: LV_NAME TYPE STRING, LV_STRING TYPE STRING, LV_MSG TYPE STRING, LV_FLAG TYPE BOOLEAN, LV_MESSAGE TYPE STRING. DATA: LREF_EXCEL TYPE REF TO CL_FDT_XL_SPREADSHEET, LREF_EXCEL_CORE TYPE REF TO CX_FDT_EXCEL_CORE, LREF_DATA TYPE REF TO DATA, LREF_DREF TYPE REF TO DATA. * Field symbols declarations FIELD-SYMBOLS: <F1> TYPE TABLE. DATA: LT_WORKSHEETS TYPE STANDARD TABLE OF STRING. * Structures declarations * get element via lead selection LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ). * get single attribute LO_EL_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = `DATESOURCE` IMPORTING VALUE = FILE_DATA ). * get single attribute LO_EL_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = `FILENAME` IMPORTING VALUE = FILE_NAME ). TRY. * Create object of class to read .xlsx file contents CREATE OBJECT LREF_EXCEL EXPORTING DOCUMENT_NAME = FILE_NAME XDOCUMENT = FILE_DATA. CATCH CX_FDT_EXCEL_CORE INTO LREF_EXCEL_CORE. * CLEAR LV_MSG. * Call method to get error message text * CALL METHOD LREF_EXCEL_CORE->IF_MESSAGE~GET_TEXT * RECEIVING * RESULT = LV_MSG. *<< Display error message returned in lv_msg >> RETURN. ENDTRY. * Call method to get list of worksheets in the .xlsx file LREF_EXCEL->IF_FDT_DOC_SPREADSHEET~GET_WORKSHEET_NAMES( IMPORTING WORKSHEET_NAMES = LT_WORKSHEETS ). * Condition to check whether .xlsx file has any active worksheets IF LT_WORKSHEETS IS NOT INITIAL. * Read active worksheet READ TABLE LT_WORKSHEETS INDEX 1 INTO LV_NAME. ELSE. *<< Display error message >> RETURN. ENDIF. * Get reference of .xlsx file contents in the active worksheet LREF_DATA = LREF_EXCEL->IF_FDT_DOC_SPREADSHEET~GET_ITAB_FROM_WORKSHEET( LV_NAME ). * Fetch all records in the active worksheet ASSIGN LREF_DATA->* TO <F1>. * Prepare exporting table with .xlsx file contents IF <F1> IS NOT ASSIGNED. *<< Display error message >> RETURN. ENDIF. endmethod.