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: 
Read only

SAP Excel program reading only two sheet

former_member191728
Active Participant
0 Likes
951

Hi Experts

I have created a excel program to read data from Excel multiple sheets

I was able to read the data earlier from multiple sheet but now I am getting a strange problem

Only two sheet are always read

Even though I am passing the third sheet name only 2nd sheet data is being fetched

The other problem is If I open the excel file ,opened third worksheet and closed it.

The program starts reading the data from 3rd worksheet but not from worksheet 1

Can you please provide the solution for this or what I am missing here when working with excel

Please find the code what I have written to read the data from multiple sheets and correct me if I am doing anything wrong

LOOP AT i_sheets INTO wa_sheets.

         lw_range-name     = 'Test'.

         lw_range-rows    = p_rows.

         lw_range-columns = p_cols.

         APPEND lw_range TO lt_range.

         CALL METHOD iref_spreadsheet->select_sheet

           EXPORTING

             name     = wa_sheets-sheet_name

*           no_flush = ' '

           IMPORTING

             error    = iref_error

*           retcode  =

           .

         IF iref_error->has_failed = 'X'.

           EXIT.

         ENDIF.

         CALL METHOD iref_spreadsheet->set_selection

           EXPORTING

             top     = 1

             left    = 1

             rows    = p_rows

             columns = p_cols.


         CALL METHOD iref_spreadsheet->insert_range

           EXPORTING

             name     = 'Test'

             rows     = p_rows

             columns  = p_cols

             no_flush = ''

           IMPORTING

             error    = iref_error.

         IF iref_error->has_failed = 'X'.

           EXIT.

         ENDIF.

         REFRESH i_data.

         CALL METHOD iref_spreadsheet->get_ranges_data

*          EXPORTING

*            all      = 'X'

           IMPORTING

             contents = i_data

             error    = iref_error

           CHANGING

             ranges   = lt_range.

         CALL METHOD iref_spreadsheet->delete_ranges

           EXPORTING

             ranges = lt_range.

endloop.

is there any special procedure we need to follow while saving the excel which I am using for the program

Thanks

Pawan Akella

3 REPLIES 3
Read only

roberto_vacca2
Active Contributor
0 Likes
837

Hi.

Your instructions are formally correct. Did you try to change Range-Name at each loop?  Excel could go crazy for the same Range Reference..

Hope to help,

Bye

Read only

0 Likes
837

Hi Roberto

Thanks for the suggestion but unfortunately it didn't work

Thanks

Pawan Akella

Read only

0 Likes
837

Hi Pavan,

Did the issue got resolved. I am also facing similar issue in my project.

kindly suggest on how you resolved this issue.

Regards

Pallavi