"1 设置行高 "参数说明:行/列号、行高/列宽、R-行 C-列

FORM row_column  USING   p_r p_width p_type.
CASE p_type.
WHEN 'R'. "行高
CALL METHOD OF gs_excel 'CELLS' = gs_cells EXPORTING # = p_r # = .
GET PROPERTY OF gs_cells 'rows' = gs_rows.
SET PROPERTY OF gs_rows 'rowheight' = p_width.
WHEN 'C'. "列宽
CALL METHOD OF gs_excel 'CELLS' = gs_cells EXPORTING # = # = p_r.
GET PROPERTY OF gs_cells 'columns' = gs_columns .
SET PROPERTY OF gs_columns 'columnwidth' = p_width.
ENDCASE.
FREE OBJECT gs_rows.
FREE OBJECT gs_columns.
FREE OBJECT gs_cells.
ENDFORM. " PRM_EXPORT_EXCEL1

"1 设置列宽

FORM row_column  USING   p_r p_width p_type.
CASE p_type.
WHEN 'R'. "行高
CALL METHOD OF gs_excel 'CELLS' = gs_cells EXPORTING # = p_r # = .
GET PROPERTY OF gs_cells 'rows' = gs_rows.
SET PROPERTY OF gs_rows 'rowheight' = p_width.
WHEN 'C'. "列宽
CALL METHOD OF gs_excel 'CELLS' = gs_cells EXPORTING # = # = p_r.
GET PROPERTY OF gs_cells 'columns' = gs_columns .
SET PROPERTY OF gs_columns 'columnwidth' = p_width.
ENDCASE.
FREE OBJECT gs_rows.
FREE OBJECT gs_columns.
FREE OBJECT gs_cells.
ENDFORM. " PRM_EXPORT_EXCEL1

"设置边框 "第一个单元格X、Y 第二个单元格X、Y、边框(1带边框 0不带)

FORM merged  USING   x1 y1 x2 y2 p_linestyle.
*--Selecting cell area to be merged.
CALL METHOD OF gs_excel 'Cells' = gs_cell1
EXPORTING
# = x1
# = y1.
CALL METHOD OF gs_excel 'Cells' = gs_cell2
EXPORTING
# = x2
# = y2.
CALL METHOD OF gs_excel 'Range' = gs_range
EXPORTING
# = gs_cell1
# = gs_cell2.
CALL METHOD OF gs_range 'Select'.
*--Merging
CALL METHOD OF gs_range 'Merge' . GET PROPERTY OF gs_range 'borders' = gs_borders .
SET PROPERTY OF gs_borders 'weight' = ''.
SET PROPERTY OF gs_borders 'linestyle' = p_linestyle. FREE OBJECT gs_range.
FREE OBJECT gs_borders. ENDFORM. " MERGED
FORM fill_cell_gs  USING p_r1
p_r2
p_bold
p_size
p_linestyle
p_value.
CALL METHOD OF gs_excel 'CELLS' = gs_cells EXPORTING # = p_r1 # = p_r2.
* 设置被选中单元格的对齐方式
" && 水平方向 2左对齐,3居中,4右对齐
SET PROPERTY OF gs_cells 'horizontalAlignment' = .
"&& 垂直方向 1靠上 ,2居中,3靠下
SET PROPERTY OF gs_cells 'VerticalAlignment' = .
"自动换行
SET PROPERTY OF gs_cells 'WrapText' = .
"设置边框属性
GET PROPERTY OF gs_cells 'borders' = gs_borders .
SET PROPERTY OF gs_borders 'weight' = ''.
SET PROPERTY OF gs_borders 'linestyle' = p_linestyle.
"设置字体属性
CALL METHOD OF gs_cells 'FONT' = gs_font.
SET PROPERTY OF gs_font 'BOLD' = p_bold. "1:粗体 0:普通字体
SET PROPERTY OF gs_font 'SIZE' = p_size. "字体大小
"设置单元格的值
SET PROPERTY OF gs_cells 'VALUE' = p_value. FREE OBJECT gs_font.
FREE OBJECT gs_borders.
FREE OBJECT gs_cells. g_c1 = g_c1 + .
ENDFORM.
FORM prm_export_excel1 .
DATA:lv_char TYPE string.
DATA:lv_line TYPE i.
DATA:lv_date TYPE string.
DATA:lv_name() TYPE c.
DATA:lv1 TYPE c,
lv2 TYPE c,
lv3 TYPE c,
lv4 TYPE c.
DATA:lv_lines TYPE i VALUE .
CREATE OBJECT gs_excel 'EXCEL.APPLICATION'.
*设置EXCEL可见
SET PROPERTY OF gs_excel 'Visible' = .
*创建工作表
CALL METHOD OF gs_excel 'Workbooks' = gs_workbook.
DESCRIBE TABLE gt_zsqm00501 LINES lv_line.
* 创建sheet并添加到工作表
SET PROPERTY OF gs_excel 'SHEETSINNEWWORKBOOK' = lv_line. "如需多个sheets,将1改成相应的值
CALL METHOD OF gs_workbook 'ADD'.
*如果是已有EXCEL模板则直接打开即可
* CALL METHOD OF gs_workbook 'OPEN'
* EXPORTING
* #1 = 'C:\test.xls'. "EXCEL文件路径
*选中相应sheet设置名称
LOOP AT gt_zsqm00501 INTO gs_zsqm00501.
* SHIFT GS_ZSQM00501-PRUEFLOS LEFT DELETING LEADING '0'.
CALL METHOD OF gs_excel 'WORKSHEETS' = gs_sheet
EXPORTING
# = lv_lines.
lv_lines = lv_lines + .
CALL METHOD OF gs_sheet 'ACTIVATE'.
SET PROPERTY OF gs_sheet 'NAME' = gs_zsqm00501-prueflos.
FREE OBJECT gs_sheet . "参数说明:行/列号、行高/列宽、R-行 C-列
PERFORM row_column USING: '' 'R', "1 设置行高
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R',
'' 'R'.
PERFORM row_column USING: '' 'C', "1 设置列宽
'' 'C',
'' 'C',
'' 'C',
'' 'C'.
"第一个单元格X、Y 第二个单元格X、Y、边框(1带边框 0不带)
PERFORM merged USING: ,"行1
,"行2
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
. SELECT SINGLE butxt INTO g_butxt
FROM t001
WHERE bukrs = gs_zsqm00501-werk.
"参数说明:单元格X、单元格Y、字体(1粗体 0普通字体)、字体大小、边框(1带边框 0不带)、内容
IF gs_zsqm00501-werk = ''.
PERFORM fill_cell_gs USING: '广州东凌粮油股份有限公司' ,
'Donlinks grain & oil CO.,LTD.'.
lv_name = '黄新哲'.
ELSE.
PERFORM fill_cell_gs USING: '广州植之元油脂实业有限公司',
'Guangzhou Green Oil Industrial Co.,Ltd.'.
lv_name = '文国才'.
ENDIF. CLEAR:lv_char.
CONCATENATE '''' gs_zsqm00501-pastrterm+() '-' gs_zsqm00501-pastrterm+() '-' gs_zsqm00501-pastrterm+() INTO lv_date.
CONCATENATE '质检批号:' gs_zsqm00501-zinslot ' 检验批:' gs_zsqm00501-prueflos
' 制单日期:' sy-datum+() '-' sy-datum+() '-' sy-datum+() INTO lv_char.
CONCATENATE '''' gs_zsqm00501-sghth INTO gs_zsqm00501-sghth.
PERFORM fill_cell_gs USING: "1 1 1 18 0 G_BUTXT ,
'检 验 单',
lv_char,
'物 料 名 称',
gs_zsqm00501-ktextmat,
'采 购 订 单',
gs_zsqm00501-ebeln,
'检 验 日 期',
lv_date,
* 6 2 1 12 1 GS_ZSQM00501-PASTRTERM,
'供 应 商',
gs_zsqm00501-name1,
'抽 样 人',
gs_zsqm00501-uname,
'车/船 号',
gs_zsqm00501-zcarid,
'抽 样 基 数',
gs_zsqm00501-zlosmenge,
'抽样数量',
gs_zsqm00501-zgesstichpr,
'执 行 标 准',
gs_zsqm00501-zstand,
'纸质合同号',
gs_zsqm00501-sghth,
'检 验 项 目',
'检 验 结 果',
'检验依据',
'企 业 标 准',
'单项评价'. g_r1 = .
LOOP AT gt_zsqm00502 INTO gs_zsqm00502 WHERE prueflos = gs_zsqm00501-prueflos.
PERFORM row_column USING: g_r1 '' 'R'. "1 设置行高
PERFORM fill_cell_gs USING:g_r1 gs_zsqm00502-kurztext,
g_r1 gs_zsqm00502-dxjg,
g_r1 gs_zsqm00502-pmethode,
g_r1 gs_zsqm00502-ktx01,
g_r1 gs_zsqm00502-jywb.
g_r1 = g_r1 + .
ENDLOOP.
PERFORM merged USING:g_r1 g_r1 ,
g_r1 g_r1 .
CLEAR:lv_char.
IF gs_zsqm00501-code = 'A'.
lv1 = '√'.
lv_char = '√ 接收 接收,扣款 让步接收 退货'.
* CONCATENATE LV1 '√ 接收 ' LV2 '接收,扣款 'LV3 '让步接收 ' LV4 '退货' INTO LV_CHAR.
ELSEIF gs_zsqm00501-code = 'A0'.
lv2 = '√'.
lv_char = '接收 √ 接收,扣款 让步接收 退货'.
ELSEIF gs_zsqm00501-code = 'A1'.
lv3 = '√'.
lv_char = '接收 接收,扣款 √ 让步接收 退货'.
ELSEIF gs_zsqm00501-code = 'R'.
lv4 = '√'.
lv_char = '接收 接收,扣款 让步接收 √ 退货'.
ENDIF. PERFORM fill_cell_gs USING: g_r1 '处 理 方 式',
g_r1 lv_char. g_r1 = g_r1 + .
PERFORM row_column USING: g_r1 '' 'R'. "1 设置行高
PERFORM fill_cell_gs USING:g_r1 '备注'.
PERFORM merged USING:g_r1 g_r1 ,
g_r1 g_r1 .
PERFORM fill_cell_gs USING:g_r1 gs_zsqm00501-sgtxt. g_r1 = g_r1 + .
PERFORM row_column USING: g_r1 '' 'R'. "1 设置行高
PERFORM merged USING:g_r1 g_r1 .
CLEAR:lv_char.
CONDENSE gs_zsqm00501-usnam NO-GAPS.
CONDENSE lv_name NO-GAPS.
CONDENSE gs_zsqm00501-name_qave NO-GAPS.
CONCATENATE '制单人:' gs_zsqm00501-usnam ' 化验员:' gs_zsqm00501-pruefer"LV_NAME
' 审核人:' gs_zsqm00501-name_qave INTO lv_char.
PERFORM fill_cell_gs USING:g_r1 lv_char. GET PROPERTY OF gs_excel 'ACTIVESHEET' = gs_sheet.
GET PROPERTY OF gs_excel 'ActiveWorkbook' = gs_workbook.
ENDLOOP. CALL METHOD OF gs_workbook 'SAVEAS'
EXPORTING
# = gv_file "保存路径
# = . IF sy-subrc = .
MESSAGE s000 WITH '数据已导出'.
ELSE.
MESSAGE s000 WITH '数据导出失败' DISPLAY LIKE 'E'.
ENDIF.
*
CALL METHOD OF gs_workbook 'CLOSE'.
CALL METHOD OF gs_excel 'QUIT'.
FREE OBJECT gs_sheet.
FREE OBJECT gs_workbook.
FREE OBJECT gs_excel.
ENDFORM. " FRM_EXCEL_BZYJH

OLE填充EXCEL 多SHEET的更多相关文章

  1. OLE填充EXCEL

    先把基本的FORM写好: 1.行列属性 FORM row_column USING p_r p_width p_type. CASE p_type. WHEN 'R'. "行高 = p_r ...

  2. (原创)带模板的OLE输出EXCEL

    其实带模板的OLE输出EXCEL就是将要输出的EXCEL中一些拥有固定值(如标题,表头行等)的单元格先填充好数据和设置好格式后作为模板上传到SAP 中.这样后续在输出EXCEL时只需从SAP中将模板下 ...

  3. OLE操作Excel编译错误处理

      Excel在公司用的很多,而这个东西我用的不是很好,就想用程序来处理,遇到很多错误.这几天研究了下OLE操作Excel.环境:VS2008 SP1+Excel 2007 加入OLE Type Li ...

  4. Easypoi实现excel多sheet表导入导出功能

    Easypoi简化了开发中对文档的导入导出实现,并不像poi那样都要写大段工具类来搞定文档的读写. 第一步引入Easypoi依赖 <!-- 导出文件工具 EasyPoi实现Excel读写管理测试 ...

  5. java的poi技术写Excel的Sheet

    在这之前写过关于java读,写Excel的blog如下: Excel转Html java的poi技术读,写Excel[2003-2007,2010] java的poi技术读取Excel[2003-20 ...

  6. Java读取excel指定sheet中的各行数据,存入二维数组,包括首行,并打印

    1. 读取 //读取excel指定sheet中的各行数据,存入二维数组,包括首行 public static String[][] getSheetData(XSSFSheet sheet) thro ...

  7. 【学习】ABAP OLE 对EXCEL的处理

    原文:http://blog.sina.com.cn/s/blog_7229b9c00100opx2.html -------------------------------------------- ...

  8. 2018年,请不要再使用OLE生成EXCEL文件

    输出EXCEL文件是ABAP开发工作中的常见需求,为了学习相关技术,我翻译过一篇文章:使用OLE2对象创建EXCEL文件,并且一度乐在其中. 最近几个月,经过与若干EXCEL打印程序的艰苦斗争,以及对 ...

  9. C# 填充Excel

    1.添加引用 Microsoft.Office.Interop.Excel; 2.使用命名空间 using Microsoft.Office.Interop.Excel; 3.填充EXCEL单元格方法 ...

随机推荐

  1. Nginx执行php显示no input file specified的处理方法

    /var/www/nginx-default中放上一份phpinfo.php,使用http://localhost/phpinfo.info 访问,结果报错,显示 “No input file spe ...

  2. lua module package.seeall选项

    module 与 package.seeall http://blog.codingnow.com/2006/02/lua_51_module.html 使用 module("test&qu ...

  3. JS中对this的理解

    // this: 指的是调用 当前 方法(函数)的那个对象 <script> function fn1(){ this } 情况1:fn1()                  //这里t ...

  4. SpringMvc异常处理

    SpringMvc通过HandlerExceptionResolver处理程序的异常,包括Handler映射.数据绑定.以及方法执行时发生的异常,SpringMvc提供的HandlerExceptio ...

  5. 谨慎使用多线程中的fork

    // Upon successful completion, pthread_atfork() shall return a value of zero; otherwise, an error nu ...

  6. ReferenceEquals和 == 和equals()的比较

    对于这几点的区别网上经常有各种答案,而且常常会出现答案之间是互相矛盾的.要嘛就是根本含糊的解释不清楚,只是把测试结果扔上来并没有言简意赅的写出他们之间的比较.难道面试的时候考官问你,你也要在纸上写一大 ...

  7. ef第一次启动较慢

    解决ef第一次启动较慢的问题: protected void Application_Start() { //禁用第一次ef查询对表__MigrationHistory的问题使用了ef的Code fi ...

  8. C#学校班级自动升级实现代码

    代码逻辑如下: //班级自动升级 //获取该学校还没有毕业的班级 List<ClassInfoes> classinfoeslist = classinfoesbll.GetList(Sc ...

  9. java mybatis 中sql 模糊查询

    示例: like concat('%',#{groupName},'%') //-------------- <select id="findList" resultType ...

  10. V​S​2​0​1​2​快​捷​键

    VS2012变化的快捷键: 注释::VS2010是(Ctrl+E,C),VS2012是(Ctrl+K, Ctrl+C),实际操作,按住Ctrl键不放,先按K键,再按C键.相当于Ctrl+K加 Ctrl ...