因为该EXCEl发送给网银接口,要求Excel的内容不可以修改。 参考信息:http://scn.sap.com/docs/DOC-45427
实现DEMO,待优化:
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
REPORT zzred_test1.
TYPE-POOLS: ole2.
DATA: password TYPE string.
DATA: w_excel TYPE ole2_object,
w_workbook TYPE ole2_object,
w_worksheet TYPE ole2_object,
w_columns TYPE ole2_object,
w_column_ent TYPE ole2_object,
w_cell TYPE ole2_object,
w_int TYPE ole2_object,
w_range TYPE ole2_object,
w_protect TYPE ole2_object,
w_selrange TYPE ole2_object.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'D:123.xls'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
password = 'Admin'.
PERFORM download_excel.
FORM download_excel.
CREATE OBJECT w_excel 'EXCEL.APPLICATION'.
SET PROPERTY OF w_excel 'VISIBLE' = 1.
CALL METHOD OF w_excel 'WORKBOOKS' = w_workbook.
CALL METHOD OF w_workbook 'ADD'.
SET PROPERTY OF w_excel 'SheetsInNewWorkbook' = 1.
PERFORM download_sheet USING 1 'Data Details' .
GET PROPERTY OF w_excel 'ActiveSheet' = w_worksheet.
GET PROPERTY OF w_worksheet 'Protection' = w_protect.
GET PROPERTY OF w_protect 'AllowEditRanges' = w_selrange.
CALL METHOD OF w_excel 'RANGE' = w_range
EXPORTING
#1 = 'A1'
#2 = 'D11'.
CALL METHOD OF w_selrange 'Add'
EXPORTING
#1 = 'Range1'
#2 = w_range
#3 = password.
GET PROPERTY OF w_excel 'ActiveSheet' = w_worksheet.
CALL METHOD OF w_worksheet 'PROTECT'
EXPORTING
#1 = password.
GET PROPERTY OF w_excel 'ActiveWorkbook' = w_workbook.
CALL METHOD OF w_workbook 'SAVES'
EXPORTING
#1 = p_file
#2 = 18.
FREE OBJECT: w_worksheet, w_excel.
ENDFORM. "download_excel
FORM download_sheet USING p_sheet TYPE i
p_name TYPE string.
CALL METHOD OF w_excel 'WORKSHEETS' = w_worksheet
EXPORTING
#1 = p_sheet.
CALL METHOD OF w_worksheet 'ACTIVATE'.
SET PROPERTY OF w_worksheet 'NAME' = p_name.
CALL METHOD OF w_excel 'Range' = w_range
EXPORTING #1 = 'A1' #2 = 'D11'.
CALL METHOD OF w_range 'FONT' = w_int.
SET PROPERTY OF w_int 'ColorIndex' = 10.
PERFORM fill_cell USING w_worksheet w_cell 1 1 'hello'.
PERFORM fill_cell USING w_worksheet w_cell 1 2 'world'.
PERFORM fill_cell USING w_worksheet w_cell 3 2 'Writed by:'.
PERFORM fill_cell USING w_worksheet w_cell 3 3 'Red'.
ENDFORM. "download_sheet
FORM fill_cell USING sheet cell row col value.
CALL METHOD OF sheet 'Cells' = cell NO FLUSH
EXPORTING #1 = row #2 = col.
SET PROPERTY OF cell 'VALUE' = value.
ENDFORM. "fill_cell
FORM user_validate TABLES p_tab CHANGING password.
password = 'Admin'.
CALL METHOD cl_http_utility=>if_http_utility~decode_base64
EXPORTING
encoded = password
RECEIVING
decoded = password.
ENDFORM. "user_validate