‎2009 Jul 31 4:18 AM
Hi everybody!
I found a few OLE code. as follows
CREATE OBJECT EXCEL_OBJ 'Excel.Application'.
IF SY-SUBRC NE 0.
MESSAGE E796(F9) WITH 'Can not Create Excel Object!'.
ENDIF.
CALL METHOD OF EXCEL_OBJ 'Workbooks' = WORKBOOK_OBJ.
CALL METHOD OF WORKBOOK_OBJ 'Open' = WORKBOOK_OBJ
EXPORTING
#1 = FILE_NAME.
SET PROPERTY OF EXCEL_OBJ 'Visible' = '1'.
I don't know how to search this value! - ('Workbooks', 'Open', 'Visible' )
Please help me!
thanks advanced.
‎2009 Jul 31 5:30 AM
Hi Xiongfei,
The below method is OLE method of uploading or downloading the data.
'Workbooks', 'Open', 'Visible' are all OLE objects used(declared) to hold the Excel worksheet related data which belong to OLE2 type group.
Below is an Example as how these are used.
*-- Get TAB-sign for separation of fields
CLASS cl_abap_char_utilities DEFINITION LOAD.
w_separator = cl_abap_char_utilities=>horizontal_tab.
*-- Open file in Excel
IF w_application-header = space OR w_application-handle = -1.
CREATE OBJECT w_application 'Excel.Application'.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
ENDIF.
CALL METHOD OF w_application 'Workbooks' = w_workbook.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
CALL METHOD OF w_workbook 'Open' EXPORTING #1 = filename.
IF sy-subrc NE '0'.
RAISE file_open_error.
ENDIF.
*-- Pass the tab number to be opened
CALL METHOD OF w_application 'Worksheets' = w_sheet
EXPORTING
#1 = tabnumber.
*-- Check if the tab number mentioned exists in the spread sheet
IF sy-subrc NE '0'.
*-- Free all the used Excel Objects
PERFORM free_excel_objects.
RAISE invalid_tab_number.
ENDIF.
*-- Activate the sheet to be opened
CALL METHOD OF w_sheet 'Activate'.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
GET PROPERTY OF w_application 'ACTIVESHEET' = w_worksheet.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
*-- Mark whole spread sheet
CALL METHOD OF w_worksheet 'Cells' = w_cell
EXPORTING #1 = c_begin_row #2 = c_begin_col.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
CALL METHOD OF w_worksheet 'Cells' = w_cell1
EXPORTING #1 = c_end_row #2 = c_end_col.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
CALL METHOD OF w_worksheet 'RANGE' = w_range
EXPORTING #1 = w_cell #2 = w_cell1.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
*-- Select the data in the range
CALL METHOD OF w_range 'SELECT'.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
*-- Copy marked area (whole spread sheet) into Clip board
CALL METHOD OF w_range 'COPY'.
IF sy-subrc NE '0'.
EXIT.
ENDIF.
*-- Read clipboard into ABAP
CALL METHOD cl_gui_frontend_services=>clipboard_import
IMPORTING
data = t_excel_tab
EXCEPTIONS
cntl_error = 1
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE a037(alsmex).
ENDIF.u2003
Where in;
*-- Work Fields declared to hold the Spread Sheet Data
DATA: w_application TYPE ole2_object,
w_workbook TYPE ole2_object,
w_range TYPE ole2_object,
w_sheet TYPE ole2_object,
w_worksheet TYPE ole2_object,
w_cell TYPE ole2_object,
w_cell1 TYPE ole2_object.
The values passed to the variables are fixed, ex: 'Workbooks'.
p_file the file from which we need to read the data.
p_tab is the sheet number which needs to be read.
Please see the Function Module ALSM_EXCEL_TO_INTERNAL_TABLE.
Please let me know if you need any further details.
Regards,
Amit.
‎2009 Aug 02 3:24 PM
Thanks your answer!
But i want to see where is have value of "open" "visible" etc.
Please help me and give a detail example!
Thanks Advanced!