Foro -Documentación -Código fuente -Contacto -Empleo

Buscar

Traducir

Amazon

ZEXCEL2 PDF Imprimir E-mail
Usar puntuación: / 0
MaloBueno 
Código fuente - Ejemplos
Lunes, 16 de Febrero de 2004 08:56
Informar celdas en Excel mediante OLE
REPORT zxxx MESSAGE-ID zxxx.
*&---------------------------------------------------------------------*
*&  OLE/2 TEST.                                                        *
*&---------------------------------------------------------------------*


INCLUDE ole2incl.

DATA:   h_appl TYPE ole2_object,
         h_work TYPE ole2_object,
         h_sheet TYPE ole2_object,
         h_cell TYPE ole2_object,
         w_row_it LIKE SY-TABIX,     " row number of the cell
         w_col_it LIKE SY-TABIX,     " column number of the cell

         p_file LIKE rlgrap-filename.


* Create an MSExcel application
 CREATE OBJECT h_appl 'Excel.application'. 
PERFORM errors.

* Make MS-Excel application visible
 SET PROPERTY OF h_appl 'Visible'  = 1.
PERFORM errors.

* Get the list of workbooks
CALL METHOD OF h_appl 'WORKBOOKS'  = h_work.
PERFORM errors.

* Add new workbook (create a file)
CALL METHOD OF h_work 'ADD'. 
PERFORM errors.

* Get the created worksheet
CALL METHOD OF h_appl 'WORKSHEETS'  = h_sheet EXPORTING #1 = 1.
PERFORM errors.

* Activate (select) the first sheet
CALL METHOD OF h_sheet 'ACTIVATE'. 
PERFORM errors.


 w_col_it = 1.
*
DO 9 TIMES.
* create cells A1 thru A9 with values 1 .. 9
  CALL METHOD OF h_sheet 'CELLS'  = h_cell
           EXPORTING #1 = sy-index  #2 = w_col_it.
   SET PROPERTY OF h_cell 'VALUE'  = sy-index.

ENDDO.

* calculate SUM on cell A10
CALL METHOD OF h_sheet 'CELLS'  = h_cell
         EXPORTING #1 = 10  #2 = w_col_it.
 SET PROPERTY OF h_cell 'VALUE'  = '=SUM(R[-9]C:R[-1]C)'. 
PERFORM errors.

* write the file
 p_file = 'c:\temp\test.xls'. 
CALL METHOD OF    h_sheet 'SAVEAS'  EXPORTING #1 = p_file.

* quit application
CALL METHOD OF    h_appl  'QUIT'. 

* free the handle
FREE OBJECT h_appl.

 h_appl-handle = -1.


*&---------------------------------------------------------------------*
*& Test for errors
*&---------------------------------------------------------------------*
FORM errors.
  IF SY-SUBRC NE 0.
*    'Error in OLE call'
     MESSAGE w001 WITH sy-msgli.
    EXIT.
  ENDIF.
ENDFORM.


*Mensajes
*----------------------------------------------------------
*
* Message class: ZXXX
* 001
Comentarios
Buscar
¡Sólo los usuarios registrados pueden escribir comentarios!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
home search