Vous êtes sur la page 1sur 12

ABAP Class ZCL_ALV2XLSX

User guide
Version 0.2.0
Hung Hoang (Hoangmanhung@gmail.com)
12/2/2010
ABAP CLASS ZCL_ALV2XLSX

Table of Contents
I. OVERVIEW............................................................................................................................. 2
II. INSTALLATION ..................................................................................................................... 3
III. DOCUMENTS ....................................................................................................................... 3
1. Attributes of the class: ZCL_ALV2XLSX: ........................................................................ 3
2. Methods of the class: ZCL_ALV2XLSX: .......................................................................... 3
2.1 CONSTRUCTOR .......................................................................................................... 3
2.2 INSERT_ROWS............................................................................................................ 4
2.3 WRITE_CELL ............................................................................................................... 4
2.4 WRITE_ROW ................................................................................................................ 4
2.5 WRITE_TABLE ............................................................................................................. 5
2.6 WRITE_TABLE_SLIS ................................................................................................... 5
2.7 WRITE_TABLE_LVC .................................................................................................... 6
2.8 WRITE_TABLE_ALV .................................................................................................... 7
2.9 FORMAT_CELLS.......................................................................................................... 8
2.10 SAVE_DOCUMENT .................................................................................................... 9
2.11 CLOSE_DOCUMENT ................................................................................................. 9
APPENDIX ...............................................................................................................................10
Structure: SOI_FORMAT_ITEM ............................................................................................10
COLOR PALETTE: ................................................................................................................10
FRAME TYPE .......................................................................................................................11

1 December 2010
ABAP CLASS ZCL_ALV2XLSX

I. OVERVIEW

Purpose:

ABAP class ZCL_ALV2XLSX is useful for ABAP developer, in SAP system.

You can use this class to export data on SAP ALV grid to xlsx / xls file format.

Main features:

- Export a CL_GUI_ALV_GRID object to xlsx/xls file with list header.


- Export a table with field catalog, sort table, filter table (in SLIS type pools) to xlsx/xls file.
- Export a table with field catalog, sort table, filter table (in LVC type pools) to xlsx/xls file.
- Export a raw data table, a record, a cell ... to xlsx/xls file.

Compatible with:

- SAP ECC 6.0


- MS Excel 2003.
- MS Excel 2007.
- MS Excel 2010 (not test).

2 December 2010
ABAP CLASS ZCL_ALV2XLSX

II. INSTALLATION
This class should be installed into your system by using SAPLINK utility
(http://code.google.com/p/saplink/)

III. DOCUMENTS
1. Attributes of the class: ZCL_ALV2XLSX:

Attributes Type / Type ref to Description


GO_PROXY I_OI_DOCUMENT_PROXY To handle Proxy control
GO_SPREADSHEET I_OI_SPREADSHEET To handle DOI object
GO_OLE_APP OLE2_OBJECT To handle OLE2 object

2. Methods of the class: ZCL_ALV2XLSX:


(Document use 'SHEET' as instance of class ZCL_ALV2XLSX)

2.1 CONSTRUCTOR
You use this method to create a new document (sheet) in the Office Apps

Could read excel template from local path or from Business Document Service (BDS)

CREATE OBJECT SHEET


EXPORTING
I_DOCUMENT_URL = 'C:\Tmp\excel_template.xls'
I_BDS_CLASS_NAME = 'SOFFICEINTEGRATION'
I_BDS_CLASS_TYPE = 'OT'
I_IBDS_OBJECT_KEY = 'ZTEST01'
I_XLS = SPACE
.

Parameter Optional Description


Xlsx / xls template file path.
I_DOCUMENT_URL X
' ' : Create a new document (don't use template)
I_BDS_CLASS_NAME X BDS class name
I_BDS_CLASS_TYPE X BDS class type
I_BDS_OBJECT_KEY X BDS object key
Xls flag
I_XLS X 'X': Create xls document
' ' : Create xlsx document

3 December 2010
ABAP CLASS ZCL_ALV2XLSX

2.2 INSERT_ROWS
You use this method to insert a numbers of empty rows into sheet.

CALL METHOD SHEET->INSERT_ROWS


EXPORTING
I_TOP = 1
I_NUMBER = 10
.

Parameter Optional Description


I_TOP Top edge of the rows
I_ROWS Number of empty rows need insert

2.3 WRITE_CELL
You use this method to insert a value into a sheet cell w/o format.

CALL METHOD SHEET->WRITE_CELL


EXPORTING
I_ROW =1
I_COLUMN = 2
I_VALUE = 'Cell value'
.

Parameter Optional Description


I_ROW Row position of cell
I_COLUMN Column position of cell
I_VALUE Cell value

2.4 WRITE_ROW
You use this method to insert an ABAP work area into a sheet line w/o format.

CALL METHOD SHEET->WRITE_ROW


EXPORTING
I_TOP =1
I_LEFT = 2
I_RECORD = wa_data
.

Parameter Optional Description


I_TOP Top position of the record
I_LEFT Left position of the record
I_RECORD Word area (record)

4 December 2010
ABAP CLASS ZCL_ALV2XLSX

2.5 WRITE_TABLE
You use this method to insert a raw data table into sheet, at a specific position.

CALL METHOD SHEET->WRITE_TABLE


EXPORTING
I_TOP =1
I_LEFT = 2
IT_OUTTAB = gt_table
.

Parameter Optional Description


I_TOP Top position of the table
I_LEFT Left position of the table
IT_OUTTAB Data table

2.6 WRITE_TABLE_SLIS
You use this method to insert a data table into sheet with field catalog table (SLIS), sort table (SLIS), filter
table (SLIS) like build an ALV grid.

CALL METHOD SHEET->WRITE_TABLE_LVC


EXPORTING
IT_OUTTAB = gt_table
IT_FIELDCAT = gt_fieldcat_lvc
IT_SORT = gt_sort_lvc
IT_FILTER = gt_filter_lvc
IT_LISTHEADER = gt_list_header
I_TOP =1
I_LEFT =1
I_COLUMNS_HEADER = 'X'
I_COLUMNS_AUTOFIT = 'X'
I_FORMAT_COL_HEADER = wa_column_head_format
I_FORMAT_SUBTOTAL = wa_subtotal_format
I_FORMAT_TOTAL = wa_total_format
.

Parameter Optional Description


IT_OUTTAB Data table
IT_FIELDCAT Field catalog table (SLIS), like method WRITE_TABLE_LVC
IT_SORT X Sort table (SLIS)
IT_FILTER X Filter table (SLIS)
IT_LISTHEADER X List header (title, subtitle ...)
I_TOP X Top position of the data block
I_LEFT X Left position of the data block
'X': Display column headers
I_COLUMNS_HEADER X
' ' : No display column headers
I_ COLUMNS_AUTOFIT X 'X': Auto fit columns

5 December 2010
ABAP CLASS ZCL_ALV2XLSX

' ' : Not auto fit columns


Column headers format: Font, color, align, number format ...
I_FORMAT_COL_HEADER X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)
Subtotal lines format: Font, color, align, number format ...
I_FORMAT_SUBTOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)
Total line format: Font, color, align, number format ...
I_FORMAT_TOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)

2.7 WRITE_TABLE_LVC
You use this method to insert a data table into sheet with field catalog table (LVC), sort table (LVC), filter
table (LVC) like build an ALV grid.

CALL METHOD SHEET->WRITE_TABLE_LVC


EXPORTING
IT_OUTTAB = gt_table
IT_FIELDCAT_LVC = gt_fieldcat_lvc
IT_SORT_LVC = gt_sort_lvc
IT_FILTER_LVC = gt_filter_lvc
IT_LISTHEADER_LVC = gt_list_header
I_TOP =1
I_LEFT =1
I_COLUMNS_HEADER = 'X'
I_COLUMNS_AUTOFIT = 'X'
I_FORMAT_COL_HEADER = wa_column_head_format
I_FORMAT_SUBTOTAL = wa_subtotal_format
I_FORMAT_TOTAL = wa_total_format
.

Parameter Optional Description


IT_OUTTAB Data table
Field catalog table (LVC)
Use to set columns characteristics (like ALV) such as
- No display,
IT_FIELDCAT_LVC - No display zero,
- Currency dependence,
- Display columns subtotal, columns total
- ...
IT_SORT_LVC X Sort table (LVC)
IT_FILTER_LVC X Filter table (LVC)
IT_LISTHEADER_LVC X List header (title, subtitle ...)
I_TOP X Top position of the data block
I_LEFT X Left position of the data block
'X': Display column headers
I_COLUMNS_HEADER X
' ' : No display column headers
'X': Auto fit columns
I_COLUMNS_AUTOFIT X
' ' : Not auto fit columns
I_FORMAT_COL_HEADER X Column headers format: Font, color, align, number format ...

6 December 2010
ABAP CLASS ZCL_ALV2XLSX

Type SOI_FORMAT_ITEM (see Appendix /


SOI_FORMAT_ITEM)
Subtotal lines format: Font, color, align, number format ...
I_FORMAT_SUBTOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)
Total line format: Font, color, align, number format ...
I_FORMAT_TOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)

2.8 WRITE_TABLE_ALV
You use this method to insert data got from ALV object (CL_GUI_ALV_GRID) into sheet.

CALL METHOD SHEET->WRITE_TABLE_ALV


EXPORTING
IO_GRID = go_alv_grid
IT_LISTHEADER = gt_list_header
I_TOP =1
I_LEFT =1
I_COLUMNS_HEADER = 'X'
I_COLUMNS_AUTOFIT = 'X'
I_FORMAT_COL_HEADER = wa_column_head_format
I_FORMAT_SUBTOTAL = wa_subtotal_format
I_FORMAT_TOTAL = wa_total_format
.

Parameter Optional Description


IO_GRID ALV object, instance of class CL_GUI_ALV_GRID
IT_LISTHEADER X List header (title, subtitle ...)
I_TOP X Top position of the data block
I_LEFT X Left position of the data block
'X': Display column headers
I_COLUMNS_HEADER X
' ' : No display column headers
'X': Auto fit columns
I_COLUMNS_AUTOFIT X
' ' : Not auto fit columns
Column headers format: Font, color, align, number format ...
I_FORMAT_COL_HEADER X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)
Subtotal lines format: Font, color, align, number format ...
I_FORMAT_SUBTOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)
Total line format: Font, color, align, number format ...
I_FORMAT_TOTAL X Type SOI_FORMAT_ITEM (see Appendix /
SOI_FORMAT_ITEM)

7 December 2010
ABAP CLASS ZCL_ALV2XLSX

2.9 FORMAT_CELLS
You use this method to format sheet cells

CALL METHOD SHEET->FORMAT_CELLS


EXPORTING
I_TOP =1
I_LEFT =1
I_ROWS = 100
I_COLUMNS =5
I_FONT_NAME = 'Arial'
I_FONT_SIZE = 10
I_FONT_STYLE = 'BI'
I_ALIGN = 'L'
I_FRONT_COLOR = 35
I_BACK_COLOR = 26
I_FRAMETYP = 111
I_FRAMECOLOR =1
I_NUMBER =1
I_DECIMALS =2
.

Parameter Optional Description


I_TOP Top position of cells block need to format
I_LEFT Left position
I_ROWS X Number of rows in cells block
I_COLUMNS X Number of columns in cells block
I_FONT_NAME X Font family
I_FONT_SIZE X Font size
Font style of cells
- 'B' : Bold
I_FONT_STYLE X
- 'I' : Italic
- 'BI' (or 'IB'): Bold Italic
Cell alignment:
- 'L': Left
I_ALIGN X
- 'C': Centered
- 'R': Right
I_FRONT_COLOR X Characters color (see Appendix / Color palette)
I_FRAMETYP X Cells border (see Appendix / Frame Type)
I_FRAMECOLOR X Cells background color (see Appendix / Color palette)
Number format:
- 1: Display as a simple number
I_NUMBER X - 2: Scientific display
- 3: Display as a percentage

I_DECIMALS X Number of decimal places

8 December 2010
ABAP CLASS ZCL_ALV2XLSX

2.10 SAVE_DOCUMENT
You use this method save document on presentation server

CALL METHOD SHEET->SAVE_DOCUMENT


EXPORTING
I_SAVE_PATH = 'C:\Export_file.xls'
.

Parameter Optional Description


I_SAVE_PATH File path need to save on presentation server

2.11 CLOSE_DOCUMENT
You use this method to close document and release data.

CALL METHOD SHEET->CLOSE_DOCUMENT


.

9 December 2010
ABAP CLASS ZCL_ALV2XLSX

APPENDIX
Structure: SOI_FORMAT_ITEM

Field Type Description


Name C(256) Name of the cells block ( no need in ZCL_ALV2XLSX class)
Front i Character color (see Appendix / Color palette)
Back I Background color (see Appendix / Color palette)
Font C(256) Name of the font family. The following values are permitted:
- 'Arial'
- 'Courier New'
- 'Times New Roman'
Size i Font size
'-1': Unchanged
Bold i - '1': Bold
- '0': Normal
- '-1': Unchanged
Italic i - '1': Italic
- '0': Normal
- '-1': Unchanged
Align i Alignment:
- '-1': Unchanged
- '0': Right-justified
- '1': Centered
- '2': Left-justified
Frametype i Control byte for setting the frame, (see Appendix / Frame Type)
'-1': Unchanged
Framecolor i Frame color (see Appendix / Color palette)
'-1': Unchanged
Curency C(3) ISO standard currency code
Number i Specifies the format of a cell in a range.
- 1: Display as a simple number
- 2: Scientific display
- 3: Display as a percentage
Decimals i Number of decimal places

COLOR PALETTE:

1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
37 38 39 40 41 42
43 44 45 46 47 48
9 50 51 52 53 54
55 56 57

10 December 2010
ABAP CLASS ZCL_ALV2XLSX

FRAME TYPE:

The parameter has 8 bits:

0 Left margin
1 Top margin
2 Bottom margin
3 Right margin
4 Horizontal line
5 Vertical line
6 Thinness
7 Thickness

For example, need to set fame tyle like that:

It's mean: (no Thickness) - Thinness - (no Vertical) - (no Horizontal) - Right - Bottom - Top - Left margin

Corresponding with 0-1-0-0-1-1-1-1 (binary) or 79 (decimal). So we set Frame type = 79 to get the result
above.

11 December 2010

Vous aimerez peut-être aussi