我想将数据库中的表导出到服务器上的 excel 文件,然后下载。以下是我为此目的开发的代码:
import flash.net.FileReference;
import flash.net.URLRequest;
public function sqlDownloadExcel():void {
var http:HTTPService = new HTTPService;
var parm:Object = new Object;
var sql:String;
sql = "insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\\inetpub\wwwroot\\myApp\\App_Data\\myExport.xls;', 'SELECT * FROM [Sheet1$]') SELECT * FROM myTable";
parm.sql = sql;
parm.db = "myDatabase";
http.url = "http://mywebsite.com/SQLconnector/sqlconnector.asp?irand="+Math.random();
http.showBusyCursor = true;
http.request = sql;
http.addEventListener(ResultEvent.RESULT, function(e:ResultEvent):void {sqlDownloadExcelResult(e);});
http.addEventListener(FaultEvent.FAULT, mssqlFault);
http.method = "POST";
sqlToken = http.send(parm);
}
public function sqlDownloadExcelResult(event:ResultEvent):void{
var request:URLRequest = new URLRequest("http://mywebsite/myApp/App_Data/myExport.xls");
var fileRef:FileReference = new FileReference();
fileRef.download(request);
}
该代码在服务器上正确创建 Excel 文件,但运行 fileRef.download(request) 函数会导致以下错误:
错误 #2176:某些操作(例如显示弹出窗口的操作)只能在用户交互时调用,例如通过鼠标单击或按钮按下。
任何建议将不胜感激。谢谢