前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ABAP 简单的OLE操作

ABAP 简单的OLE操作

作者头像
matinal
发布2020-11-27 16:07:23
9150
发布2020-11-27 16:07:23
举报
文章被收录于专栏:SAP Technical

没外网,对于一个做IT的来说,真是相当于脱了水的鱼啊

代码语言:javascript
复制
type-pools ole2 .
data:  count type i,
       count_real type i,
       application type ole2_object,
       workbook type ole2_object,
       excel     type ole2_object,
       sheet type ole2_object,
       cells type ole2_object.
constants: row_max type i value 256.
data index type i.
 
 
data:
      h_cell        type ole2_object,        " cell
      h_f           type ole2_object,        " font
      h_int         type ole2_object,
      h_width       type ole2_object,
      h_columns     type ole2_object,
      h_rows        type ole2_object,
      h_font        type ole2_object,
      h_entirecol   type ole2_object.
.
 
create object excel 'EXCEL.APPLICATION'.
 
if sy-subrc ne 0.
  write: / 'No EXCEL creation possible'.
  stop.
endif.
 
set property of excel 'DisplayAlerts' = 0.
 
call method of excel 'WORKBOOKS' = workbook .
 
set property of excel 'VISIBLE' = 1.
 
 
set property of excel 'SheetsInNewWorkbook' = 1.
call method of workbook 'ADD'.
 
call method of excel 'WORKSHEETS' = sheet
  exporting
  #1 = 1.
 
set property of sheet 'NAME' = 'Color Palette'.
call method of sheet 'ACTIVATE'.
 
data: col type i value 1,
row type i value 2,
col1 type i value 2,
col_real type i value 1.
 
row = 1.
col = 2.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'No.'.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Background'.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Foreground with white background'.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Foreground with black background'.
 
call method of excel 'Rows' = h_rows
  exporting
    #1 = '2:2'.
set property of h_rows 'WrapText' = 1.
 
col = 8.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'No.'.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Background'.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Foreground with white background'.
set property of h_cell 'Bold' = 1.
 
col = col + 1.
call method of excel 'Cells' = h_cell
  exporting
  #1 = row
  #2 = col.
set property of h_cell 'Value' = 'Foreground with black background'.
 
call method of excel 'Rows' = h_rows
  exporting
    #1 = '1:1'.
set property of h_rows 'WrapText' = 1.
get property of h_rows 'Font' = h_font.
set property of h_font 'Bold' = 1.
 
 
count = 1.
count_real = count.
row = 2.
col = 2.
do 56 times.
  perform write_num_and_color.
enddo.
 
 
call method of excel 'Columns' = h_columns
  exporting
    #1 = 'B:K'.
get property of h_columns 'EntireColumn' = h_entirecol.
set property of h_entirecol 'Autofit' = 1.
 
 
 
*&---------------------------------------------------------------------*
*&      Form  write_num_and_color
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form write_num_and_color.
 
" write the color number
  index = row_max * ( row - 1 ) + col.
  call method of sheet 'Cells' = cells
    exporting
    #1 = index.
  set property of cells 'Value' = count_real.
 
" write the color as the background
  col = col + 1.
  call method of excel 'Cells' = h_cell
    exporting
    #1 = row
    #2 = col.
  get property of h_cell 'Interior'   = h_int.
  set property of h_int  'ColorIndex' = count_real.
 
" write the color as the foreground with a white background
  col = col + 1.
  call method of excel 'Cells' = h_cell
  exporting
    #1 = row
    #2 = col.
  set property of h_cell 'Value' = 'Sample Text'.
  get property of h_cell 'Font'    = h_f.
  set property of h_f 'ColorIndex' = count_real.
 
" write the color as the foreground with a black background
  col = col + 1.
  call method of excel 'Cells' = h_cell
  exporting
    #1 = row
    #2 = col.
  get property of h_cell 'Interior'   = h_int.
  set property of h_int  'ColorIndex' = 1.
  set property of h_cell 'Value' = 'Sample Text'.
  get property of h_cell 'Font'    = h_f.
  set property of h_f 'ColorIndex' = count_real.
 
  row = row + 1.
  col = col - 3.
  count = count + 1.
  if count = 29.
    count = 1.
    row = 2.
    col = col + 6.
  endif.
  count_real = count_real + 1.
 
endform.                    "write_num_and_color
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017/02/24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档