用SMW0上传图片文件或者EXCEL模板时,如果没有维护 MIME TYPE,系统会给出提示,
如下:
"无分配给对象 .XLS的 MIME 类型" , 需要先维护 .XLS 文件的MIME TYPE
打开 SMW0
选择第二项二进制数据,然后进去
点菜单“设置”--》维护MIME类型
点击“新增”增加一个类型: TYPE: EXCEL , EXTENSION : *.xls
保存重新再进来就可以了。
其它文件类型原理是一样的。
一:所用到的事物码:
smw0
二:上传步骤
图1
图2
图3
注:“包”为你所在项目的包的名称。
图5
点击“7” 选择Excel模版,就可以将模版上传到sap的服务器上了,另需要记住对象名称,在后面的程序中有需要。
三:下载代码
report ztest135 no standard page heading.
data : fname type string.
data: excel type ole2_object,
workbook type ole2_object,
sheet type ole2_object,
cell type ole2_object.
data: begin of wa,
tabix type i,
t01 type c length 4,
t02 type c length 4,
t03 type c length 4,
t04 type c length 4,
t05 type c length 4,
t06 type c length 4,
end of wa.
data : itab like table of wa with header line.
data: tab type i,
lv_detail type i value 18,
bod type c length 10.
start-of-selection.
perform temp_excel_get.
do 10 times.
itab-t01 = sy-tabix.
itab-t02 = sy-tabix.
itab-t03 = sy-tabix.
itab-t04 = sy-tabix.
itab-t05 = sy-tabix.
itab-t06 = sy-tabix.
append itab.
enddo.
create object excel 'EXCEL.APPLICATION'. "Create EXCEL OBJECT
if sy-subrc ne 0.
exit.
endif.
set property of excel 'Visible' = 1. "1/0 是否显示EXCEL
call method of
excel
'Workbooks' = workbook.
call method of
workbook
'Open'
exporting
#1 = fname."打开上面下载路径下的excel文件
* call method of
* exporting
* #1 = 1.
call method of
sheet
'Select'.
call method of
sheet
'ACTIVATE'.
"sheet 激活
set property of sheet 'NAME' = 'Sheet1'.
"设定sheet名称
*此处假设内表itab 中已经存在需要写入excel中的数据
*并且假如从模板的第19行开始插入数据
perform fill_range using 7 3 'PO PO PO PO PO PO PO PO PO'.
perform fill_range using 7 7 'Ship SHIP Ship SHIP Ship SHIP'.
tab = lv_detail.
loop at itab into wa.
tab = tab + 1.
*在excel中插入一行
perform excel_row_insert using excel tab 1.
*填充所插入行的每个单元格的数据
perform fill_range using tab 1 wa-t01.
perform fill_range using tab 2 wa-t02.
perform fill_range using tab 3 wa-t03.
perform fill_range using tab 5 wa-t04.
perform fill_range using tab 6 wa-t05.
perform fill_range using tab 7 wa-t06.
perform fill_range using tab 8 wa-t06.
endloop.
tab = tab + 1.
perform excel_row_delete using excel tab 1.
*设置EXCEL中所插入的数据行边框线格式为黑色有边框
* bod = tab.
* condense bod no-gaps.
* concatenate 'A1:F' bod into bod.
perform borderrange using excel bod.
perform sub_excel_save."保存excel数据
*&---------------------------------------------------------------------*
*& Form temp_excel_get
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form temp_excel_get.
data: lo_objdata like wwwdatatab,
lo_mime like w3mime,
lc_filename type string value'test01' ,
lc_fullpath type string value'D:\test\' ,
lc_path type string value'D:\test\' ,
ls_destination like rlgrap-filename,
ls_objnam type string,
li_rc like sy-subrc,
ls_errtxt type string.
data:p_objid type wwwdatatab-objid,
p_dest like sapb-sappfad.
p_objid = 'ZPICK'. "此处为excel模板名称
call method cl_gui_frontend_services=>file_save_dialog "调用保存对话框
exporting
default_extension = 'XLS'
default_file_name = lc_filename
changing
filename = lc_filename
path = lc_path
fullpath = lc_fullpath
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4.
if lc_fullpath = ''.
message '不能打开excel' type 'E'.
endif.
if sy-subrc = 0.
p_dest = lc_fullpath.
* concatenate p_objid '.XLS' into ls_objnam.
condense ls_objnam no-gaps.
select single relid objid from wwwdata into corresponding fields of lo_objdata
where srtf2 = 0 and relid = 'MI' and objid = p_objid.
*检查表wwwdata中是否存在所指定的模板文件
if sy-subrc ne 0 or lo_objdata-objid eq space.
"“如果不存在,则给出错误提示
concatenate '模板文件' ls_objnam '不存在' into ls_errtxt.
message ls_errtxt type 'I'.
endif.
ls_destination = p_dest. "保存路径
*如果存在,调用DOWNLOAD_WEB_OBJECT 函数下载模板到路径下
call function 'DOWNLOAD_WEB_OBJECT'
exporting
key = lo_objdata
destination = ls_destination
importing
rc = li_rc.
if li_rc ne 0.
concatenate '模板文件:' ls_objnam '下载失败' into ls_errtxt.
message ls_errtxt type 'E'.
endif.
fname = ls_destination.
endif.
endform. "fm_excel
*&---------------------------------------------------------------------*
*& Form sub_excel_save
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_excel_save.
get property of excel 'ActiveSheet' = sheet. "获取活动sheet
* free object sheet.
* free object workbook.
get property of excel 'ActiveWorkbook' = workbook.
call method of
workbook
'SAVE'.
*
* set property of excel 'Visible' = 1. "是否显示EXCEL 此处显示不退出
call method of
workbook
'CLOSE'.
call method of excel 'QUIT'. "注释部分为不显示直接退出
free object sheet.
free object workbook.
free object excel.
endform. "save_book
*&---------------------------------------------------------------------*
*& 向excel中的指定行插入N行
*&---------------------------------------------------------------------*
form excel_row_insert using lcobj_sheet
lc_row
lc_count.
data lc_range type ole2_object.
data h_borders type ole2_object.
do lc_count times.
call method of
lcobj_sheet
'Rows' = lc_range
exporting
#1 = lc_row.
call method of
lc_range
'Copy'.
"“copy第19行插入一个新行
call method of
lcobj_sheet
'Rows' = lc_range
exporting
#1 = lc_row.
call method of
lc_range
'Insert'.
call method of lc_range 'ClearContents'. "是否需要清空Cell
enddo.
endform. "excel_row_insert
*&---------------------------------------------------------------------*
*& Form EXCEL_ROW_DELETE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXCEL text
* -->P_TAB text
* -->P_1 text
*----------------------------------------------------------------------*
form excel_row_delete using lcobj_sheet
lc_row
lc_count.
data lc_range type ole2_object.
data h_borders type ole2_object.
do lc_count times.
call method of
lcobj_sheet
'Rows' = lc_range
exporting
#1 = lc_row.
call method of
lc_range
'Delete'.
enddo.
endform. " EXCEL_ROW_DELETE
False False Bitmap
|
||||||||
VTech Communications Ltd. | ||||||||
(Contract Manufacturing Division) | ||||||||
PACKING LIST | ||||||||
SHIPMENT VIA: | ||||||||
REF.PO# : | SHIP MARK: | |||||||
CUSTOMER : | ||||||||
PREPARED BY : | MODEL NO.: | |||||||
DEPARTMENT : | ||||||||