【ABAP系列】SAP ABAP DOI展示EXCEL或WORD

前言部分
大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。
正文部分
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的更多相关文章
- 【ABAP系列】ABAP CL_ABAP_CONV_IN_CE
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]ABAP CL_ABAP_CON ...
- 【ABAP系列】SAP DOI技术中I_OI_SPREADSHEET接口的使用
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP DOI技术中I_OI_S ...
- 【ABAP系列】SAP ABAP下载带密码的Excel文件
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP下载带密码的Ex ...
- 【ABAP系列】【第五篇】SAP ABAP7.50 之用户接口
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列][第五篇]SAP ABAP7.5 ...
- 【ABAP系列】SAP ABAP OOALV 动态设置单元格可否编辑
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP OOALV 动 ...
- 【ABAP系列】SAP ABAP同时显示多个ALV的方法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP同时显示多个AL ...
- 【ABAP系列】SAP ABAP常用函数总结第一篇
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP常用函数总结第一 ...
- 【ABAP系列】SAP ABAP BAPI_REQUISITION_CREATE创建采购申请
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP BAPI_RE ...
- 【ABAP系列】SAP ABAP 字符编码与解码、Unicode
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 字符编码与解码 ...
随机推荐
- [易学易懂系列|rustlang语言|零基础|快速入门|(4)|借用Borrowing]
[易学易懂系列|rustlang语言|零基础|快速入门|(4)] Borrowing 继续讲讲另一个重要的概念:借用(borrowing), 什么是借用? 我们先来看前一文章([易学易懂系列|rust ...
- MVC-MVP-MVVM框架模式分析
MVC(Model-View-Controller) MVC 架构模式图(经典版) 注:实际上,Model和View永远不能相互通信,只能通过Controller传递:上图只是MVC模式的经典图. M ...
- typedef int(init_fnc_t) (void)的理解
typedef int(init_fnc_t) (void); 这个就是一个取别名的过程. 我们通常情况下会如下使用 typedef :typedef int MyInt;MyInt a; 这个时候我 ...
- python 控制流(二)
常用控制流 条件语句 循环语句 一.条件语句 if 条件表达式: #条件表达式--->比较运算符--->布尔值 满足条件表达式执行的代码块 #当布尔值为 True时执行此句 elif 条件 ...
- webpack4基础配置
网页中常见的静态资源: js: .js .jsx .coffee .ts(TypeScript 类 C# 语言) css: .css .less .sass .scss Images: .jpg .p ...
- bash: ipconfig: command not found
问题描述: [root@localhost ~]# ipconfig-bash: ipconfig: command not found[root@localhost ~]# 解决方法一: cd /e ...
- 微信小程序-饮食日志_开发记录03
这段时间主要是收尾阶段. 美化界面,排版分部等. 并进行上传,审核. 环境部署一直出现问题,所以测试版食物查找查找不到. 主要问题是:https://的网页证书没有通过审核. 所以现在推行开发,调试版 ...
- SpringCloud学习系列-Eureka服务注册与发现(2)
构建 microservicecloud-eureka-7001 eureka服务注册中心Module 1.新建microservicecloud-eureka-7001 2.pom <proj ...
- 源码编译git-go
2018.8.29 安装指定版本的git 一,安装 编译前准备: 依赖库 yum install curl-devel expat-devel gettext-devel openssl-devel ...
- cvtColor
E:/OpenCV/opencv/sources/modules/imgproc/src/color.cpp CV_RGB2GRAY:RGB--->GRAY.