Age: 160 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Mon Dec 01, 2008 6:34 pm Post subject: Read different worksheets of Excel
Code:
FUNCTION zexcel_lectura_libro .
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(FILENAME) LIKE RLGRAP-FILENAME
*" VALUE(I_BEGIN_COL) TYPE I
*" VALUE(I_BEGIN_ROW) TYPE I
*" VALUE(I_END_COL) TYPE I
*" VALUE(I_END_ROW) TYPE I
*" TABLES
*" INTERN_SALIDA STRUCTURE ZALSMEX_TABLINE
*" EXCEPTIONS
*" INCONSISTENT_PARAMETERS
*" UPLOAD_OLE
*"----------------------------------------------------------------------
* Variables Locales
DATA: l_excel TYPE ole2_object,
l_libro TYPE ole2_object,
l_hoja TYPE ole2_object,
l_cont TYPE i,
l_celli TYPE ole2_object,
l_cellf TYPE ole2_object,
l_cell TYPE ole2_object,
lt_tabla TYPE TABLE OF ty_s_senderline.
DATA: ld_separator TYPE c.
DATA: ld_rc TYPE i.
DATA: intern LIKE alsmex_tabline OCCURS 0
WITH HEADER LINE.
DATA: lf_pestania(50).
* Se verifica que las filas y columnas sean coherentes
IF i_begin_row > i_end_row.
RAISE inconsistent_parameters.
ENDIF.
IF i_begin_col > i_end_col.
RAISE inconsistent_parameters.
ENDIF.
* Abrimos el Excel
IF l_excel-header = space OR l_excel-handle = -1.
CREATE OBJECT l_excel 'Excel.Application'.
ENDIF.
CALL METHOD OF l_excel 'Workbooks' = l_libro.
CALL METHOD OF l_libro 'Open'
EXPORTING
#1 = filename.
* Se identifica el separador de campos
CLASS cl_abap_char_utilities DEFINITION LOAD.
ld_separator = cl_abap_char_utilities=>horizontal_tab.
* Recorremos las Hojas del Excel
DO.
*-- Incrementamos el Contador para ir de hoja en hoja
ADD 1 TO l_cont.
*-- Leemos la Hoja
CALL METHOD OF l_excel 'Worksheets' = l_hoja
EXPORTING
#1 = l_cont.
*-- Si no existe la hoja Salimos del Bucle
IF NOT sy-subrc IS INITIAL.
EXIT.
ENDIF.
* Tomamos el nombre de la pestaсa
GET PROPERTY OF l_hoja 'NAME' = lf_pestania.
COMMIT WORK AND WAIT.
*-- Recogemos la Primera Celda
CALL METHOD OF l_hoja 'Cells' = l_celli
EXPORTING
#1 = i_begin_row
#2 = i_begin_col.
COMMIT WORK AND WAIT.
*-- Recogemos la Ultima Celda
CALL METHOD OF l_hoja 'Cells' = l_cellf
EXPORTING
#1 = i_end_row
#2 = i_end_col.
COMMIT WORK AND WAIT.
*-- Recogemos las celdas comprendidas entre la Primera y la Ultima
*-- y lo copiamos a la memoria intermedia
CALL METHOD OF l_hoja 'RANGE' = l_cell
EXPORTING
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.