- class ZCL_EXCEL_READ DEFINITION.
- PUBLIC SECTION.
- data:
- excel_file type LOCALFILE,
- excel_ini_row type i,
- excel_ini_col type i,
- excel_end_row type i,
- excel_end_col type i,
- excel_tab type STANDARD TABLE OF alsmex_tabline,
- excel_tab_head type alsmex_tabline.
- METHODS:
- constructor IMPORTING i_filename type any OPTIONAL
- i_i_row type i OPTIONAL
- i_i_col type i OPTIONAL
- i_e_row type i OPTIONAL
- i_e_col type i OPTIONAL,
- READ_EXCEL IMPORTING i_filename TYPE any OPTIONAL.
- ENDCLASS.
- CLASS ZCL_EXCEL_READ IMPLEMENTATION.
- METHOD constructor.
- if i_i_row is INITIAL. me->excel_ini_row = 1. else. me->excel_ini_row = i_i_row. endif.
- if i_i_col is INITIAL. me->EXCEL_INI_COL = 1. else. me->EXCEL_INI_COL = i_i_col. endif.
- if i_e_col is INITIAL. me->excel_end_col = 100. else. me->excel_end_col = i_e_col. endif.
- if i_e_row is INITIAL. me->excel_end_row = 65535. else. me->excel_end_row = i_e_row. endif.
- if not i_filename is INITIAL. excel_file = i_filename. endif.
- ENDMETHOD.
- METHOD READ_EXCEL.
- if not i_filename is INITIAL.
- me->excel_file = i_filename.
- endif.
- check not me->excel_file is INITIAL.
- CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
- EXPORTING
- filename = me->excel_file
- i_begin_col = me->EXCEL_INI_COL
- i_begin_row = me->EXCEL_INI_ROW
- i_end_col = me->EXCEL_END_COL
- i_end_row = me->EXCEL_END_ROW
- TABLES
- intern = me->excel_tab
- EXCEPTIONS
- inconsistent_parameters = 1
- upload_ole = 2
- OTHERS = 3.
- ENDMETHOD.
- ENDCLASS.
- END-OF-SELECTION.
- *--[ Ejemplo de USO
- data: lv_excel type REF TO ZCL_EXCEL_READ.
- CREATE OBJECT lv_excel
- EXPORTING
- i_filename = 't:\miexcel.xls'
- i_i_row = 1
- i_i_col = 1
- i_e_row = 100
- i_e_col = 10.
- Lv_excel->READ_EXCEL( ).
- loop at Lv_excel->excel_tab into Lv_excel->excel_tab_head.
- CASE Lv_excel->excel_tab_head-col.
- WHEN '1'. " Procesamos la primera columna
- when '2'. " Procesamos la segunda columna
- endcase.
- AT END OF row.
- * APPEND gt_fact.
- * CLEAR gt_fact.
- ENDAT.
- ENDLOOP.
Última modificación de la página el 04 November 2015 a las 15h04
Powered by
PmWiki