OLE-DB 操作excel 基本
1
方法用例
*&---------------------------------------------------------------------*
*&
本程序总结了常用的
ABAP
对
EXCEL
的操作,包括如下子例程
*&
方法名
方法说明
*& (1) create_excel
创建
excel
*& (2) insert_row
插入行
*& (3) fill_cell
填充单元格
*& (4) columnwidth
调整列宽
*& (5) create_sheet
创建
sheet
*& (6) copy_sheet_all sheet
复制
*& (7) copy_sheet_area sheet
区域复制
*& (8) copy_cells
复制单元格
*& (9) range_borders
边框粗细
*& (10) row_color
行颜色
*& (11) preview_excel
预览
*& (12) free_object
释放对象
*& (13) close_excel
关闭
excel
*& (14) download_excel_fromserver
从服务器下载
excel
模板(进入模板事务代码
SMW0
)
*& (15) open_excel_hide
隐蔽打开
excel
*& (16) open_excel
打开
excel
*& (17) open_excel_sheet
打开指定的
excel
的
sheet
*& (18) open_excel_by_sheet
打开
sheet
*& (19) select_range
选择范围
*& (20) clear_data
清除数据
*& (21) merge_cells
合并单元格
*& (22) process_indcator
进度指示
*& (23) delete_row
删除行
*& (24) add_comment
添加注释
*& (25) hide_columns
隐藏列
*& (26) delete_columns
删除列
*& (27) hide_row
隐藏行
*
保护工作区
lock_unlock_excel
:未完成
*
保护整个工作表
lock_sheet
:
未完成
*&
本示例程序作为
ABAP
对
EXCEL
操作的参考
,
可以根据需要做适当的调整
*&---------------------------------------------------------------------
*
REPORT zdealexcel.
TYPE-POOLS ole2.
TABLES sscrfields.
DEFINE m_
m
essage.
case sy-subrc.
when '0'.
when others.
message e000(zmeg)
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endcase.
END-OF-DEFINITION.
DATA: application TYPE ole2_object, "excel object
workbook TYPE ole2_object, "excel workbook objcet sheet TYPE ole2_object, "workbook sheet object columns TYPE ole2_object, "sheet col objcet rows TYPE ole2_object, "sheet row objcet range TYPE ole2_object, "range
range1 TYPE ole2_object, "range1 font TYPE ole2_object, "font cell TYPE ole2_object, "cell
cell1 TYPE ole2_object, "cell1 sheet1 TYPE ole2_object, "workbook sheet object borders TYPE ole2_object. "borders
DATA: index TYPE i VALUE 0.
*定义模板下载到本地保存的全名称
DATA: p_down_file LIKE sapb-sappfad. "定义模板下载到本地保存的全名称
*演示excel操作
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN: PUSHBUTTON 01(12) but0 USER-COMMAND cli0, PUSHBUTTON 20(15) but2 USER-COMMAND cli2. SELECTION-SCREEN END OF LINE.
*导入数据块
SELECTION-SCREEN BEGIN OF BLOCK status2 WITH FRAME TITLE text-f02. SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(20) text-002. PARAMETERS: p_file LIKE rlgrap-filename. SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK status2.
*导出数据块
SELECTION-SCREEN BEGIN OF BLOCK status3 WITH FRAME TITLE text-f03 .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(20) text-003.
PARAMETERS: p_down LIKE rlgrap-filename.
SELECTION-SCREEN:
PUSHBUTTON 75(20) but1 USER-COMMAND cli1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK status3.
INITIALIZATION.
CREATE OBJECT application 'excel.APPLICATION'.
but0 =
'
演示
excel
操作
'. "
初始化导出
button
显示名称
but1 =
'
导出
'. "
初始化导出
button
显示名称
but2 =
'
从模板导出
excel'. "
从模板导出
excel
*-------------------------
设置文件上载
-------------------------
AT SELECTION-SCREEN ON VALUE-
REQUEST FOR p_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path =
p_file
m
ask =
',*.*.'
m
ode =
'O'
title =
text-f01
IMPORTING
filenam
e =
p_file
EXCEPTIONS
inv_winsys =
1
no_batch =
2
selection_cancel =
3
selection_error =
4
OTHERS =
5.
CHECK sy-subrc =
0 AND NOT p_file IS INITIAL.
*-------------------------
设置文件下载
-------------------------
AT SELECTION-SCREEN ON VALUE-
REQUEST FOR p_down.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path =
p_down
m
ask =
',*.xls,*.xls.'
m
ode =
'S'
title =
text-f02
IMPORTING
filenam
e =
p_down
EXCEPTIONS
inv_winsys =
1
no_batch =
2
selection_cancel =
3
selection_error =
4
OTHERS =
5.
CHECK sy-subrc =
0 AND NOT p_down IS INITIAL.
*--------------------------------------------------------------
AT SELECTION-SCREEN.
IF sscrfields-ucomm EQ 'CLI1'.
IF p_down IS INITIAL.
MESSAGE e804(zdev).
ELSE.
p_down_file =
p_down.
PERFORM download_excel_fromserver USING 'ZHRI0004' p_down_file .
"
下载模板到本地
MESSAGE i600(zdev) WITH '
模板导出成功
'.
ENDIF.
ELSEIF sscrfields-ucomm EQ 'ONLI'.
IF p_file IS INITIAL.
MESSAGE e803(zdev).
ENDIF.
ELSEIF sscrfields-ucomm EQ 'CLI0'.
PERFORM demo_forms.
ELSEIF sscrfields-ucomm EQ 'CLI2'.
PERFORM demo_forms_server USING p_file.
ENDIF.
START-OF-SELECTION.
PERFORM open_excel_hide USING p_file.
PERFORM close_excel.
PERFORM open_excel USING p_file.
PERFORM close_excel.
PERFORM open_excel_sheet USING 'sheet2' p_file.
DO 10 TIMES.
PERFORM insert_row USING 1.
PERFORM fill_cell USING 1 1 0 'e'.
PERFORM fill_cell USING 1 2 0 'f'.
PERFORM fill_cell USING 1 3 0 'g'.
index =
index +
1.
ENDDO.
PERFORM close_excel.
PERFORM free_object.
*&---------------------------------------------------------------------* *& Form demo_forms_server
*&---------------------------------------------------------------------* * 从SMW0下载excel模板
*----------------------------------------------------------------------* * -->P_FILE excel本地路径
*----------------------------------------------------------------------* FORM demo_forms_server USING p_file. p_down_file = p_file.
PERFORM process_indcator USING '程序正在下载模板' 0 .
PERFORM download_excel_fromserver USING 'ZHRI0004' p_down_file .
PERFORM process_indcator USING '程序正在初始化OLE控件' 0 .
PERFORM process_indcator USING '程序正在打开excel文档' 0 .
PERFORM open_excel_sheet USING '处分处罚信息批导入' p_file.
DO 10 TIMES.
PERFORM insert_row USING 5. PERFORM fill_cell USING 5 1 0 'e'. PERFORM fill_cell USING 5 2 0 'f'. PERFORM fill_cell USING 5 3 0 'g'. index = index + 1. ENDDO.
PERFORM clear_data USING 1 6 2 7. PERFORM merge_cells USING 1 6 2 7. PERFORM add_comment USING 8 1 'OK'. PERFORM close_excel. PERFORM free_object.
ENDFORM. "demo_forms_server
*&---------------------------------------------------------------------* *& Form demo_forms
*&---------------------------------------------------------------------* * 演示用form
*----------------------------------------------------------------------* FORM demo_forms
DO 10 TIMES.
PERFORM insert_row USING 1.
PERFORM fill_cell USING 1 1 0 'a'.
PERFORM fill_cell USING 1 2 0 'b'.
PERFORM fill_cell USING 1 3 0 'c'.
index =
index +
1.
ENDDO.
PERFORM columnwidth USING 'A:C' '' .
PERFORM create_sheet.
PERFORM create_sheet.
PERFORM copy_sheet_all.
PERFORM copy_sheet_area.
PERFORM copy_cells.
PERFORM range_borders.
PERFORM row_color USING 1.
PERFORM preview_excel.
PERFORM del_sheet USING 'sheet2'.
PERFORM free_object.
ENDFORM. "dem
o_forms
*&---------------------------------------------------------------------
*
*& (1) Form create_excel
*&---------------------------------------------------------------------
*
*
创建
excel
*----------------------------------------------------------------------*
FORM create_excel.
IF sy-subrc <> 0.
MESSAGE 'EXCEL ERROR' TYPE 'S' DISPLAY LIKE 'E'.
STOP.
ENDIF.
CALL METHOD OF application 'WORKBOOKS' =
workbook.
SET PROPERTY OF application 'VISIBLE' =
1.
SET PROPERTY OF application 'SHEETSINNEWWORKBOOK' =
1.
CALL METHOD OF workbook 'ADD' =
sheet.
CALL METHOD OF sheet 'ACTIVE'.
ENDFORM. "create_excel
*&---------------------------------------------------------------------
*
*& (2) Form
insert_row
*&---------------------------------------------------------------------
*
*
根据行号插入一行
*----------------------------------------------------------------------*
* -->
I_ROW
行号
*----------------------------------------------------------------------*
FORM insert_row USING i_row.
CALL METHOD OF application 'ROWS' =
rows
EXPORTING
#1 =
i_row.
CALL METHOD OF rows 'INSERT'.
ENDFORM. "insert_row
*&---------------------------------------------------------------------
*
*& (3) Form
fill_cell
*&---------------------------------------------------------------------
*
*
填充单元格
*----------------------------------------------------------------------*
* -->
I_ROW
行号
* -->
I_COL
列号
* -->BOLD
是否加粗
* -->
P_VALUE
值
*----------------------------------------------------------------------*
FORM fill_cell USING i_row i_col bold p_value.
CALL METHOD OF application 'CELLS' =
cell
EXPORTING
#1 =
i_row
#2 =
i_col.
SET PROPERTY OF cell 'VALUE' = p_value.
SET PROPERTY OF cell 'HORIZONTALALIGNMENT' =
2.
GET PROPERTY OF cell 'FONT' =
font.
SET PROPERTY OF font 'BOLD' =
bold.
SET PROPERTY OF font 'COLORINDEX' =
41.
CALL METHOD OF cell 'BORDERS' =
borders
EXPORTING
#1 =
'2'.
SET PROPERTY OF borders 'LINESTYLE' =
'0'.
SET PROPERTY OF borders 'WEIGHT' =
0.
ENDFORM. "fill_cell
*&---------------------------------------------------------------------
*
*& (4) Form
columnwidth
*&---------------------------------------------------------------------*
*
设置列宽为自动或是固定值
*----------------------------------------------------------------------*
* -->
COLNUM
列号
,
可以为单个列或是多个列
* -->
WIDT
H
列宽值
*----------------------------------------------------------------------*
FORM columnwidth USING colnum width.
CALL METHOD OF application 'COLUMNS' =
columns
EXPORTING
#1 =
colnum.
IF width =
''.
CALL METHOD OF columns 'AutoFit'.
ELSE.
SET PROPERTY OF colum
ns 'COLUMNWIDTH' =
width.
ENDIF.
ENDFORM. "columnwidth
*&---------------------------------------------------------------------
*
*& (5) Form
create_sheet
*&---------------------------------------------------------------------
*
*
创建
sheet
*----------------------------------------------------------------------*
FORM create_sheet.
CALL METHOD OF application 'sheets' =
sheet.
CALL METHOD OF sheet 'ADD'.
ENDFORM. "create_sheet
*&---------------------------------------------------------------------
*
*& (6) Form
copy_sheet_all
*&---------------------------------------------------------------------
*
*
复制
sheet
全部内容到另一个
sheet
*----------------------------------------------------------------------*
FORM copy_sheet_all.
CALL METHOD OF application 'Sheets' =
sheet
EXPORTING
#1 =
'Sheet1'.
CALL METHOD OF sheet 'Cells' =
cell.
CALL METHOD OF cell 'copy'.
CALL METHOD OF application 'Sheets' =
sheet
EXPORTING
#1 =
'Sheet3'.
CALL METHOD OF application 'Range' =
range
EXPORTING
#1 =
'A1'.
CALL METHOD OF range 'PasteSpecial'.
ENDFORM. "copy_sheet_all
*&---------------------------------------------------------------------
*
*& (7) Form
copy_sheet_area
*&---------------------------------------------------------
------------*
*
复制
sheet
部分内容到另一个
sheet
*----------------------------------------------------------------------*
FORM copy_sheet_area.
CALL METHOD OF application 'Sheets' =
sheet
EXPORTING
#1 =
'Sheet1'.
CALL METHOD OF sheet 'Range' =
range
EXPORTING
#1 =
'A1'
#2 =
'B10'.
CALL METHOD OF range 'copy'.
CALL METHOD OF application 'Sheets' =
sheet1
EXPORTING
#1 =
'Sheet2'.
CALL METHOD OF sheet1 'Range' = range1
EXPORTING
#1 =
'A1'
#2 =
'B10'.
CALL METHOD OF range1 'PasteSpecial'.
ENDFORM. "copy_sheet_area
*&---------------------------------------------------------------------
*
*& (8) Form
copy_cells
*&---------------------------------------------------------------------*
*
在一个
sheet
内复制单元格
*----------------------------------------------------------------------*
FORM copy_cells.
CALL METHOD OF application 'Sheets' =
sheet
EXPORTING
#1 =
'Sheet1'.
CALL METHOD OF sheet 'Range' =
range
EXPORTING
#1 =
'A1'
#2 =
'B10'.
CALL METHOD OF range 'copy'.
CALL METHOD OF sheet 'Range' =
range1
EXPORTING
#1 =
'A12'
#2 =
'B22'.
CALL METHOD OF range1 'PasteSpecial'.
ENDFORM. "copy_cells
*&---------------------------------------------------------------------*
*& (9) Form
range_borders
*&---------------------------------------------------------------------
*
*
指定
range
加边框
*----------------------------------------------------------------------*
FORM range_borders.
CALL METHOD OF application 'Range' =
range
EXPORTING
#1 =
'A1'
#2 =
'B10'.
CALL METHOD OF range 'BORDERS' =
borders.
SET PROPERTY OF borders 'LINESTYLE' =
1.
SET PROPERTY OF borders 'WEIGHT' =
10.
ENDFORM. "range_borders
*&---------------------------------------------------------------------
*
*& (10) Form row_color
*&---------------------------------------------------------------------
*
*
设定行背景色
*----------------------------------------------------------------------*
* -->
I_ROW
行号
*----------------------------------------------------------------------*
FORM row_color USING i_row.
CALL METHOD OF application 'ROWS' =
rows
EXPORTING
#1 =
i_row.
GET PROPERTY OF rows 'Interior' =
font.
SET PROPERTY OF font 'ColorIndex' =
'10'.
ENDFORM. "row_color
*&---------------------------------------------------------------------
*
*& (11) Form preview_excel
*&---------------------------------------------------------------------*
*
预览
excel
*----------------------------------------------------------------------*
FORM preview_excel.
SET PROPERTY OF application 'VISIBLE' =
1.
CALL METHOD OF sheet 'PRINTPREVIEW'.
* m
_message.
ENDFORM. "preview_excel
*&---------------------------------------------------------------------
*
*& (12) Form free_object
*&---------------------------------------------------------------------
*
*
释放
object
*----------------------------------------------------------------------*
FORM free_object.
FREE OBJECT font.
FREE OBJECT range.
FREE OBJECT range1.
FREE OBJECT columns.
FREE OBJECT rows.
FREE OBJECT cell.
FREE OBJECT cell1.
FREE OBJECT sheet1.
FREE OBJECT sheet.
FREE OBJECT workbook.
FREE OBJECT application.
ENDFORM. "free_object
*&---------------------------------------------------------------------
*
*& (13) Form close_excel
*&---------------------------------------------------------------------
*
*
关闭
excel
并保存
*----------------------------------------------------------------------*
FORM close_excel.
CALL METHOD OF workbook 'Save'.
CALL METHOD OF workbook 'Close'
EXPORTING
#1 =
0.
CALL METHOD OF application 'Quit'.
ENDFORM. "close_excel
*&---------------------------------------------------------------------
*
*& (14) Form download_excel_fromserver
*&---------------------------------------------------------------------
*
*
从服务器下载
excel
模板
*----------------------------------------------------------------------*
* -->
P_OBJID
模板名称
* -->
P_DEST
存档路径
*----------------------------------------------------------------------*
FORM download_excel_fromserver
USING p_objid LIKE wwwdatatab-objid
p_dest LIKE sapb-sappfad.
DATA: lo_objdata LIKE wwwdatatab,
lo_m
ime LIKE w3mime,
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
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.
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
CONCATENATE '
模板文件:
' ls_objnam '
不存在,请用
TCODE
:
SMW0
进行加载
' INTO ls_errtxt.
MESSAGE e600(zdev) WIT
H ls_errtxt.
ENDIF.
ls_destination =
p_dest.
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_errt
xt.
MESSAGE e600(zdev) WIT
H ls_errtxt.
ENDIF.
ENDFORM. "download_excel_fromserver
*&---------------------------------------------------------------------*
*& (15) Form open_excel_hide
*&---------------------------------------------------------------------
*
*
后台打开指定的
excel
*----------------------------------------------------------------------*
* -->
P_FILE excel
本地路径
*----------------------------------------------------------------------*
FORM open_excel_hide USING p_file.
SET PROPERTY OF application 'Visible' =
0.
CALL METHOD OF application 'Workbooks' =
workbook.
CALL METHOD OF workbook 'Open' =
workbook
EXPORTING
#1 =
p_file.
CALL METHOD OF workbook 'Worksheets' =
sheet
EXPORTING
#1 =
'Sheet1'.
CALL METHOD OF sheet 'Activate'.
ENDFORM. "open_excel_hide
*&---------------------------------------------------------------------*
*& (16) Form open_excel
*&---------------------------------------------------------------------
*
*
打开指定的
excel
*----------------------------------------------------------------------*
* -->
P_FILE excel
本地路径
*----------------------------------------------------------------------*
FORM open_excel USING p_file.
SET PROPERTY OF application 'Visible' =
1.
CALL METHOD OF application 'Workbooks' =
workbook.
CALL METHOD OF workbook 'Open' =
workbook
EXPORTING
#1 =
p_file.
CALL METHOD OF workbook 'Worksheets' =
sheet
EXPORTING
#1 =
'Sheet1'.
CALL METHOD OF sheet 'Activate'.
ENDFORM. "open_excel
*&---------------------------------------------------------------------* *& (17) Form open_excel_sheet
*&---------------------------------------------------------------------* * 打开指定的excel的sheet
*----------------------------------------------------------------------* * -->P_SHEET 打开的sheet名 * -->P_FILE excel本地路径
*----------------------------------------------------------------------* FORM open_excel_sheet USING p_sheet p_file. SET PROPERTY OF application 'Visible' = 1.
CALL METHOD OF application 'Workbooks' = workbook. CALL METHOD OF workbook 'Open' = workbook EXPORTING #1 = p_file.
CALL METHOD OF workbook 'Worksheets' = sheet EXPORTING #1 = p_sheet.
CALL METHOD OF sheet 'Activate'.
ENDFORM. "open_excel_sheet
*&---------------------------------------------------------------------* *& (18) Form open_excel_by_sheet
*&---------------------------------------------------------------------* * 打开sheet
*----------------------------------------------------------------------* * -->P_SHEET 打开的sheet名
*----------------------------------------------------------------------* FORM open_excel_by_sheet USING p_sheet.
CALL METHOD OF workbook 'WORKSHEETS' = sheet EXPORTING #1 = p_sheet.
CALL METHOD OF sheet 'ACTIVATE'.
ENDFORM. "open_excel_by_sheet
*&---------------------------------------------------------------------* *& (19) Form select_range
*&---------------------------------------------------------------------* * 选择范围
*----------------------------------------------------------------------* * -->P_LEFT 左 * -->P_TOP 上 * -->P_RIGHT 右 * -->P_BUTTOM 下
*----------------------------------------------------------------------* FORM select_range USING p_left TYPE i p_top TYPE i p_right TYPE i p_buttom TYPE i.
CALL METHOD OF application 'CELLS' = cell EXPORTING #1 = p_top #2 = p_left.
CALL METHOD OF application 'CELLS' = cell1 EXPORTING #1 = p_buttom #2 = p_right.
CALL METHOD OF application 'RANGE' = range EXPORTING #1 = cell #2 = cell1.
CALL METHOD OF range 'SELECT'.
ENDFORM. "select_range
*&---------------------------------------------------------------------* *& (20) Form clear_data
*&---------------------------------------------------------------------* * 清除数据
*----------------------------------------------------------------------* * -->P_LEFT 左 * -->P_TOP 上 * -->P_RIGHT 右 * -->P_BUTTOM 下
*----------------------------------------------------------------------* FORM clear_data USING p_left TYPE i p_top TYPE i p_right TYPE i
p_buttom TYPE i.
PERFORM select_range USING p_left
p_top
p_right
p_buttom
.
CALL METHOD OF range 'ClearContents'.
ENDFORM. "clear_data
*&---------------------------------------------------------------------
*
*& (21) Form m
erge_cells
*&---------------------------------------------------------------------
*
*
合并单元格
*----------------------------------------------------------------------*
* -->
P_LEFT text
* -->
P_TOP text
* -->
P_RIGHT text
* -->
P_BUTTOM text
*----------------------------------------------------------------------*
FORM m
erge_cells USING p_left TYPE i
p_top TYPE i
p_right TYPE i
p_buttom TYPE i.
PERFORM select_range USING p_left
p_top
p_right
p_buttom
.
CALL METHOD OF range 'Merge'.
ENDFORM. "m
erge_cells
*&---------------------------------------------------------------------
*
*& (22) Form process_indcator
*&---------------------------------------------------------------------
*
*
进度指示
*----------------------------------------------------------------------*
* -->
TEXT
提示文字
* -->
PERCENTAGE
进度百分比
*----------------------------------------------------------------------*
FORM process_indcator USING text percentage.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage =
percentage
text =
text.
ENDFORM. "process_indcator
*&---------------------------------------------------------------------
*
*& (23) Form delete_row
*&---------------------------------------------------------------------
*
*
删除行
*----------------------------------------------------------------------*
* -->
I_ROW
行号
*----------------------------------------------------------------------*
FORM delete_row USING i_row.
CALL METHOD OF application 'ROWS' =
rows
EXPORTING
#1 =
i_row.
CALL METHOD OF rows 'DELETE'.
ENDFORM. "delete_row
*&---------------------------------------------------------------------
*
*& (24) Form add_comment
*&---------------------------------------------------------------------
*
*
添加注释
*----------------------------------------------------------------------*
* -->
I_ROW
行号
* -->
I_COL
列号
* -->
P_TEXT
注释内容
*----------------------------------------------------------------------*
FORM add_comment USING i_row i_col p_text.
CALL METHOD OF application 'Cells' = cell
EXPORTING
#1 =
i_row
#2 =
i_col.
CALL METHOD OF cell 'AddComment' =
cell1.
CALL METHOD OF cell1 'Text'
EXPORTING
#1 =
p_text.
CALL METHOD OF cell1 'Shape' =
font.
SET PROPERTY OF font 'Width' =
'20'.
SET PROPERTY OF font 'Height' =
'20'.
ENDFORM. "add_comment
*&---------------------------------------------------------
------------*
*&
(
25
)
Form
hide_columns
*&---------------------------------------------------------------------
*
*
隐藏列
*----------------------------------------------------------------------*
* -->
COLNUM
输入列号
*----------------------------------------------------------------------*
FORM hide_columns USING colnum
.
CALL METHOD OF application 'COLUMNS' =
columns
EXPORTING
#1 =
colnum.
SET PROPERTY OF columns 'Hidden' =
'true'.
ENDFORM. "hide_columns
*&---------------------------------------------------------------------
*
*& (26) Form delete_columns
*&---------------------------------------------------------------------
*
*
删除列
*----------------------------------------------------------------------*
* -->
COLNUM
输入列号
*----------------------------------------------------------------------*
FORM delete_columns USING colnum.
CALL METHOD OF application 'COLUMNS' =
columns
EXPORTING
#1 =
colnum.
CALL METHOD OF columns 'DELETE'.
ENDFORM. "delete_columns
*&---------------------------------------------------------------------
*
*&
(
27
)
Form
hide_row
*&---------------------------------------------------------------------
*
*
隐藏行
*----------------------------------------------------------------------*
* -->
I_ROW
输入行号
*----------------------------------------------------------------------*
FORM hide_row USING i_row.
CALL METHOD OF application 'ROWS' =
rows
EXPORTING
#1 =
i_row.
SET PROPERTY OF rows 'Hidden' = 'true'.
ENDFORM. "hide_row
2
注意事项
2.1
Sheet
名称
Sheet
名为中文时,在调用
sheet
对象时往往会调用不到,用英文字母不存在该问题。
2.2
释放对象
程序结束时需要释放对象,否则
Excel
有可能无法关闭。
释放对象代码如下:
FORM free_object.
FREE OBJECT font.
FREE OBJECT range.
FREE OBJECT range1.
FREE OBJECT columns.
FREE OBJECT rows.
FREE OBJECT cell.
FREE OBJECT cell1.
FREE OBJECT sheet1.
FREE OBJECT sheet.
FREE OBJECT workbook.
FREE OBJECT application.
ENDFORM.
OLE-DB 操作excel 基本的更多相关文章
- 使用OLE DB读写Excel
说明: 使用这种技术的好处是无需引用对象,坏处是无法处理类似合并单元格这样的复杂情况 一些更新: 为了使用Office 2010,需要安装Microsoft Access 2010 数据库引擎可再发行 ...
- Delphi中使用OLE方法操作Excel
首先创建 Excel 对象,使用ComObj: var ExcelApp: Variant; ExcelApp := CreateOleObject( ′Excel.Application′ ); 注 ...
- VS2010 C++ 操作Excel表格的编程实现
转载请注明原文网址: http://www.cnblogs.com/xianyunhe/archive/2011/09/25/2190485.html 通过VC实现对Excel表格的操作的方法有多种, ...
- Microsoft OLE DB Provider for SQL Server 错误 '80040e21'
我的是因为数据库满了,正在向服务商申请增加数据库容量 原文地址:Microsoft OLE DB Provider for SQL Server 错误 '800作者:欧阳IT记事本 昨天打开网站还正常 ...
- 微软BI 之SSIS 系列 - 通过 OLE DB 连接访问 Excel 2013 以及对不同 Sheet 页的数据处理
文章更新历史 2014年9月7日 - 加入了部分更新内容,在文章最后提到了关于不同 Office Excel 版本间的连接问题. 开篇介绍 这篇文章主要总结在 SSIS 中访问和处理 Excel 数据 ...
- 使用Win32::OLE操作Excel——Excel对象模型
像VBA操作Excel一样,Win32::OLE模块也是通过对象操作来控制Excel. 如果想自动化操作和控制Excel应用程序,则必须要与Excel对象模型所提供的对象进行交互.理解和熟悉Excel ...
- OLE操作Excel编译错误处理
Excel在公司用的很多,而这个东西我用的不是很好,就想用程序来处理,遇到很多错误.这几天研究了下OLE操作Excel.环境:VS2008 SP1+Excel 2007 加入OLE Type Li ...
- 21. 无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务”
无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务” 原因:调用存储过程的方式有问题,必须用JDBC方式调用存储过程才可以正常 ...
- 无法执行该操作,因为链接服务器 "xxxxx" 的 OLE DB 访问接口 "SQLNCLI" 无法启动分布式事务
在存储过程中使用事务,并且使用链接服务器时,报类似下面的错误 链接服务器"****"的 OLE DB 访问接口 "SQLNCLI10" 返回了消息 " ...
- SSIS 抽取excel出错:所请求的 OLE DB 访问接口 Microsoft.ACE.OLEDB.12.0 尚未注册
如果是安装的office2010就要装这个,如果是2007就不用装! http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b ...
随机推荐
- Eclipse,hadoop2.7.2 hadoop-eclipse-plugin.jar的制作
装好了hadoop后发现有装个eclipse的必要,于是参照文章A(http://www.powerxing.com/hadoop-build-project-using-eclipse/)进行安装, ...
- .net对文件的操作之对文件目录的操作
.NET 提供一个静态File类用于文件的操作,下面列出它的主要操作方法. 返回值类型 方法名称 说明 bool Exists(string path) 用于检查指定文件是否存在 void Copy( ...
- 网页JavaScript2
window.close() 关闭网页, window.opener.close() 关闭打开当前窗口的源窗口 间隔与延迟 window.setlnterval("执行代码&q ...
- C#。3 循环
循环:可以反复执行某段代码,直到不满足循环条件为止. 一.循环的四要素:初始条件.循环条件.状态改变.循环体. 1.初始条件:循环最开始的状态. 2.循环条件:在什么条件下进行循环,不满足此条件,则循 ...
- Function Currying in javascript 的一些注释
理解函数柯里化(Function Currying ),最关键的是理解下面这个函数: function curry(fn){ var args = Array.prototype.slice.call ...
- 【转】C++:MessageBox的常见用法
一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口 ...
- 转载:JAVA中使用JSON进行数据传递
转载网址:http://www.cnblogs.com/undead/archive/2012/07/18/2594900.html 最近在做一个基于JAVA Servlet的WEB应用以及对应的An ...
- Python中*和**的用法
好久不用Python,今天在用Python写个小工具的时候发现好些东西都快忘记了,特别是*和**. 什么情况下使用*和**呢(不是C里面的指针哦!) 当函数的参数不确定时,可以使用*args 和**k ...
- Hibernate学习笔记--Hibernate框架错误集合及解决
错误1:MappingException: Unknown entity解决方案 http://jingyan.baidu.com/article/e75aca8552761b142edac6cf.h ...
- [SQL注入1]From SQL injection to Shell
第一次写,希望大神们多指点. 对于刚接触WEB渗透测试这块的朋友们,很希望能有个平台可以练习.网络上有不少,十大渗透测试演练系统,我这里推荐一个在10以外,适合初学者一步一步进步的平台PENTESTE ...