日期:2014-01-26 浏览次数:20883 次
public string ExportReport()
{
ExportOptions creo = new ExportOptions();
DiskFileDestinationOptions crdo = new DiskFileDestinationOptions();
string FileName = Request.PhysicalApplicationPath + "ExportFile\Exap.xls";
//设置导出选项
creo = Myrpt.ExportOptions;
creo.ExportFormatType = ExportFormatType.Excel;
creo.ExportDestinationType = ExportDestinationType.DiskFile;
//设置磁盘文件选项
crdo.DiskFileName = FileName;
creo.DestinationOptions = crdo;
//导出报表
MyRpt.Export();
return FileName;
}
private void buttonExport_Click(object sender, System.EventArgs e)
{
string FileName = ExportReport();
Response.Redirect(Replace(FileName,Request.PhysicalApplicationPath + "ExportFile\",""));
}
要注意的是:当在web中进行导出时,需要对导出目录具有建立文件的权限,如果权限不足,将会出现“拒绝访问报表文件……”的错误。 让ASPNET用户(安装.NET Framework时自动生成的系统用户)在导出目录文具有“写入”权限即可。