OLE 下载SWM0模板

用OLE 下载 SWM0里面的模板到本地,并进行数据填充 。这里好像上传不了模板 直接上代码了。

REPORT ZJ_TE1.
INCLUDE OLE2INCL.
" 时间: 2015/01/05  BY:CHARLES
" 描述:通过OLE下载服务器文件模板到本地

DATA:GC_FIEL TYPE STRING.  "下载路径
DATA GC_NAME TYPE STRING.  " 文件名

DATA: EXCEL     TYPE OLE2_OBJECT,
      WORKBOOK  TYPE OLE2_OBJECT,
      SHEET     TYPE OLE2_OBJECT,
      CELL      TYPE OLE2_OBJECT,
*      cell1     type ole2_object,
      COLUMN    TYPE OLE2_OBJECT,
      RANGE     TYPE OLE2_OBJECT,
      BORDERS   TYPE OLE2_OBJECT,
      BUTTON    TYPE OLE2_OBJECT,
      INT       TYPE OLE2_OBJECT,
      FONT      TYPE OLE2_OBJECT,
      ROW       TYPE OLE2_OBJECT.
DATA: APPLICATION TYPE OLE2_OBJECT,
      BOOK        TYPE OLE2_OBJECT,
      BOOKS       TYPE OLE2_OBJECT,
      OLE_BOOK    TYPE OLE2_OBJECT.

START-OF-SELECTION.

  PERFORM GET_FIEL USING GC_FIEL. "选择路径
  PERFORM GET_MODULE USING ‘TEST.XLS‘ GC_FIEL.  "下载模板

  PERFORM FRM_PROCESS_INDCATOR USING ‘程序正在打开excel文档‘ 0 .  "左下角显示进度条
  PERFORM FRM_CREATE_EXCEL USING GC_FIEL.    " 打开已下载的模板
  PERFORM FRM_FILL_SHEET.   "进行数据填充

  PERFORM FRM_FREE_OBJECT.

*&---------------------------------------------------------------------*
*&      Form  get_fiel
*&---------------------------------------------------------------------*
*       text  下载路径
*----------------------------------------------------------------------*
FORM GET_FIEL USING GC_FIEL.

  GC_NAME = ‘D_NAME‘. " 下载后文件名

  CALL FUNCTION ‘WS_FILENAME_GET‘
    EXPORTING
      DEF_FILENAME     = GC_NAME
      MASK             = ‘,*.XLS,*.XLS,*.XLT,*.XLT,所有文件,*.*. ‘
      MODE             = ‘O‘
      TITLE            = ‘选择输出文件‘
    IMPORTING
      FILENAME         = GC_FIEL
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.

  CASE SY-SUBRC.
    WHEN 0.
    WHEN OTHERS.
      EXIT.
  ENDCASE.

ENDFORM.                    "get_fiel

*&---------------------------------------------------------------------*
*&      Form  get_module
*&---------------------------------------------------------------------*
*       text  获取下载模板
*----------------------------------------------------------------------*
FORM GET_MODULE USING L_NAME L_FILE.
  DATA: LO_OBJDATA LIKE WWWDATATAB,
        LS_OBJNAM TYPE STRING,  "模板文件名
        LS_DESTINATION LIKE RLGRAP-FILENAME.  "

  DATA:LI_RC LIKE SY-SUBRC.

  CONCATENATE L_NAME ‘.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    = L_NAME.

  IF SY-SUBRC NE 0 OR LO_OBJDATA-OBJID EQ SPACE.
    MESSAGE E600(ZDEV) WITH ‘模板文件不存在请用SMW0进行加载‘.
  ENDIF.

  "模板下载
  LS_DESTINATION   = L_FILE.

  CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT‘
    EXPORTING
      KEY         = LO_OBJDATA
      DESTINATION = LS_DESTINATION
    IMPORTING
      RC          = LI_RC.

  IF LI_RC NE 0 .
    MESSAGE E600(ZDEV) WITH ‘模板下载失败‘.
  ENDIF.

ENDFORM.                    "get_module

*&---------------------------------------------------------------------*
*&      Form  FRM_PROCESS_INDCATOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TEXT        text
*      -->P_PERCENTAGE  text
*----------------------------------------------------------------------*
FORM FRM_PROCESS_INDCATOR USING P_TEXT P_PERCENTAGE.

  CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
    EXPORTING
      PERCENTAGE = P_PERCENTAGE
      TEXT       = P_TEXT.
ENDFORM.                    "FRM_PROCESS_INDCATOR

*&---------------------------------------------------------------------*
*&      Form  create_excel
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FRM_CREATE_EXCEL USING P_FILE.

  CREATE OBJECT EXCEL ‘EXCEL.APPLICATION‘.

  IF SY-SUBRC NE 0.
    EXIT.
  ELSE.

    SET PROPERTY OF EXCEL ‘VISIBLE‘ = 1.

    CALL METHOD OF EXCEL                   " Create wbook object
         ‘Workbooks‘ = WORKBOOK.
    " 打开下载的模板
    CALL METHOD OF
        WORKBOOK
        ‘Open‘   = WORKBOOK
      EXPORTING
        #1       = P_FILE.

  ENDIF.

ENDFORM.                    "create_excel

*&---------------------------------------------------------------------*
*&      Form  FRM_FILL_SHEET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FRM_FILL_SHEET.

  CALL METHOD OF
      EXCEL
      ‘WORKSHEETS‘ = SHEET
    EXPORTING
      #1           = 1.   "打开第一个SHEET

  CALL METHOD OF     "显示当前选择的SHEET
      SHEET
      ‘ACTIVATE‘.

  " 抬头信息
  " perform FRM_LINE_RANGE using  1  7 ‘订单号:41088888‘.  “按行 列进行填充

  PERFORM FRM_VALUE_RANGE USING ‘P‘ 1 ‘Z‘ 1 ‘订单号:41088888‘." 按照范围进行填充

  "----------行项目信息
  " 插入空行
  DO 3 TIMES.
    PERFORM FRM_INSERT_ROW USING 14 SHEET CHANGING RANGE.  "14 为被COPY的行
  ENDDO.

" 赋值
  PERFORM FRM_VALUE_RANGE USING ‘A‘14 ‘B‘ 14  ‘TEST1‘.

  PERFORM FRM_VALUE_RANGE USING ‘A‘ 15 ‘B‘ 15  ‘TEST2‘.

  " 资源释放
  FREE OBJECT:BUTTON, FONT, INT, CELL, RANGE, BORDERS, COLUMN, ROW,SHEET.

ENDFORM.                    "FRM_FILL_SHEET

*&---------------------------------------------------------------------*
*&      Form  FRM_VALUE_RANGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FRM_LINE_RANGE  USING    P_LINE
                                P_CELL
                                P_VALUE.
  CALL METHOD OF
      EXCEL
      ‘Cells‘ = CELL
    EXPORTING
      #1      = P_LINE   " 行
      #2      = P_CELL.             "
  SET PROPERTY OF CELL ‘Value‘ =   P_VALUE.

ENDFORM.                    "FRM_VALUE_RANGE

*&---------------------------------------------------------------------*
*&      Form  FRM_VALUE_RANGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0337   text
*      -->P_1      text
*      -->P_0339   text
*      -->P_2      text
*      -->P_LV_VALUE  text
*----------------------------------------------------------------------*
FORM FRM_VALUE_RANGE  USING    P_LEFT
                                P_TOP
                                P_RIGHT
                                P_BOTTOM
                                P_VALUE.

  "data lv_area1 type char3.
  "data lv_area2 type char3.
  "data lv_char2 type char2.

  DATA LV_AREA1 TYPE CHAR4.
  DATA LV_AREA2 TYPE CHAR4.
  DATA LV_CHAR2 TYPE CHAR3.

  LV_CHAR2 = P_TOP.
  CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘  "补零
    EXPORTING
      INPUT  = LV_CHAR2
    IMPORTING
      OUTPUT = LV_CHAR2.

  CLEAR:LV_AREA1,LV_AREA2.

  CONCATENATE P_LEFT LV_CHAR2 INTO LV_AREA1.

  LV_CHAR2 = P_BOTTOM.
  CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
    EXPORTING
      INPUT  = LV_CHAR2
    IMPORTING
      OUTPUT = LV_CHAR2.
  CONCATENATE P_RIGHT LV_CHAR2 INTO LV_AREA2.

  " 设定操作范围
  CALL METHOD OF
      EXCEL
      ‘RANGE‘ = RANGE
    EXPORTING
      #1      = LV_AREA1
      #2      = LV_AREA2.
  SET PROPERTY OF RANGE    ‘VALUE‘ = P_VALUE.

 " PERFORM FRM_SET_FONT  USING 1 ‘11‘ ‘1‘ CHANGING RANGE.

ENDFORM.                    " FRM_VALUE_RANGE

*&---------------------------------------------------------------------*
*&      Form  FRM_INSERT_ROW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_ROW  text
*      <--P_RANGE  text
*----------------------------------------------------------------------*
FORM FRM_INSERT_ROW  USING    P_ROW
                              P_SHEET
                     CHANGING P_RANGE.
  CALL METHOD OF
      P_SHEET
      ‘Rows‘  = P_RANGE
    EXPORTING
      #1      = P_ROW.

  CALL METHOD OF  "COPY 当前行
      P_RANGE
      ‘Copy‘.
  CALL METHOD OF
      P_SHEET
      ‘Rows‘  = P_RANGE
    EXPORTING
      #1      = P_ROW.
  CALL METHOD OF    "在当前行插入
      P_RANGE
      ‘Insert‘.
  CALL METHOD OF P_RANGE ‘ClearContents‘. "是否需要清空Cell
ENDFORM.                    " FRM_INSERT_ROW

*&---------------------------------------------------------------------*
*&      Form  FRM_FREE_OBJECT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FRM_FREE_OBJECT .
  FREE OBJECT SHEET.
  FREE OBJECT WORKBOOK.
  FREE OBJECT EXCEL.

ENDFORM.                    " FRM_FREE_OBJECT

*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FONT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_BOLD     text
*      -->P_SIZE     text
*      -->P_ULINE    text
*      -->P_CELL     text
*    设置字体是否加粗显示
*----------------------------------------------------------------------*
FORM FRM_SET_FONT USING P_BOLD P_SIZE P_ULINE CHANGING P_CELL .
  DATA LR_FONT      TYPE OLE2_OBJECT.

  CALL METHOD OF
      P_CELL
      ‘FONT‘ = LR_FONT.
  SET PROPERTY OF LR_FONT ‘BOLD‘ = P_BOLD.
  SET PROPERTY OF LR_FONT ‘SIZE‘ = P_SIZE.
  SET PROPERTY OF LR_FONT ‘UNDERLINE‘ = P_ULINE.
  FREE OBJECT LR_FONT.

ENDFORM.                    "font
*
时间: 2024-11-11 08:09:15

OLE 下载SWM0模板的相关文章

看到个有趣的方法批量下载rtf模板

一般想要批量下载rtf模板我们都是用fndload来实现或者 perl download.pl来实现,今天看到一个比较有趣的方法 Hi, Blob column 'template file data' below is just what you want, open it in PLSQL-DEVELOPER and save it as a rtf file or you can write programs that work with 'BLOB' objects to export

SpringMVC导入Excule并解析Excule中的数据以及下载Excule模板

把Excule导入,并把Excule中的数据解析出来,包装成对象的属性,保存在数据库中: Excule中的数据: 1.web.xml的配置: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/java

word2013删除下载的模板

word2013删除下载的模板 删除步骤: 1)关闭相关的word文档. 2)按照以下的路径找到相应的位置:"%系统根目录%\Users\Administrator\AppData\Roaming\Microsoft\Templates\". 3)删除相应的模板即可.

download下载excel模板的代码

<%-- 直接在JSP页面中进行文件下载的代码(改 Servlet 或者 JavaBean 的话自己改吧), 支持中文附件名(做了转内码处理). 事实上只要向 out 输出字节就被认为是附件内容, 不一定非要从文件读取原始数据, 从数据 库中读取也可以的. 需传三个参数 newname,name,path --%> <%@ page contentType=" text/html; charset=utf-8" pageEncoding="utf-8&quo

javaweb下载文件模板

import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletReque

关于一个标准的poi下载文件模板 可拿来来直接使用

@RequestMapping(value = "/RK/downloadDemo") @ResponseBody public void downloadExcel(HttpServletResponse response,HttpServletRequest request) { try { Workbook workbook = new HSSFWorkbook(); request.setCharacterEncoding("UTF-8"); respons

SpringBoot之下载excel模板

@GetMapping(value = "/downloadTemplate") public void downFrozenTemplate(HttpServletRequest request, HttpServletResponse response) throws Exception { String fileName = "模板"+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Da

ppt模板下载keyppt.cn

ppt模板下载 ppt模板下载 如何制作ppt ppt背景 ppt是什么 ppt下载 免费ppt模板 动态ppt模板 ppt模板免费下载 商务ppt模板 ppt模板下载 免费完整版 自我介绍ppt模板 商务ppt模板 职业生涯规划ppt模板 ppt模板下载 免费 免费ppt模板下载 工作总结ppt模板 工作汇报ppt模板 ppt http://www.keyppt.cn ppt模板 http://www.keyppt.cn PPT模板下载 http://www.keyppt.cn 商务ppt模板

干货分享!12款响应式的移动网站模板免费下载

如果你打算开发网站,你想要关注的第一件事就是网站的外观和感觉.另外用户体验很重要,现在是属于移动互联的时代,用户有可能通过移动设备浏览你的网站,因此同样重要的是要考虑你的网站在移动端的使用体验. 这个特殊的列表包含一组基于 HTML5 和 CSS3 的移动网站模板,你可以免费下载这些模板,没有任何限制.赶紧收藏吧:) 您可能感兴趣的相关文章 太赞了!超炫的页面切换动画效果[附源码下载] 创意无限!一组网页边栏过渡动画[附源码下载] 好东西!动感的页面加载动画效果[附源码下载] 使用 CSS3 实