如何创建文件 xslx multpi sheet sap



我需要从字符串的itab创建一个文件xlsx。 我使用了类cl_gui_frontend_services,方法clipboard_export。 我编写了以下代码,但它没有按预期在路径中创建文件。

IF v_excel-header = space OR v_excel-handle = -1.
CREATE OBJECT v_excel 'EXCEL.APPLICATION'.
ENDIF.
CALL METHOD OF v_excel 'Workbooks' = v_workbooklist.
SET PROPERTY OF v_excel 'Visible' = 0.
CALL METHOD OF v_workbooklist 'Add' = v_workbook.
v_sheet_name = 'A'.
SET PROPERTY OF v_worksheet 'Name' = v_sheet_name.
GET PROPERTY OF v_excel 'ACTIVESHEET' = v_worksheet.
CALL METHOD OF v_excel 'range' = v_range
EXPORTING
#1 = 'A1' "From column
#2 = 'D1'. "To column

CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data                 = pt_data_s1
CHANGING
rc                   = v_return_code
EXCEPTIONS
cntl_error           = 1
error_no_gui         = 2
not_supported_by_gui = 3
OTHERS               = 4.
CALL METHOD OF v_excel 'Cells' = v_fromcell
EXPORTING
#1 = 1
#2 = 1.
CALL METHOD OF v_excel 'Cells' = v_tocell
EXPORTING
#1 = 3
#2 = 4.
CALL METHOD OF v_excel 'Range' = v_datarange
EXPORTING
#1 = v_fromcell
#2 = v_tocell.
CALL METHOD OF v_excel 'Columns' = v_column.
CALL METHOD OF v_column 'Autofit'.
FREE OBJECT v_column.
CALL METHOD OF v_datarange 'Select'.
CALL METHOD OF v_worksheet 'Paste'.
GET PROPERTY OF v_excel 'ActiveWorkbook' = v_worksheet.
CALL METHOD OF v_worksheet 'SAVEAS'
EXPORTING
#1 = lv_path
#2 = 1.
CALL METHOD OF v_worksheet 'close'.

有人可以给我一些建议吗? 谢谢

在乞讨时,您需要调用工作表的方法,例如:

DATA: go_sheet       TYPE ole2_object.
CALL METHOD OF v_excel 
'Worksheets'   = go_sheet
EXPORTING
#1             = gs_config-id_sheet.
CALL METHOD OF go_sheet 'Activate'.
SET PROPERTY OF go_sheet 'Name' = gs_config-name_sheet. "'Sheet1'.

相关内容

  • 没有找到相关文章

最新更新