关于使用SAP的BSP在后台导出excel(xml格式),并在web上弹出的方法

来源:互联网 发布:小猪cms收银系统源码 编辑:程序博客网 时间:2024/05/17 21:58

首先你的机器必须装了excel2003或以上 否则xml格式的数据读不出来 2000是肯定不行的


步骤如下:


先把你的excel模板准备好.然后选择另存为xml表格格式.


用写字板打开这个xml  仔细观察这段xml

前面描述部分不用管 注意数据部分 这就是你loop内表的时候要操作的部分


一行数据从<row>开始 到<row/>结束


接下来 在bsp的ini事件里创一个string变量 

先把前面描述部分放进去 

然后loop你要显示出来的内表 加上xml的代码 拼到string里

最后再把xml的结尾部分拼进去



 

call function 'SCMS_STRING_TO_XSTRING'

 把它转成xstring 即二进制流


最后写response.


 

response->set_header_field( name  = 'cache-control'

                   value = 'max-age=0' ).

response->set_header_field( name  = 'content-type'

                            value = 'text/html; charset=utf-8' ).

data : aa type string .

concatenate 'attachment; filename= ' test.xls'  into aa .

response->set_header_field( name  = 'content-disposition' value = aa ).

l_xlength = xstrlen( val_xstring ).

response->set_data( data =  val_xstring  length = l_xlength ).

navigation->response_complete( ).

 


此段代码运行完毕 web页面上就会弹出让你保存或打开文件的对话框.