公众号: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. openCV for python的使用

    一.openCV简介 OpenCV是一个开源的跨平台计算机视觉库.它轻量级而且高效——由一系列 C 函数和少量C++类构成,同时提供了Python.Ruby.MATLAB等语言的接口,实现了图像处理和 ...

  2. 在HTML页面加载完毕后运行某个js

    js <script type="text/javascript"> window.onload=function(){ //执行} </script> j ...

  3. collections queue、os、datetime,序列化(json和pickle)模块

    目录 Collections 模块 1.nametuple 2.deque(双端队列) 3.双端队列(deque): 4.Odereddict(有序字典): 5.Defaultdict(默认字典,首字 ...

  4. iOS画线段

    CGContextRef context = UIGraphicsGetCurrentContext(); //设置线条类型 CGContextSetLineCap(context, kCGLineC ...

  5. xgboost调参过程

    from http://blog.csdn.net/han_xiaoyang/article/details/52665396

  6. jsonp跨域实例

    一.什么是跨域 二.如何解决跨域 1.前端常用 JSONP 2.服务器端配置 HTTP 协议的 header 解析 三.JSONP实现的实例 <!DOCTYPE html> <htm ...

  7. SQL高级教程-TOP 子句

    TOP 子句 TOP 子句用于规定要返回的记录的数目. 对于拥有数千条记录的大型表来说,TOP 子句是非常有用的. 注释:并非所有的数据库系统都支持 TOP 子句. SQL Server 的语法: S ...

  8. asp.net批量下载

    1.首先读取文件夹下的文件,可能同时存在多个文件 2.选中文件,然后点击下载,同时可以选择多个文件. 思路:通过生产压缩包的形式进行下载,然后再清楚压缩包,这样用户可以一次性全部下载下来. 一.获取目 ...

  9. NOIP2018 D1T3赛道修建

    题目链接:Click here Solution: 最小值最大,考虑二分一个答案\(k\) 考虑在子树内先匹配,最后传递一个值给自己的父亲(因为每条边只能用一次,所以一颗子树最多传递一个值) 那么我们 ...

  10. K8S简介

    简介 Kubernetes是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效(powerful),Kubernetes提供了应用部署,规 ...