公众号: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. linux下利用tcpdump抓包工具排查nginx获取客户端真实IP实例

    一.nginx后端负载服务器的API在获取客户端IP时始终只能获取nginx的代理服务器IP,排查nginx配置如下 upstream sms-resp { server ; server ; } s ...

  2. hdu 1003 最大连续子串

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  3. imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable

    错误: imagecreatefromstring(): Empty string or invalid image 或者 imagesx() expects parameter 1 to be re ...

  4. Java并发编程实战 第10章 避免活跃性危险

    死锁 经典的死锁:哲学家进餐问题.5个哲学家 5个筷子 如果没有哲学家都占了一个筷子 互相等待筷子 陷入死锁 数据库设计系统中一般有死锁检测,通过在表示等待关系的有向图中搜索循环来实现. JVM没有死 ...

  5. 如何连接虚拟的OneNote打印机

    include <Windows.h> #include <iostream> int main() { HANDLE handle = CreateFile(L"O ...

  6. http.sys_DDos攻击(ms15-043)

    远程执行代码漏洞存在于HTTP协议堆栈(HTTP.sys)中,当HTTP.sys未正确分析经特殊设计的HTTP请求时会导致该漏洞.该漏洞利用成功可使目标机器蓝屏. 微软官方说明: https://do ...

  7. JAVA笔记27-正则表达式(RegularExpressions)

    正则表达式是字符串的处理利器. 用途:字符串匹配(字符匹配).字符串查找.字符串替换 例如:IP地址是否正确.从网页中揪出email地址(如垃圾邮件).从网页中揪出链接等 涉及到的类:java.lan ...

  8. 部署zabbix 4.0 + grafana

    不完整,仅供参考 Zabbix+grafana监控部署 基本环境 系统: CentOS Linux release 7.3.1611 Zabbix—server:  Zabbix_agent:   N ...

  9. oracle 7.4安装nvidia驱动

    2019-8-28 参考网页: 如何在k8s集群中安装nvidia.cuda并使用GPU进行训练 https://blog.csdn.net/u013042928/article/details/78 ...

  10. 观察者模式------《Head First 设计模式》

    第二章---观察者模式 xzmxddx 学习方式:书籍<Head First 设计模式>,这本书通俗易懂,所有知识点全部取自本书. 面向对象设计原则 封装变化 多用组合,少用继承 针对接口 ...