Dear colleagues,
I do need help! The problem in few words:
I've created a MS Excel document in XML format using XSLT.
This document is fine except one: it's XML and users want to see a native XLS format.
I have GUI available furthermore I have Excel application on the frontend installed.
I'm trying to use OLE to open this XML file in background and then save it as a 'normal' XLS file.
Here's the code:
METHOD optimize_file.
DATA: application TYPE ole2_object,
workbooks TYPE ole2_object,
workbook TYPE ole2_object,
cells TYPE ole2_object,
entirerow TYPE ole2_object,
lv_excel TYPE i VALUE 56,
lv_rows TYPE string,
lv_index TYPE i,
lv_visibility VALUE '0'.
CREATE OBJECT application 'Excel.application'.
CHECK sy-subrc = 0.
SET PROPERTY OF: application 'Visible' = lv_visibility," NO FLUSH,
application 'DisplayAlerts' = 0." NO FLUSH.
GET PROPERTY OF application 'Workbooks' = workbooks." NO FLUSH.
CHECK sy-subrc = 0.
CALL METHOD OF workbooks 'OpenXML' = workbook "
EXPORTING
#1 = cv_file.
*\/\/\/\/\/\/-----THIS CODE IS JUST FOR VISUAL ISSUES \/\/\/\/\/\/\/
lv_index = 22 + lines( output_table ).
lv_rows = lv_index.
CONDENSE lv_rows.
lv_rows = '22:' && lv_rows.
GET PROPERTY OF application 'Rows' = cells "#EC NOTEXT
EXPORTING #1 = lv_rows.
GET PROPERTY OF cells 'EntireRow' = entirerow . "#EC NOTEXT
CALL METHOD OF entirerow 'AutoFit'. "#EC NOTEXT
*/\/\/\/\/\------END OF VISUAL ISSUES
CALL METHOD OF workbook 'Save'. "#EC NOTEXT
REPLACE '.xml' IN cv_file WITH '.xls'.
IF sy-subrc = 0.
CALL METHOD OF workbook 'Saveas' " NO FLUSH "
EXPORTING "
#1 = cv_file
#2 = lv_excel "'56'
.
IF sy-subrc <> 0.
REPLACE '.xls' IN cv_file WITH '.xml'.
ENDIF.
ENDIF.
CALL METHOD OF workbook 'Close'.
CALL METHOD OF application 'Quit'. " NO FLUSH. "
FREE OBJECT: entirerow,
cells,
workbooks, " NO FLUSH,
workbook ,"NO FLUSH,
application.
ENDMETHOD.
One little addition. If I omit the fileformat in SaveAs method call - everything is working, but file is XML in fact having XLS axtension at the same time. Any help or ideas are highly welcomed!