ABAP WPS与Microsoft的代码区别
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
WPS office 2007替换Microsoft Office需要对现有开发的修改技术点( 所有采用Microsoft Office的OLE开发代码需要调整到WPS的ETAPI开发代码):
1. 应用程序切换(Microsoft Office --> WPS office 2007)
改语句 CREATE OBJECT EXCEL 'EXCEL.APPLICATION' 为 CREATE OBJECT EXCEL 'ET.APPLICATION'
2. 单元字体设定
改语句 SET PROPERTY OF FONT 'BOLD' = 1 为 SET PROPERTY OF FONT 'FontStyle' = 'Bold'
备注: 斜体/下划线同理 例如修改粗体+斜体字设定
SET PROPERTY OF FONT 'BOLD' = 1
SET PROPERTY OF FONT 'ITALIC' = 1 2句为一句 SET PROPERTY OF FONT 'FontStyle' = 'Bold Italic'
3. 单元格画框 (不采用EXCEL模板填充数据的开发都用到)
左边框 改语句 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '1'
为 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '7'
右边框 改语句 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '2'
为 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '10'
上边框 改语句 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '3'
为 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '8'
下边框 改语句 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '4'
为 CALL METHOD OF CELL 'BORDERS' = BORDERS EXPORTING #1 = '9'
框线格式语句与线条粗细语句合并
改语句 SET PROPERTY OF BORDERS 'LINESTYLE' = 1. "框线格式
SET PROPERTY OF BORDERS 'WEIGHT' = 4. "线粗
为 SET PROPERTY OF BORDERS 'WEIGHT' = 1. (1.2.3......)
4. 单元格合并 (HR大多数用到EXCEL的开发都用到)
改语句 CALL METHOD OF EXCEL 'RANGE' = CELL EXPORTING #1 = 'A1:A10'.
SET PROPERTY OF CELL 'MERGECELLS' = 1. " 合并单元格
为 CALL METHOD OF EXCEL 'RANGE' = CELL EXPORTING #1 = 'A1:A10'.
GET PROPERTY OF RANGE 'MERGE' = T. " T 为I类型或者CHAR类型,目前是固值8,实际任何值都可以
例子:
DATA:TTT TYPE I VALUE 8.
CALL METHOD OF EXCEL'RANGE' = RANGE EXPORTING #1 = 'C4' #2 = 'E5' . "指定单元格位置
SET PROPERTY OF RANGE 'HORIZONTALALIGNMENT' = -4108. " 居中
GET PROPERTY OF RANGE 'MERGE' = TTT. " 合并单元格
SET PROPERTY OF RANGE 'VALUE' = '安徽电力'. "填充值
5. 单元格上载图片 (仅HR一个开发用到)
改语句 CALL METHOD OF EXCEL 'RANGE' = CELL EXPORTING #1 = 'A8'.
CALL METHOD OF CELL 'SELECT' = SELECT.
GET PROPERTY OF SHEET 'PICTURES' = PICTURE.
CALL METHOD OF PICTURE 'INSERT' EXPORTING #1 = 'C:\00000001.JPG'.
为
CALL METHOD OF EXCEL 'RANGE' = CELL EXPORTING #1 = 'A8'.
CALL METHOD OF CELL
'SELECT' = SELECT.
GET PROPERTY OF SHEET 'SHAPES' = PICTURE.
CALL METHOD OF PICTURE 'ADDPICTURE' EXPORTING #1 = 'C:\00000001.JPG' #2 = 0 #3 = 1 #4 = 0 #5 = 0.
GET PROPERTY OF SHEET 'SHAPES' = PICTURE.
GET PROPERTY OF PICTURE 'COUNT' = iCount. " iCount类型I
CALL METHOD OF PICTURE 'ITEM' = myShape EXPORTING #1 = iCount.
SET PROPERTY OF myShape 'LEFT' = 33.
SET PROPERTY OF myShape 'TOP' = 33.
例子: (必须使用新版本的WPS office 2009)
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 3 #2 = 4. "指定单元格位置 C4
CALL METHOD OF CELL 'SELECT' = SELECT.
GET PROPERTY OF SHEET 'SHAPES' = PICTURE.
CALL METHOD OF PICTURE 'ADDPICTURE' EXPORTING #1 = 'C:\00000001.JPG' #2=0 #3=1 #4=0 #5=0.
获取宽度(WIDTH的属性值只有在新版本的WPS office 2009中有)
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 1 #2 = 1. "指定第1行第1个单元格
GET PROPERTY OF CELL 'WIDTH' = mywidth1. "第1行第1个单元格的宽度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 1 #2 = 2. "指定第1行第2个单元格
GET PROPERTY OF CELL 'WIDTH' = mywidth2. "第1行第2个单元格的宽度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 1 #2 = 3. "指定第3个单元格
GET PROPERTY OF CELL 'WIDTH' = mywidth3. "第1行第3个单元格的宽度
获取高度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 1 #2 = 1. "指定第1列第1个单元格位置
GET PROPERTY OF CELL 'ROWHEIGHT' = myHeight1. "第1列第1个单元格的宽度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 2 #2 = 1. "指定第1列第2个单元格位置
GET PROPERTY OF CELL 'ROWHEIGHT' = myHeight2. "第1列第2个单元格的宽度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 3 #2 = 1. "指定第1列第3个单元格位置
GET PROPERTY OF CELL 'ROWHEIGHT' = myHeight3. "第1列第3个单元格的宽度
CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = 4 #2 = 1. "指定第1列第3个单元格位置
GET PROPERTY OF CELL 'ROWHEIGHT' = myHeight4. "第1列第3个单元格的宽度
计算图片移动偏移量
LEFT = mywidth1 + mywidth2 + mywidth3. "从横向第1个到第3个单元格一共的宽度
TOP = myHeight1 + myHeight2 + myHeight3 + myHeight4. "从纵向第1个到第4单元格一共的高度
得到最后一个图形,即插入的图形
GET PROPERTY OF SHEET 'SHAPES' = PICTURE.
GET PROPERTY OF PICTURE 'COUNT' = iCount.
CALL METHOD OF PICTUR
E 'ITEM' = myShape EXPORTING #1 = iCount.
移动图片
SET PROPERTY OF myShape 'LEFT' = LEFT. "赋值
SET PROPERTY OF myShape 'TOP' = TOP. "赋值
备注: 目前仍存在一个技术验证点,因为实际测试代码中,没有后续ET代码(哪怕是错误语句),无法正常移动图片
这个问题已经提交WPS相关人员确认
7. 采用SAP函数SAP_CONVERT_TO_XLS_FORMAT生成EXCEL文件的代码需要更改成用函数GUI_DOWNLOAD生成
改语句
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER = 'X'
I_FILENAME = 'C:\2.xls'
TABLES
I_TAB_SAP_DATA = ITAB.
为
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\2.xls'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = '?'
CODEPAGE = '4103'
WRITE_BOM = 'X'
TABLES
DATA_TAB = ITAB
FIELDNAMES = FIELD.
无需修改的技术点:
1. 创建\打开\保存EXCEL文件
2. 打开\退出\EXCEL
3. 创建\命名\增加sheet(支持多sheet)
4. 单元格大小自适应\单元格颜色设置\单元格内容居中
5. 字体大小\颜色设置
6. 填充SHEET单元格值