*&---------------------------------------------------------------------*
*& Report Z_BARRY_UPLOAD_EXCEL
*&
*&---------------------------------------------------------------------*
*& 上传Excel文件到SAP内表
*& 除此方法,还可以使用FM: ALSM_EXCEL_TO_INTERNAL_TABLE
*&---------------------------------------------------------------------*
REPORT z_barry_upload_excel.
TYPE-POOLS: truxs.
TYPES: BEGIN OF t_datatab,
col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
END OF t_datatab.
DATA: it_datatab TYPE STANDARD TABLE OF t_datatab,
wa_datatab TYPE t_datatab.
DATA: it_raw TYPE truxs_t_text_data.
PARAMETERS: p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT it_datatab INTO wa_datatab.
WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3.
ENDLOOP.
如果有Excel内Cell内容过长情况,请参考:
以Excel格式下载内表到本机
**************
Report z_export_excel.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'C:\test4.xls'.
DATA: t100_lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.
SELECT * FROM t001 INTO TABLE t100_lines.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = p_file
TABLES
i_tab_sap_data = t100_lines.
**注:如果是使用Office2007,需要GUI为720版本,否则生成的Excel文件可能会打不开
阅读(8254) | 评论(13) | 转发(0) |