在存储过程服务器中输出PDF,CSV,RTF文件

 在存储过程服务器中输出PDF,CSV,RTF文件

   当运行存储过程服务器(Stored Process Server)时,是可以建立pdf,csv,rtf文件输出到WEB浏览器,如下
   
               
             (例子代码来自SAS技术支持网站)
 
       /* Example 1: Create a PDF file for downloading */
 
      *ProcessBody;
 
      data _null_;
      rc = stpsrv_header('Content-type','application/pdf');
      rc =
      stpsrv_header('Content-disposition','attachment; filename=temp.pdf');
      run;
 
      ods listing close;
 
      ods PDF  body=_webout ;
 
      proc print data=sashelp.class;
      run;
 
      ODS PDF  CLOSE;
 
 
     /*************************************************************/
 
 
     /* Example 2: Create a CSV file for downloading  */
 
     *ProcessBody;
 
     data _null_;
     rc = stpsrv_header('Content-type','application/vnd.ms-excel');
     rc =
     stpsrv_header('Content-disposition','attachment; filename=temp.csv');
     run;
 
     ods listing close;
 
     ods CSV  body=_webout ;
 
     proc print data=sashelp.class;
     run;
 
     ODS CSV  CLOSE;
 
 
     /*************************************************************/
 
 
     /* Example 3: Create an RTF file for downloading  */
 
     *ProcessBody;
 
     data _null_;
     rc = stpsrv_header('Content-type','application/vnd.ms-excel');
     rc =
     stpsrv_header('Content-disposition','attachment; filename=temp.rtf');
     run;
 
     ods listing close;
 
     ods RTF  body=_webout ;
 
     proc print data=sashelp.class;
     run;
 
     ods rtf close;
 
     /*************************************************************/
 
     /*  Example 4: Create a PDF file for downloading using    */
     /*            %STPBEGIN and %STPEND                       */
 
   *ProcessBody;
 
   data _null_;
    rc = stpsrv_header('Content-type','application/pdf');
    rc =
     stpsrv_header('Content-disposition','attachment; filename=temp.pdf');
   run;
 
   %let _odsdest=pdf;
 
   %stpbegin;
 
     proc print data=sashelp.class;
     run;
 
   %stpend;

    ----------------------------------
   
    看到上面代码了吧,想想以前要输出一个二进制文件有多枯燥,对比一下,给大家参考一下,输出一个保存在表里的excel文件
        dcl num crc=appsrv_header('Content-type','application/vnd.ms-excel');
        crc=appsrv_header('Content-disposition','attachment;filename=test.xls');
        dcl num fid=fopen('_webout','A',0,'B');    
        dcl num dsid=open('v1');                   
        do while(fetch(dsid)^=-1);                 
        dcl char(256) rec=getvarc(dsid,1);      
        dcl num rc=fput(fid,put(rec,$char256.));
        rc=fwrite(fid);                         
        end;                                       
        dsid=close(dsid);                          
        fid=fclose(fid);                           



简洁之美,一目了然
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值