当前位置:网站首页>SAP ABAP excel export (multiple sheet pages)
SAP ABAP excel export (multiple sheet pages)
2022-07-19 00:36:00 【Please enter the nickname inflated steamed bread】
SAP ABAP EXCEL export ( many sheet page )
List of articles
Preface
Sometimes we need to divide the data sheet Page export , and SAP The standard export function of cannot meet our needs
At this time, we need to develop our own export function
Code Overview
DATA: v_filename TYPE string,
wa_excel TYPE ole2_object,
wa_book TYPE ole2_object,
wa_sheet TYPE ole2_object,
wa_cell TYPE ole2_object.
DATA: v_index TYPE i VALUE IS INITIAL,
v_sheet_index TYPE i VALUE IS INITIAL.
CALL METHOD cl_gui_frontend_services=>directory_browse
CHANGING
selected_folder = v_filename.
CONCATENATE v_filename '\ xxx surface ' '_' sy-datum '_' sy-uzeit
'.xls'
INTO v_filename.
CREATE OBJECT wa_excel 'EXCEL.APPLICATION'.
SET PROPERTY OF wa_excel 'Visible' = 0.
CALL METHOD OF wa_excel 'Workbooks' = wa_book.
SET PROPERTY OF wa_excel 'SHEETSINNEWWORKBOOK' = 1.
CALL METHOD OF wa_book 'ADD'.
v_sheet_index = 1.
CALL METHOD OF wa_excel 'WORKSHEETS' = wa_sheet
EXPORTING
#1 = v_sheet_index.
CALL METHOD OF wa_sheet 'ACTIVATE'.
SET PROPERTY OF wa_sheet 'NAME' = 'sheetname'.
CLEAR v_index.
LOOP AT it_fieldcat INTO wa_fieldcat. " EXCEL Look up
v_index = v_index + 1.
CALL METHOD OF wa_excel 'Cells' = wa_cell
EXPORTING #1 = v_index #2 = sy-index.
SET PROPERTY OF wa_cell 'Value' = wa_fieldcat-seltext_l.
ENDLOOP.
GET PROPERTY OF wa_excel 'ActiveWorkbook' = wa_book.
CALL METHOD OF wa_sheet 'SAVEAS'
EXPORTING
#1 = v_filename
#2 = 1.
CALL METHOD OF wa_book 'CLOSE'.
CALL METHOD OF wa_excel 'QUIT'.
MESSAGE ' export ' && v_filename && ' Completed ! Please sprinkle flowers to celebrate !' TYPE 'S'.
Code parsing
Variable definitions
| v_filename | Exported file name |
|---|---|
| wa_excel | Excel object |
| wa_book | Workbook object |
| wa_sheet | Sheet object |
| wa_cell | Cell object |
| v_index | control cell Number of columns |
| v_sheet_index | control sheet the number of pages |
DATA: v_filename TYPE string,
wa_excel TYPE ole2_object,
wa_book TYPE ole2_object,
wa_sheet TYPE ole2_object,
wa_cell TYPE ole2_object.
DATA: v_index TYPE i VALUE IS INITIAL,
v_sheet_index TYPE i VALUE IS INITIAL.
establish Excel And Book Workbook object
The file name here can be defined at the end of the program
CREATE OBJECT wa_excel ‘EXCEL.APPLICATION’ Create a EXCEL object
CALL METHOD OF wa_excel ‘Workbooks’ = wa_book call EXCEL Object's Workbooks The method is to EXCEL Object to add a workbook object
CALL METHOD cl_gui_frontend_services=>directory_browse
CHANGING
selected_folder = v_filename.
CONCATENATE v_filename '\ xxx surface ' '_' sy-datum '_' sy-uzeit
'.xls'
INTO v_filename.
CREATE OBJECT wa_excel 'EXCEL.APPLICATION'.
SET PROPERTY OF wa_excel 'Visible' = 0.
CALL METHOD OF wa_excel 'Workbooks' = wa_book.
SET PROPERTY OF wa_excel 'SHEETSINNEWWORKBOOK' = 1.
CALL METHOD OF wa_book 'ADD'.
newly build sheet Page and fill in the cell contents
ALL METHOD OF wa_excel ‘WORKSHEETS’ call EXCEL Of ‘WORKSHEETS’ Method to pass in parameters sheet The page number is added to the workbook sheet page
CALL METHOD OF wa_sheet ‘ACTIVATE’ Select the currently added sheet object
SET PROPERTY OF wa_sheet ‘NAME’ = ‘sheetname’ Modify the current sheet Page name
Here we cycle ALV A list of , Add the list names to our cell In cell
CALL METHOD OF wa_excel ‘Cells’ = wa_cell Pass in the row and column to get the specified cell object
SET PROPERTY OF wa_cell ‘Value’ = wa_fieldcat-seltext_l Set the properties of the cell object Value The value is our ALV List name
v_sheet_index = 1.
CALL METHOD OF wa_excel 'WORKSHEETS' = wa_sheet
EXPORTING
#1 = v_sheet_index.
CALL METHOD OF wa_sheet 'ACTIVATE'.
SET PROPERTY OF wa_sheet 'NAME' = 'sheetname'.
CLEAR v_index.
LOOP AT it_fieldcat INTO wa_fieldcat. " EXCEL Look up
v_index = v_index + 1.
CALL METHOD OF wa_excel 'Cells' = wa_cell
EXPORTING #1 = v_index #2 = sy-index.
SET PROPERTY OF wa_cell 'Value' = wa_fieldcat-seltext_l.
ENDLOOP.
Excel Save and export
CALL METHOD OF wa_sheet ‘SAVES’ call sheet Object's SAVES Method passes in the file name to save the file
Then close the workbook one by one and exit EXCEL process
GET PROPERTY OF wa_excel 'ActiveWorkbook' = wa_book.
CALL METHOD OF wa_sheet 'SAVEAS'
EXPORTING
#1 = v_filename
#2 = 1.
CALL METHOD OF wa_book 'CLOSE'.
CALL METHOD OF wa_excel 'QUIT'.
MESSAGE ' export ' && v_filename && ' Completed ! Please sprinkle flowers to celebrate !' TYPE 'S'.
边栏推荐
- 【无标题】
- C语言的内存管理-堆、栈等
- uml类图浅录
- libtorch cmake
- Lead friends on the whole network to complete chalk login encryption analysis, and change the way to play again
- Solve the problem of browser strobe after Huawei notebook is installed with driver
- 推荐一个讲即时通信的博客
- 2022-07-15 advanced network engineering (XIX) BGP state machine, interaction principles between peers, factors affecting the establishment of peer relations, peer table, routing table, detailed routin
- KubeSphere 部署
- Arrow function of ES6
猜你喜欢

Points needing attention in vertx programming

微信小程序开发学习2(模板与配置)

WordPress Theme sharing: flatsome theme v3.15.7 download the latest version in 2022 for free

Memory management of C language - heap, stack, etc

Lead friends on the whole network to complete chalk login encryption analysis, and change the way to play again

PHP uploads Excel files through form forms and imports Excel data into the database

Box model, table case

php通过form表单上传Excel文件并把Excel数据导入到数据库中

C语言的内存管理-堆、栈等

Coordinate solution of rectangular coordinate system rotation (n*90 °) (1 ≤ n ≤ 4)
随机推荐
没有老板的乐视员工过上“神仙日子”,靠什么?
Beautiful Soup模块是什么
C语言的内存管理-堆、栈等
Installation and usage of yarn tool in nodejs compilation environment
利用numpy实现卷积操作
Effectively reduce project costs, starting with project procurement management
Umap introduction and code examples
【无标题】
面试官:工作两年了,这么简单的算法题你都不会?
Database collation
Introduction to promise module in nodejs
Stateless design of application
After yarn /nmp global installation, the command does not take effect
有的小伙伴问我英语不好可以学编程吗?
业务太忙,真的是没时间搞自动化理由吗?
25 performance testing articles
Shell's third day small exercise: access the self built nextcloud network disk service through the self built DNS server
TCP silly window syndrome and rate based flow control
Easy operation of cloud platform
C语言基础演练(5)