SAP SMW0 上传EXCEL模板

用SMW0上传图片文件或者EXCEL模板时,如果没有维护 MIME TYPE,系统会给出提示,

 

如下:


"无分配给对象 .XLS的 MIME 类型"  , 需要先维护 .XLS 文件的MIME TYPE

 

打开 SMW0

 

选择第二项二进制数据,然后进去

点菜单“设置”--》维护MIME类型

点击“新增”增加一个类型: TYPE:  EXCEL  ,    EXTENSION :   *.xls

 

保存重新再进来就可以了。

其它文件类型原理是一样的。

:所用到的事物码:

    smw0

二:上传步骤

       

                图1

      图2

                                              图3

注:“包”为你所在项目的包的名称。

 

                      图4

                图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 length 4,
      t02 type length 4,
      t03 type length 4,
      t04 type length 4,
      t05 type length 4,
      t06 type length 4,
      end of wa.
data : itab like table of wa with header line.
data: tab type i,
      lv_detail type value 18,
      bod type 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 'PO PO PO PO PO PO PO PO PO'.
  perform fill_range using '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 wa-t01.
    perform fill_range using tab wa-t02.
    perform fill_range using tab wa-t03.
    perform fill_range using tab wa-t04.
    perform fill_range using tab wa-t05.
    perform fill_range using tab wa-t06.
    perform fill_range using tab 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 and relid 'MI' and objid p_objid.

*检查表wwwdata中是否存在所指定的模板文件
    if sy-subrc ne 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 :      
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,ABAP中可以使用SMW0事务代码来上文件。具体的实现可以参考以下步骤: 1. 首先,创建一个ABAP报表或者一个函数模块,其中包含一个上文件的功能。 2. 在报表或者函数模块中,使用FORM语句定义一个名为FRM_EXCEL_SAVE的子程序,该子程序用于将文件保存到指定的路径。\[1\] 3. 同样,在报表或者函数模块中,使用FORM语句定义一个名为FRM_EXCEL_OPEN的子程序,该子程序用于打开指定的文件。\[2\] 4. 如果需要将数据导出到文件中,可以在报表或者函数模块中使用FORM语句定义一个名为FRM_DATA_EXPORT的子程序。\[3\] 5. 在主程序中,调用相应的子程序来实现文件上功能。具体的步骤包括选择文件、指定文件路径、保存文件等。 总结起来,ABAP中可以通过定义子程序来实现文件上功能,其中包括保存文件和打开文件的子程序。同时,如果需要将数据导出到文件中,可以定义一个导出数据的子程序。在主程序中,调用相应的子程序来实现文件上功能。 #### 引用[.reference_title] - *1* *2* *3* [ABAP文件下上载 用SMW0](https://blog.csdn.net/Wengyuyu1234/article/details/23356331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值