You are on page 1of 11

ABAP Class ZCL_ALV2XLSX

User guide
Hung Hoang (Hoangmanhung@gmail.com) 9/21/2010

ABAP CLASS ZCL_ALV2XLSX

Table of Contents
OVERVIEW .................................................................................................................................................... 2 DOCUMENTS................................................................................................................................................. 3
Attributes of the class: ZCL_ALV2XLSX .............................................................................................. 3 Methods of the class: ZCL_ALV2XLSX ................................................................................................. 3 CONSTRUCTOR .................................................................................................................................. 3 INSERT_ROWS .................................................................................................................................... 3 WRITE_CELL ........................................................................................................................................ 4 WRITE_ROW ........................................................................................................................................ 4 WRITE_TABLE ..................................................................................................................................... 4 WRITE_TABLE_LVC ............................................................................................................................ 5 WRITE_TABLE_SLIS ........................................................................................................................... 6 WRITE_TABLE_ALV ............................................................................................................................ 7 FORMAT_CELLS .................................................................................................................................. 8 SAVE_DOCUMENT .............................................................................................................................. 9 CLOSE_DOCUMENT ........................................................................................................................... 9

APPENDIX ................................................................................................................................................... 10
Structure: SOI_FORMAT_ITEM ............................................................................................................ 10 Color palette: ......................................................................................................................................... 10

September 2010

ABAP CLASS ZCL_ALV2XLSX

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).

September 2010

ABAP CLASS ZCL_ALV2XLSX

Documents
Attributes of the class: ZCL_ALV2XLSX:

Attributes GO_PROXY GO_SPREADSHEET GO_OLE_APP

Type / Type ref to I_OI_DOCUMENT_PROXY I_OI_SPREADSHEET OLE2_OBJECT

Description To handle Proxy control To handle DOI object To handle OLE2 object

Methods of the class: ZCL_ALV2XLSX: (Document use SHEET as instance of class ZCL_ALV2XLSX) CONSTRUCTOR You use this method to create a new document (sheet) in the Office Apps CREATE OBJECT SHEET EXPORTING I_DOCUMENT_URL = 'C:\template.xls' I_XLS = SPACE I_PARAENT = CL_GUI_CONTAINER=>DEFAULT_SCREEN I_INPLACE = 'X' I_NO_FLUSH = 'X' . Parameter I_DOCUMENT_URL I_XLS Optional X X Description Xlsx / xls template file path. ' ' : Create a new document (don't use template) Xls flag 'X': Create xls document ' ' : Create xlsx document

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 I_TOP I_NUMBER Optional Description Top edge of the rows Number of empty rows need insert

September 2010

ABAP CLASS ZCL_ALV2XLSX

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 I_ROW I_COLUMN I_VALUE Optional Description Row position of cell Column position of cell Cell value

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 I_TOP I_LEFT I_RECORD Optional Description Top position of the record Left position of the record Word area (record)

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 I_TOP I_LEFT IT_OUTTAB Optional Description Top position of the table Left position of the table Data table

September 2010

ABAP CLASS ZCL_ALV2XLSX

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_NO_COLUMNS_HEADER = SPACE I_FORMAT_COL_HEADER = wa_column_head_format I_FORMAT_SUBTOTAL = wa_subtotal_format I_FORMAT_TOTAL = wa_total_format . Parameter IT_OUTTAB Optional Description Data table Field catalog table (LVC) Use to set columns characteristics (like ALV) such as - No display, - No display zero, - Currency dependence, - Display columns subtotal, columns total - ... Sort table (LVC) Filter table (LVC) List header (title, subtitle ...) Top position of the data block Left position of the data block 'X': No display column headers ' ' : Display column headers Column headers format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Subtotal lines format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Total line format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM)

IT_FIELDCAT_LVC

IT_SORT_LVC IT_FILTER_LVC IT_LISTHEADER_LVC I_TOP I_LEFT I_NO_COLUMNS_HEADER I_FORMAT_COL_HEADER I_FORMAT_SUBTOTAL I_FORMAT_TOTAL

X X X X X X X X X

September 2010

ABAP CLASS ZCL_ALV2XLSX

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_NO_COLUMNS_HEADER = SPACE I_FORMAT_COL_HEADER = wa_column_head_format I_FORMAT_SUBTOTAL = wa_subtotal_format I_FORMAT_TOTAL = wa_total_format .

Parameter IT_OUTTAB IT_FIELDCAT IT_SORT IT_FILTER IT_LISTHEADER I_TOP I_LEFT I_NO_COLUMNS_HEADER I_FORMAT_COL_HEADER I_FORMAT_SUBTOTAL I_FORMAT_TOTAL

Optional

X X X X X X X X X

Description Data table Field catalog table (SLIS), like method WRITE_TABLE_LVC Sort table (SLIS) Filter table (SLIS) List header (title, subtitle ...) Top position of the data block Left position of the data block 'X': No display column headers ' ' : Display column headers Column headers format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Subtotal lines format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Total line format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM)

September 2010

ABAP CLASS ZCL_ALV2XLSX

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_NO_COLUMNS_HEADER = SPACE I_FORMAT_COL_HEADER = wa_column_head_format I_FORMAT_SUBTOTAL = wa_subtotal_format I_FORMAT_TOTAL = wa_total_format . Parameter IO_GRID IT_LISTHEADER I_TOP I_LEFT I_NO_COLUMNS_HEADER I_FORMAT_COL_HEADER I_FORMAT_SUBTOTAL I_FORMAT_TOTAL Optional X X X X X X X Description ALV object, instance of class CL_GUI_ALV_GRID List header (title, subtitle ...) Top position of the data block Left position of the data block 'X': No display column headers ' ' : Display column headers Column headers format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Subtotal lines format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM) Total line format: Font, color, align, number format ... Type SOI_FORMAT_ITEM (ref to SOI_FORMAT_ITEM)

September 2010

ABAP CLASS ZCL_ALV2XLSX

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 I_TOP I_LEFT I_ROWS I_COLUMNS I_FONT_NAME I_FONT_SIZE I_FONT_STYLE Optional Description Top position of cells block need to format Left position Number of rows in cells block Number of columns in cells block Font family Font size Font style of cells - 'B' : Bold - 'I' : Italic - 'BI' (or 'IB'): Bold Italic Cell alignment: - 'L': Left - 'C': Centered - 'R': Right Characters color (ref to Color palette) Cells border Cells background color (ref to color palette) Number format: - 1: Display as a simple number - 2: Scientific display - 3: Display as a percentage Number of decimal places

X X X X X

I_ALIGN I_FRONT_COLOR I_FRAMETYP I_FRAMECOLOR

X X X X

I_NUMBER

I_DECIMALS

September 2010

ABAP CLASS ZCL_ALV2XLSX

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 I_SAVE_PATH Optional Description File path need to save on presentation server

CLOSE_DOCUMENT You use this method to close document and release data. CALL METHOD SHEET->CLOSE_DOCUMENT .

September 2010

ABAP CLASS ZCL_ALV2XLSX

Appendix
Structure: SOI_FORMAT_ITEM

Field Name Front Back Font

Type C(256) i I C(256)

Size Bold

i i

Italic

Align

Frametype Framecolor Curency Number

i i C(3) i

Decimals

Description Name of the cells block ( no need in ZCL_ALV2XLSX class) Character color (ref to color palette) Background color (ref to color palette) Name of the font family. The following values are permitted: - 'Arial' - 'Courier New' - 'Times New Roman' Font size '-1': Unchanged - '1': Bold - '0': Normal - '-1': Unchanged - '1': Italic - '0': Normal - '-1': Unchanged Alignment: - '-1': Unchanged - '0': Right-justified - '1': Centered - '2': Left-justified Control byte for setting the frame '-1': Unchanged Frame color (see color palette) '-1': Unchanged ISO standard currency code Specifies the format of a cell in a range. - 1: Display as a simple number - 2: Scientific display - 3: Display as a percentage Number of decimal places

COLOR PALETTE: 1 2 7 8 13 14 19 20 25 26 31 32 37 38 43 44 9 50 55 56

3 9 15 21 27 33 39 45 51 57

4 10 16 22 28 34 40 46 52

5 11 17 23 29 35 41 47 53

6 12 18 24 30 36 42 48 54

10

September 2010

You might also like