下載內表資料到excel

qiujun發表於2010-07-21

FORM excel_data .

DATA:
l_filename TYPE string,
l_path TYPE string,
l_fullpath TYPE string,
l_title TYPE string.

l_title = '開票資訊下載'.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = l_title
default_extension = 'xls'
default_file_name = l_title
file_filter = '(電子表格EXCEL)'
CHANGING
filename = l_filename
path = l_path
fullpath = l_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
STOP.
ENDIF.

DATA x_filename LIKE rlgrap-filename.
WRITE l_fullpath TO x_filename.

DATA: BEGIN OF itab_field OCCURS 0,
fname(40) TYPE c ,
END OF itab_field.

DATA: BEGIN OF lt_tab OCCURS 0,
kpsqh(12),
zcxdd(5),
tzkpfs(10),
datum(8),
uname(12),
kzwij(13),
zkpyq(100),
kunag(10),
name1(10),
extension1(40),
extension2(40),
remark(50),
zshr(12),
zshrq(8),
zswfph(30),
zkpbz(40),
zkpr(12),
zkpsj(8),
zkdgs(10),
zkddh(20),
zjjrq(8),
END OF lt_tab.

itab_field-fname = '開票申請號'.
APPEND itab_field.
itab_field-fname = '促銷分開'.
APPEND itab_field.
itab_field-fname = '開票方式'.
APPEND itab_field.
itab_field-fname = '申請日期'.
APPEND itab_field.
itab_field-fname = '申請人'.
APPEND itab_field.
itab_field-fname = '金額'.
APPEND itab_field.
itab_field-fname = '開票特殊要求'.
APPEND itab_field.
itab_field-fname = '客戶'.
APPEND itab_field.
itab_field-fname = '客戶描述'.
APPEND itab_field.
itab_field-fname = '稅務發票收件人'.
APPEND itab_field.
itab_field-fname = '稅務發票收件電話'.
APPEND itab_field.
itab_field-fname = '稅務發票收件地址'.
APPEND itab_field.
itab_field-fname = '稽核人'.
APPEND itab_field.
itab_field-fname = '稽核日期'.
APPEND itab_field.
itab_field-fname = '稅務發票號'.
APPEND itab_field.
itab_field-fname = '開票備註'.
APPEND itab_field.
itab_field-fname = '開票人'.
APPEND itab_field.
itab_field-fname = '開票時間 '.
APPEND itab_field.
itab_field-fname = '快遞公司'.
APPEND itab_field.
itab_field-fname = '快遞單號'.
APPEND itab_field.
itab_field-fname = '寄件日期'.
APPEND itab_field.

LOOP AT it_tab.
MOVE-CORRESPONDING it_tab TO lt_tab.
APPEND lt_tab.
CLEAR lt_tab.
ENDLOOP.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = x_filename
data_sheet_name = '開票資訊'
create_pivot = 0
TABLES
data_tab = lt_tab
fieldnames = itab_field
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
OTHERS = 9.

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90072/viewspace-1035452/,如需轉載,請註明出處,否則將追究法律責任。

相關文章