公众号:SAP Technical
本文作者:matinal
 

前言部分

大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

正文部分

DOI技术算是比较老的技术了

用来直接调用office展示结果

可以是EXCEL也可以是WORD


data: begin of s_fal.
include structure faglflext.
data: end of s_fal.
data: i_fal like table of s_fal.
data: ok_code like sy-ucomm.
type-pools: soi,sbdst,abap.
class c_oi_errors definition load. data control type ref to i_oi_container_control.
data retcode type soi_ret_string. data: container type ref to cl_gui_custom_container. data: document type ref to i_oi_document_proxy.
data: error type ref to i_oi_error.
data: errors type ref to i_oi_error occurs . data spreadsheet type ref to i_oi_spreadsheet.
data sheetname() type c.
select * from faglflext into corresponding fields of table i_fal where rbukrs = '' and ryear = '' and racct = ''. call screen .
*&---------------------------------------------------------------------*
*& Module status_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status ''. call method c_oi_container_control_creator=>get_container_control
importing
control = control
retcode = retcode. create object container
exporting
container_name = 'DOI_PARENT'."100屏幕上的控件名. call method control->init_control
exporting
r3_application_name = 'Demo Document Container'
inplace_enabled = 'X'
parent = container
importing
retcode = retcode. call method control->get_document_proxy
exporting
document_type = 'Excel.Sheet.8'
document_format = 'OLE'
importing
document_proxy = document
retcode = retcode. call method document->create_document
exporting
create_view_data = 'X'
open_inplace = 'X'
importing
retcode = retcode.
call method document->get_spreadsheet_interface
exporting
no_flush = ' '
importing
sheet_interface = spreadsheet
error = error.
call method spreadsheet->get_active_sheet
exporting
no_flush = ''
importing
sheetname = sheetname
error = error
retcode = retcode.
call method spreadsheet->add_sheet
exporting
name = '年度报表'
no_flush = ''
importing
error = error
retcode = retcode.
call method spreadsheet->delete_sheet
exporting
name = sheetname
no_flush = ''
importing
error = error
retcode = retcode.
call method spreadsheet->select_sheet
exporting
name = '年度报表'
no_flush = ''
importing
error = error
retcode = retcode. data: rows like sy-tabix.
data: field_count type i.
data: rangeitem type soi_range_item.
data: ranges type soi_range_list.
data: excel_input type soi_generic_table.
data: excel_input_wa type soi_generic_item.
field-symbols: <field> type any,
<wa> type any.
field_count = .
do.
assign component field_count of structure s_fal to <field>."assign成功subrc = 0.
if sy-subrc <> .
exit.
endif.
add to field_count.
enddo.
field_count = field_count - .
describe table i_fal lines rows.
call method spreadsheet->insert_range_dim
exporting
name = 'CELL'
no_flush = 'X'
top =
left =
rows = rows
columns = field_count
importing
error = error. clear rangeitem.
refresh ranges.
rangeitem-name = 'CELL'.
rangeitem-columns = field_count.
rangeitem-rows = rows.
append rangeitem to ranges.
call method spreadsheet->set_font
exporting
rangename = 'CELL'
family = 'Times New Roman'
size =
bold =
italic =
align =
importing
error = error
retcode = retcode.
call method spreadsheet->set_format
exporting
rangename = 'CELL'
typ =
currency = 'RMB'
importing
error = error
retcode = retcode. refresh excel_input. data: field_value type string.
loop at i_fal assigning <wa>.
rows = sy-tabix.
field_count = .
do.
assign component field_count of structure <wa> to <field>."assign成功subrc = 0.
if sy-subrc <> .
exit.
endif.
clear excel_input_wa.
excel_input_wa-column = field_count.
excel_input_wa-row = rows.
field_value = <field>.
excel_input_wa-value = field_value.
append excel_input_wa to excel_input.
add to field_count.
enddo.
endloop.
* set data
call method spreadsheet->set_ranges_data
exporting
ranges = ranges
contents = excel_input
no_flush = 'X'
importing
error = error.
*get desktop directory
data: desktop_directory type string.
call method cl_gui_frontend_services=>get_sapgui_workdir
changing
sapworkdir = desktop_directory
exceptions
get_sapworkdir_failed =
cntl_error =
error_no_gui =
not_supported_by_gui =
others = .
if sy-subrc <> .
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif. if desktop_directory is initial.
desktop_directory = 'C:'.
endif.
concatenate desktop_directory '\' '年度报表.xls' into desktop_directory. data: result type abap_bool.
call method cl_gui_frontend_services=>file_exist
exporting
file = desktop_directory
receiving
result = result
exceptions
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
others = 5.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
data: rc type i.
if result = 'X'.
call method cl_gui_frontend_services=>file_delete
exporting
filename = desktop_directory
changing
rc = rc
exceptions
file_delete_failed = 1
cntl_error = 2
error_no_gui = 3
file_not_found = 4
access_denied = 5
unknown_error = 6
not_supported_by_gui = 7
wrong_parameter = 8
others = 9.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endif.
data:file_name(250) type c.
file_name = desktop_directory.
call method document->save_as
exporting
file_name = file_name
prompt_user = ''
importing
error = error
retcode = retcode.
*放到FTP
*.............................
*.............................
*在这里写放到FTP上的语句.
endmodule. " status_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
case ok_code.
when 'EXIT' or 'BACK'.
leave to screen 0.
endcase.
endmodule. " user_command_0100 INPUT ​

【ABAP系列】SAP ABAP DOI展示EXCEL或WORD的更多相关文章

  1. 【ABAP系列】ABAP CL_ABAP_CONV_IN_CE

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]ABAP CL_ABAP_CON ...

  2. 【ABAP系列】SAP DOI技术中I_OI_SPREADSHEET接口的使用

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP DOI技术中I_OI_S ...

  3. 【ABAP系列】SAP ABAP下载带密码的Excel文件

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP下载带密码的Ex ...

  4. 【ABAP系列】【第五篇】SAP ABAP7.50 之用户接口

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列][第五篇]SAP ABAP7.5 ...

  5. 【ABAP系列】SAP ABAP OOALV 动态设置单元格可否编辑

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP OOALV 动 ...

  6. 【ABAP系列】SAP ABAP同时显示多个ALV的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP同时显示多个AL ...

  7. 【ABAP系列】SAP ABAP常用函数总结第一篇

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP常用函数总结第一 ...

  8. 【ABAP系列】SAP ABAP BAPI_REQUISITION_CREATE创建采购申请

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP BAPI_RE ...

  9. 【ABAP系列】SAP ABAP 字符编码与解码、Unicode

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 字符编码与解码 ...

随机推荐

  1. regsvr32 驱动

    1.将SYS驱动文件放到系统目录的SYSTEM32目录中.2.按WIN+R组合键,在运行框中输入:regsvr32 sys所在全路径,点击确定即可.

  2. 对OO原则的个人理解

    1.单一职责原则.(Single Responsibility Principle) 注解:社会化大生产分工要细.具体每个人最好只做一件事(不要一人兼多职),这样如果这个人请假或辞职,对生产不会产生影 ...

  3. docker概述和安装

    一:概述 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器或Windows 机器上,也可以实现虚拟化,容器是完全使用 ...

  4. idea控制台搜索框

    https://blog.csdn.net/honnyee/article/details/82772948

  5. java数据结构--array与ArrayList的区别

    ArrayList 内部是由一个array 实现的. 如果你知道array 和 ArrayList 的相似点和不同点,就可以选择什么时候用array 或者使用ArrayList , array 提供 ...

  6. ESP8266内置的定时器库--Ticker库

    Ticker的功能非常简单,就是规定时间后调用函数 总体上,根据功能可以把方法分为两大类: 定时器管理方法: 定时器启用方法: detach()     停止定时器 active()    定时器是否 ...

  7. 【NOIP2016提高A组模拟9.9】闭门造车

    题目 自从htn体验了一把飙车的快感,他就下定决心要闭门造车!但是他两手空空怎么造得出车来呢?无奈的他只好来到了汽车零部件商店. 一走进商店,玲琅满目的各式零件看得htn眼花缭乱.但是他很快便反应过来 ...

  8. 【NOIP2012模拟10.25】剪草

    题目 有N棵小草,编号0至N-1.奶牛Bessie不喜欢小草,所以Bessie要用剪刀剪草,目标是使得这N棵小草的高度总和不超过H.在第0时刻,第i棵小草的高度是h[i],接下来的每个整数时刻,会依次 ...

  9. Help library 安装arcobjects for .NET异常问题

    新建一个reg文件写入,也可以导出一个reg文件在上面重新写入. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\CLSID\{9DAA ...

  10. 更改pip源地址为阿里云

    1.在用户名目录创建pip目录,在pip目录下创建pip.ini. 2.pip.ini中输入: [global] index-url = http://mirrors.aliyun.com/pypi/ ...