ITPub博客

首页 > 数字化转型 > ERP > SAP逐行寫出Excel文件

SAP逐行寫出Excel文件

原创 ERP 作者:tolyhuang 时间:2007-05-16 15:18:05 0 删除 编辑

report ztest_export_excel.
include ole2incl.
data: application type ole2_object,
workbook type ole2_object,
sheet type ole2_object,
cells type ole2_object.

constants: row_max type i value 256.
data index type i.
data: begin of itab occurs 0,
first_name(10),
last_name(10),
address(100),
end of itab.

start-of-selection.

...

[@more@]

"Add data to itab

itab-first_name = '123445'.
itab-last_name = 'tesst'.
itab-address = '中國'.
append itab.
clear itab.


itab-first_name = 'ABCDE'.
itab-last_name = 'tessasdfasdft'.
itab-address = '中國中山'.
append itab.
clear itab1.

itab-first_name = '123456'.
itab-last_name = 'tessasdfasdft'.
itab-address = '中國中山'.
append itab.
clear itab.


create object application 'excel.application'.
set property of application 'visible' = 1.
call method of application 'Workbooks' = workbook.
call method of workbook 'Add'.


call method of application 'Worksheets' = sheet
exporting #1 = 1.

call method of sheet 'Activate'.
set property of sheet 'Name' = 'Sheet1'.

"寫標題
index = 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = 'Field1'.

index = index + 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = 'Field2'.

index = index + 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = 'Field3'.

"寫數據
loop at itab.
index = row_max * sy-tabix + 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = itab-first_name.

index = index + 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = itab-last_name.

index = index + 1. " 1 - column name
call method of sheet 'Cells' = cells exporting #1 = index.
set property of cells 'Value' = itab-address.
endloop.


* 保存文件
call method of sheet 'SaveAs'

exporting #1 = 'c:tempexceldoc1.xls' "filename

#2 = 1. "fileFormat

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9437124/viewspace-915245/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-22

  • 博文量
    268
  • 访问量
    1468755