Quantcast
Channel: SCN: Message List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 3125

Change to the Existing Excel (.XLSM) template from SAP using OLE methods

$
0
0

Hi Experts,

 

As per the client requirement, they have a excel template (which is in .XLSM format) in which they have multiple sheets. The first sheet of the Excel will have to populated from the SAP and same has to be saved in different file name. The subsequent sheets is linked with the first sheet and also there is a macro in place for some functions.

 

I have successfully changed and saved the Excel using the OLE method, but what I could not accomplish was to save it in a different file name. I have tried the method 'SAVEAS' but with no success.

 


REPORT  ZTEST_OLE.

PARAMETERS: XLSFILE(64) TYPE C DEFAULT
'C:\ABCD.XLSM'.
TABLES USR02.
DATA: USERS LIKE USR02 OCCURS 100 WITH HEADER LINE
,ITEMS TYPE I.

CONSTANTS: OK TYPE I VALUE 0.
INCLUDE OLE2INCL.
DATA: EXCEL TYPE OLE2_OBJECT,
WORKBOOK
TYPE OLE2_OBJECT,
SHEET
TYPE OLE2_OBJECT,
CELL
TYPE OLE2_OBJECT,
ROW
TYPE OLE2_OBJECT.

* Create an Excel object and start Excel.
CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
IF SY-SUBRC NE OK.
MESSAGE  'Err' TYPE 'E'."SY-MSGLI.
ENDIF.

* Create an Excel workbook Object.
CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK .
* Put Excel in background
SET PROPERTY OF EXCEL 'VISIBLE' = 0 .

* Transfer the header line to Excel.
CALL METHOD OF WORKBOOK 'OPEN' EXPORTING #1 = XLSFILE.
CALL METHOD OF EXCEL 'RANGE' = CELL EXPORTING #1 = 'A7'.
SET PROPERTY OF CELL 'VALUE' = 'Sample value' .


 

  CALL METHOD OF  WORKBOOK  'SAVE AS'

     EXPORTING

      #1        = 'C:\JUNK\WXYZ.XLSM'.

      #2        = 1.

" At this point i get sy-subrc = 2' which means the method is having some error. Can anyone throw some light on this?

CALL METHOD OF EXCEL 'QUIT'.

* Free all objects
FREE OBJECT CELL.
FREE OBJECT WORKBOOK.
FREE OBJECT EXCEL.
EXCEL
-HANDLE = -1.
FREE OBJECT ROW.

Thanks & Regards,

Ganesh Salunke.


Viewing all articles
Browse latest Browse all 3125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>