Application Development 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: 

How to write data on a new sheet of existing Excel file using abap2xlsx

hamida_ashna
Explorer
0 Kudos

I want to know, is there any difference between writing data to a new Excel file and an existing Excel file?

I am able to write data to a new Excel file (create new file). But unfortunately, I am not able to write data to an existing Excel file without changing of data in other sheets of that file.

If somebody could give me some advice or an example code, that would be great. Thanks in advance.

9 REPLIES 9

abo
Active Contributor

You need to read the Excel file first, make the changes you want, then write the file back (see zdemo_excel37 demo)

Be aware that there might, very rarely, be unintended changes: if the file is complex and you simply want to fill in some values in an existing template file, you could also check the zdemo_excel_fill_template demo.

0 Kudos

c5e08e0478aa4727abc4482f5be390b2, thank you for your reply.

Now I can write data to an existing Excel file. Just I don't know why, but after writing data it will remove styles from other sheets.

For example: I have the below Excel file with sheet2, but after writing data to a new sheet, it will remove table style from sheet2.

Sandra_Rossi
Active Contributor

hamida_ashna

Not possible to answer if you don't explain how you generated the Excel file. Is it obtained by just running zdemo_excel37 or by custom code? You must initialize the style of course.

0 Kudos

sandra.rossi, I used the below custom code.

0 Kudos

sandra.rossi, can you please tell me how to initialize the style

0 Kudos

sandra.rossi, do you have any advice?

Sandra_Rossi
Active Contributor

hamida_ashna The abap2xslx demos repository is full of examples. Use either Github or RS_ABAP_SOURCE_SCAN to search anything related to "style".

0 Kudos

sandra.rossi, can please give me advice.

As I mentioned my problem, after reading the file using zcl_excel_reader_2007, I found it that the reader is not able to read style of tables in a sheet (reader can read other styles but can't load table style). Can you please tell me how to fix this issue or how to initialize the style of table?

I checked the abap2xslx demos repository, but didn't find anything related to this issue.

Sandra_Rossi
Active Contributor

hamida_ashna abap2xlsx was created by volunteer ABAP developers and is missing lots of features.

Please create the minimal reproducible example = one very simple Excel file + one very simple program that you attach to a New Issue · abap2xlsx/abap2xlsx (github.com) and I'll look into it.