Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple sheets from EXCEL

vinotha_m
Participant
0 Kudos
266

Hi Everyone,

My requirment is as follows to read multiple sheets from an EXCEL that contains MAcro and some Visual BAsic Components.

I am using FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to read a single sheet which works fine.

But it brings in only one Active sheet at a time.

Please help me resolve this.

CREATE OBJECT application 'EXCEL.APPLICATION'.

CALL METHOD OF application 'Workbooks' = workbook.

CALL METHOD OF workbook 'Open' EXPORTING #1 = p_file.

*call METHOD of Workbook 'Sheets' EXPORTING

  • Open the first sheet in the workbook

CALL METHOD OF workbook 'Worksheets' = sheet EXPORTING #1 = 1.

CALL METHOD OF workbook 'ActivateSheet'

EXPORTING

#1 = 1.

CALL METHOD OF sheet 'Activate'.

CALL METHOD OF sheet 'Save'.

FREE OBJECT application.

SET PROPERTY OF application 'visible' = 0.

CALL METHOD OF application 'QUIT'.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '60'

i_end_row = '32000'

TABLES

intern = it_data

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE:/ 'Upload Error ', sy-subrc.

ENDIF.

APPEND LINES OF it_data TO gt_data.

BREAK-POINT.

CREATE OBJECT application 'EXCEL.APPLICATION'.

CALL METHOD OF application 'Workbooks' = workbook.

CALL METHOD OF workbook 'Open' EXPORTING #1 = p_file.

  • Open the second sheet in the workbook

CALL METHOD OF workbook 'Worksheets' = sheet EXPORTING #1 = 2.

CALL METHOD OF workbook 'ActivateSheet'

EXPORTING

#1 = 2.

CALL METHOD OF sheet 'Activate'.

CALL METHOD OF sheet 'Save'.

SET PROPERTY OF application 'visible' = 0.

FREE OBJECT application.

CALL METHOD OF application 'QUIT'.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '60'

i_end_row = '32000'

TABLES

intern = it_data

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE:/ 'Upload Error ', sy-subrc.

ENDIF.

1 REPLY 1

Subhankar
Active Contributor
0 Kudos
140

Hi ,

Check the below link.

[http://wiki.sdn.sap.com/wiki/display/Snippets/ReadmultiplesheetsofanExcelfileintoSAPthroughABAP]

Thanks.

Subhankar