一、Silverlight xaml.cs文件按钮触发方法
1、//下载图表
private void btnDown_Click(object sender, RoutedEventArgs e)
{
DBServiceClient svc = new DBServiceClient();
svc.GenerateExcelReportAsync();
svc.GenerateExcelReportCompleted += new EventHandler<GenerateExcelReportCompletedEventArgs>(svc_GenerateExcelReportCompleted);
}
2、//委托 在本地弹出下载提示框 并删除服务器上的Excel文件
private void svc_GenerateExcelReportCompleted(object sender, GenerateExcelReportCompletedEventArgs e)
{
string strExcelName = e.Result;
string strUri = Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin")) + "/Temp/" + strExcelName;
strUri = "window.location.href=‘" + strUri + "‘;";
System.Windows.Browser.HtmlPage.Window.Eval(strUri);//本地弹出下载提示框
//删除Excel临时文件
DBServiceClient svc = new DBServiceClient();
svc.DeleteExcelReportAsync();
}
二、wcf
1、 //下载图表
[OperationContract]
[ServiceKnownType(typeof(ListItem))]
public string GenerateExcelReport()
{
string strTemplatePath = "ReportMgt\\Template\\SilverlightChart\\" + strAppCode;
string strExcelVisualPath = string.Format("/{0}/{1}.xls", strTemplatePath, strChartExcelName);//Excel模板地址
strExcelVisualPath = Context.Request.ApplicationPath + strExcelVisualPath;
DataSet ds = new DataSet();
ds = dtChart.DataSet;
string strExcelChartPath = new CreateExcelChart().Create(strExcelVisualPath, ds, strTitleChart, "", "");//下载报表到指定地址(Temp文件夹下)
strExcelName = string.Format("{0}.xls", strTitleChart);
return strExcelName;
}
2、//删除服务器上的图表
[OperationContract]
[ServiceKnownType(typeof(ListItem))]
public void DeleteExcelReport()
{
//检查目录是否存在(根据虚拟地址转换成物理地址)
string path = Context.Server.MapPath(Context.Request.ApplicationPath) + "\\Temp\\" + strExcelName;
//File.Exists("D:\\iirs2010new\\sln\\BS.EAP.Portal\\Temp/XXXXXx产量变化图.xls")
if (File.Exists(path))
{
File.Delete(path);
}
}
Silverlight 图表下载到Excel文件中,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/xuxin-1989/p/3862927.html