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

Hi all problem while saving excel file.

Former Member
0 Likes
675

Hi all,

I have written following code bt facing problem while saving & closing file. It doesn't save file automatically with save statement .

REPORT ZOPEN_EXCEL .

include ole2incl.

data: e_sheet type ole2_object.

data: e_appl type ole2_object.

data: e_work type ole2_object.

data: e_cell type ole2_object.

data: field_value(30) type c.

parameters: p_file type localfile default 'C:\EBP0447_G1.xls'.

start-of-selection.

  • Start the application

create object e_appl 'EXCEL.APPLICATION'.

set property of e_appl 'VISIBLE' = 1.

  • Open the file

call method of e_appl 'WORKBOOKS' = e_work.

call method of e_work 'OPEN'

exporting

#1 = p_file.

  • Write data to the excel file

do 20 times.

  • Create the value

field_value = sy-index.

shift field_value left deleting leading space.

concatenate 'Cell' field_value

into field_value separated by space.

  • Position to specific cell in Column 1

call method of e_appl 'Cells' = e_cell

exporting

#1 = sy-index

#2 = 1.

  • Set the value

set property of e_cell 'Value' = field_value .

  • Position to specific cell in Column 2

call method of e_appl 'Cells' = e_cell

exporting

#1 = sy-index

#2 = 2.

  • Set the value

set property of e_cell 'Value' = field_value .

enddo.

  • Close the file

call method of e_work 'close'.

  • Quit the file

call method of e_appl 'QUIT'.

free object e_appl.

4 REPLIES 4
Read only

Former Member
0 Likes
617

Hi Abhijeeth,

Where you mentioned save statement in the code. please check code once, If it is there just debug it and it will clear for you..

Regards,

Kumar.

Read only

0 Likes
617

Hi lakshman I added save statement as

call method of e_work 'save'.

bt still not working it wont even close the file.

I added that statemnt before closing workbook.

call method of e_work 'save'.

  • Close the file

call method of e_work 'close'.

  • Quit the file

call method of e_appl 'QUIT'.

free object e_appl.

Read only

0 Likes
617

Hi Abhijeeth,

the hierarchy is:

excel

-workbooks <- this is more like a collection of files; you cannot save this!

--workbook <- this represents a single file

For saving and closing you have to use the workbook-object!

So add the workbook variable to your code as follows:

call method of e_work 'OPEN'= e_workbook

exporting

#1 = p_file.

And now call the method save and close from this object like:

call method of e_workbook 'save'.

call method of e_workbook 'close'.

The Objekt e_work is like a collection of all workbooks. This is why it has an "s" at the end ( workbooks ).This could not be saved or closed.

Thats all. I hope, this serve well.

Best regards

Thomas

Read only

0 Likes
617

Thanks Thomas you solved my problem awarding you full points. If you have any related links please forward it to me.

I need to select sheet depending upon sheet name. Right now I am able to select sheet with sheet number and not with sheet name.

I want to know which are the call methods, properties, etc available for excel application.

if possible please provide us some example codes for better understanding.