首页 > 代码库 > bk00
bk00
FORM down_load_file_excel USING p_file_path
p_file_excel TYPE STANDARD TABLE
CHANGING p_subrc.
* Starting download
DATA: l_lcobj_excel TYPE ole2_object,
l_lcobj_workbook TYPE ole2_object,
l_lcobj_sheet TYPE ole2_object,
l_cell TYPE ole2_object,
l_rc TYPE i,
l_sheetname(20) TYPE c,
l_range TYPE ole2_object,
ls_file_excel LIKE LINE OF gt_file_vat_excel.
DATA: ls_separator TYPE c.
CLASS cl_abap_char_utilities DEFINITION LOAD.
ls_separator = cl_abap_char_utilities=>horizontal_tab.
CLEAR ls_file_excel.
CONCATENATE text-l01
text-t01
text-c18
text-c36
text-t09
text-t08
text-t11
text-t12
text-t13
text-t05
* text-c41 "Notes 1732316
* text-c42 "Notes 1732316
text-c42 "Notes 1732316
text-c41 "Notes 1732316
text-l02
text-c16
text-c17
text-l03
text-c19
text-l04
text-t24
text-c23
text-c24
text-c25
text-l05
text-t27
text-l06
text-l07
text-l08
INTO ls_file_excel-line
SEPARATED BY ls_separator.
INSERT ls_file_excel INTO p_file_excel INDEX 1.
l_sheetname = text-c43.
* Create an Excel object and start Excel.
CREATE OBJECT l_lcobj_excel ‘Excel.Application‘.
IF sy-subrc NE 0 AND p_subrc = 0.
p_subrc = 4.
ENDIF.
SET PROPERTY OF l_lcobj_excel ‘Visible‘ = 0.
* Create an Excel workbook Object.
CALL METHOD OF
l_lcobj_excel
‘Workbooks‘ = l_lcobj_workbook.
SET PROPERTY OF l_lcobj_excel ‘SheetsInNewWorkbook‘ = 1.
CALL METHOD OF
l_lcobj_workbook
‘ADD‘.
CALL METHOD OF
l_lcobj_excel
‘Sheets‘ = l_lcobj_sheet
EXPORTING
#1 = 1.
* change sheet name
IF l_sheetname IS NOT INITIAL.
SET PROPERTY OF l_lcobj_sheet ‘NAME‘ = l_sheetname.
ENDIF.
CALL METHOD OF
l_lcobj_excel
‘Worksheets‘ = l_lcobj_sheet
EXPORTING
#1 = l_sheetname.
CALL METHOD OF
l_lcobj_sheet
‘Activate ‘.
CALL METHOD OF
l_lcobj_excel
‘COLUMNS‘ = l_range
EXPORTING
#1 = 2. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 10.
SET PROPERTY OF l_range ‘NumberFormatLocal‘ = ‘@‘ .
CALL METHOD OF
l_lcobj_excel
‘COLUMNS‘ = l_range
EXPORTING
#1 = 3. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 10.
SET PROPERTY OF l_range ‘NumberFormatLocal‘ = ‘@‘ .
CALL METHOD OF
l_lcobj_sheet
‘COLUMNS‘ = l_range
EXPORTING
#1 = 6. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 20.
SET PROPERTY OF l_range ‘NumberFormat‘ = ‘@‘.
CALL METHOD OF
l_lcobj_sheet
‘COLUMNS‘ = l_range
EXPORTING
#1 = 10. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 20.
SET PROPERTY OF l_range ‘NumberFormat‘ = ‘@‘.
CALL METHOD OF
l_lcobj_sheet
‘COLUMNS‘ = l_range
EXPORTING
#1 = 11. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 12.
SET PROPERTY OF l_range ‘NumberFormat‘ = ‘@‘.
CALL METHOD OF
l_lcobj_sheet
‘COLUMNS‘ = l_range
EXPORTING
#1 = 12. "the column number
SET PROPERTY OF l_range ‘ColumnWidth‘ = 10.
SET PROPERTY OF l_range ‘NumberFormat‘ = ‘@‘.
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = p_file_excel
CHANGING
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
CALL METHOD OF
l_lcobj_sheet
‘Cells‘ = l_cell
EXPORTING
#1 = 1
#2 = 1.
CALL METHOD OF
l_cell
‘SELECT‘.
IF sy-subrc NE 0 AND p_subrc = 0.
p_subrc = 5.
ENDIF.
CALL METHOD OF
l_lcobj_sheet
‘PASTE‘.
IF sy-subrc NE 0 AND p_subrc = 0.
p_subrc = 6.
ENDIF.
GET PROPERTY OF l_lcobj_excel ‘ActiveWorkbook‘ = l_lcobj_workbook.
CALL METHOD OF
l_lcobj_workbook
‘SAVEAS‘
EXPORTING
#1 = p_file_path
#2 = 1.
CALL METHOD OF
l_lcobj_workbook
‘CLOSE‘.
CALL METHOD OF
l_lcobj_excel
‘QUIT‘.
IF sy-subrc NE 0 AND p_subrc = 0.
p_subrc = 7.
ENDIF.
ENDFORM.