首页 > Web开发 > 详细

Silverlight 图表下载到Excel文件中

时间:2014-07-23 15:18:06      阅读:386      评论:0      收藏:0      [点我收藏+]

一、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

Silverlight 图表下载到Excel文件中

原文:http://www.cnblogs.com/xuxin-1989/p/3862927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!