&---------------------------------------------------------------------
*& Report Y06_01
&---------------------------------------------------------------------
*& folder.
&---------------------------------------------------------------------
REPORT y06_01.
"定义EXCEL操作相关的变量
DATA: g_excel TYPE ole2_object,
g_application TYPE ole2_object,
g_wbooklist TYPE ole2_object,
g_wbook TYPE ole2_object,
g_newsheet TYPE ole2_object,
go_shapes TYPE ole2_object,
g_pictures TYPE ole2_object.
DATA: picpath TYPE rlgrap-filename. "变量-图片路径
"初始化图片
CREATE OBJECT g_excel ‘EXCEL.APPLICATION’ .
SET PROPERTY OF g_excel ‘Visible’ = 0 .
GET PROPERTY OF g_excel ‘Workbooks’ = g_wbooklist .
GET PROPERTY OF g_wbooklist ‘Application’ = g_application .
SET PROPERTY OF g_application ‘SheetsInNewWorkbook’ = 1 .
CALL METHOD OF g_wbooklist ‘Add’ = g_wbook .
CALL METHOD OF g_wbook ‘WorkSheets’ = g_newsheet
EXPORTING
#1 = 1.
"调用函数
PERFORM download_pic.
PERFORM insert_picture.
"设置EXCEL不可见
SET PROPERTY OF g_excel ‘Visible’ = 1 .
"下载图片到本地
FORM download_pic.
DATA: lf_doctype LIKE bapi_doc_draw-documenttype.
DATA : l_bytecount TYPE i,
l_tdbtype LIKE stxbitmaps-tdbtype,
l_content TYPE STANDARD TABLE OF bapiconten INITIAL SIZE 0.
DATA: graphic_size TYPE i.
DATA: BEGIN OF graphic_table OCCURS 0,
line(255) TYPE x,
END OF graphic_table.
CALL FUNCTION ‘SAPSCRIPT_GET_GRAPHIC_BDS’
EXPORTING
i_object = ‘GRAPHICS’ "对象
i_name = ‘MANSION_LOG2’ "SE78中的名字
i_id = ‘BMAP’ "固定为BMAP
i_btype = ‘BCOL’ "颜色模式 BMON黑白 BCOL彩色
IMPORTING
e_bytecount = l_bytecount
TABLES
content = l_content
EXCEPTIONS
not_found = 1
bds_get_failed = 2
bds_no_content = 3
OTHERS = 4.
CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP’
EXPORTING
old_format = ‘BDS’
new_format = ‘BMP’
bitmap_file_bytecount_in = l_bytecount
IMPORTING
bitmap_file_bytecount = graphic_size
TABLES
bds_bitmap_file = l_content
bitmap_file = graphic_table
EXCEPTIONS
OTHERS = 1.
picpath = ‘E:\CI_LOG2.BMP’.
CALL FUNCTION ‘WS_DOWNLOAD’
EXPORTING
bin_filesize = graphic_size
filename = picpath
filetype = ‘BIN’
TABLES
data_tab = graphic_table
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6.
ENDFORM.
"EXCEL插入图片
FORM insert_picture.
-
GET PROPERTY OF go_sheet ‘Pictures’ = go_pictures.
-
CALL METHOD OF go_pictures ‘Insert’
-
EXPORTING
-
#1 = gv_picpath.
GET PROPERTY OF go_sheet ‘Shapes’ = go_shapes.
CALL METHOD OF go_shapes ‘AddPicture’
EXPORTING
#1 = gv_picpath "image file name on presentation server
#2 = abap_true "1
#3 = abap_true
#4 = 20 "左侧距离
#5 = 8 "上边距
#6 = 90 "宽度
#7 = 45. "高度
ENDFORM.