在存储过程服务器中输出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);
简洁之美,一目了然
当运行存储过程服务器(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);
简洁之美,一目了然