Silverlight 图表下载到Excel文件中

一、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文件中,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。