一、Silverlight xaml.cs文件

1、 //下载图表
        private void btnDown_Click(object sender, RoutedEventArgs e)
        {
            DBServiceClient svc = new DBServiceClient();
            svc.ShowPresentationAsync();
            svc.ShowPresentationCompleted += new EventHandler<ShowPresentationCompletedEventArgs>(svc_ShowPresentationCompleted);
        }

2、//下载图表
        private void svc_ShowPresentationCompleted(object sender, ShowPresentationCompletedEventArgs e)
        {
         string strUri = Application.Current.Host.Source.AbsoluteUri.Substring(0, Application.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin")) + "/Temp/" + "Silverlight图表.ppt";
          strUri = "window.location.href='" + strUri + "';";
          System.Windows.Browser.HtmlPage.Window.Eval(strUri);
            //删除Excel临时文件
            DBServiceClient svc = new DBServiceClient();
            svc.DeleteExcelReportAsync();
        }

二、WCF

添加引用

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using System.Runtime.InteropServices;

在所属项目中添加引用,COM选项卡下:

Microsoft.Office.Interop.PowerPoint

Microsoft Excel 12.0 Object Library

Microsoft Graph 12.0 Object Library

Microsoft PowerPoint 12.0 Object Library

Microsoft…………Word文档

添加之后可能会报错:

检索COM 类工厂中CLSID 为{91493442-5A91-11CF-8700-00AA0060263B} 的组件失败,原因是出现以下错误: 80070005 拒绝访问

电脑要进行设置

1:在服务器上安装office的Excel软件.

2:在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务"

3:依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置"

4:在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击右键,然后点击"属性",弹出"Microsoft Excel 应用程序属性"对话框

5:点击"标识"标签,选择"交互式用户"

6:点击"安全"标签,在"启动和激活权限"上点击"自定义",然后点击对应的"编辑"按钮,在弹出的"安全性"对话框中填加一个"NETWORK SERVICE"用户(注意要选择本计算机名),并给它赋予"本地启动"和"本地激活"权限.

7:依然是"安全"标签,在"访问权限"上点击"自定义",然后点击"编辑",在弹出的"安全性"对话框中也填加一个"NETWORK SERVICE"用户,然后赋予"本地访问权限

(6步骤,可以点击“高级”--“查找”进行添加用户,还要添加IIS-……用户,权限也要有“远程…”权限;DCOM配置要对MicrosoftPPt,word,Excel……都要进行配置)

项目引用中会增加:

Microsoft.Office.Core

Microsoft.Office.Interop.PowerPoint

Microsoft.Office.Interop.Excel

Microsoft.Office.Interop.Graph

Microsoft.Office.Interop.Word

所属项目版本号会增加:

<ItemGroup>
    <COMReference Include="Microsoft.Office.Core">
      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
      <VersionMajor>2</VersionMajor>
      <VersionMinor>4</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="Microsoft.Office.Interop.Excel">
      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>6</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="Microsoft.Office.Interop.Graph">
      <Guid>{00020802-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>1</VersionMajor>
      <VersionMinor>6</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="Microsoft.Office.Interop.PowerPoint">
      <Guid>{91493440-5A91-11CF-8700-00AA0060263B}</Guid>
      <VersionMajor>2</VersionMajor>
      <VersionMinor>9</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="Microsoft.Office.Interop.Word">
      <Guid>{00020905-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>8</VersionMajor>
      <VersionMinor>4</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>primary</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
    <COMReference Include="VBIDE">
      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
      <VersionMajor>5</VersionMajor>
      <VersionMinor>3</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>tlbimp</WrapperTool>
      <Isolated>False</Isolated>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>

 WCF代码

[OperationContract]
        private void ShowPresentation()
        {
            String strTemplate, strPic, strExcel;

//静态地址(PPT所需内容,图片,Excel文件,模板)
            strTemplate =   "C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Blends.pot";
            strPic = "C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\QQ.gif";
            strExcel = "C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\股份公司1950-2013年原油产量变化图.xls";

//动态地址     

strExcel = Context.Server.MapPath(Context.Request.ApplicationPath) + "\\Temp\\" + strExcelName;
            strTemplate = Context.Server.MapPath(Context.Request.ApplicationPath) + "\\Temp\\Blends.pot";
            strPic = Context.Server.MapPath(Context.Request.ApplicationPath) + "\\Temp\\QQ.gif";
            //bool bAssistantOn;

PowerPoint.Application objApp;
            PowerPoint.Presentations objPresSet;
            PowerPoint._Presentation objPres;
            PowerPoint.Slides objSlides;
            PowerPoint._Slide objSlide;
            PowerPoint.TextRange objTextRng;
            PowerPoint.Shapes objShapes;
            PowerPoint.Shape objShape;

//PPT播放所需
            //PowerPoint.SlideShowWindows objSSWs;
            //PowerPoint.SlideShowTransition objSST;
            //PowerPoint.SlideShowSettings objSSS;
            //PowerPoint.SlideRange objSldRng;
            //Graph.Chart objChart;

//Create a new presentation based on a template.
            objApp = new PowerPoint.Application();
            objApp.Visible = MsoTriState.msoTrue;
            objPresSet = objApp.Presentations;
            objPres = objPresSet.Open(strTemplate,
                MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            objSlides = objPres.Slides;

//PPT第一页,添加Text文本框,添加图片

objSlide = objSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            objTextRng.Text = "My Sample Presentation";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 48;
            objSlide.Shapes.AddPicture(strPic, MsoTriState.msoFalse, MsoTriState.msoTrue,
                150, 150, 500, 350);

//PPT第二页,添加Text文本框,添加Excel文件

objSlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            objTextRng.Text = "My Chart";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 48;

//给PPT添加对象
            objSlide.Shapes.AddOLEObject(150, 150, 480, 320, "", strExcel, MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);
            //objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320,
            //    "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "",
            //    MsoTriState.msoFalse).OLEFormat.Object;
            //objChart.ChartType = Graph.XlChartType.xl3DPie;
            //objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom;
            //objChart.HasTitle = true;
            //objChart.ChartTitle.Text = "Here it is...";

//PPT第二页,添加结束语

//Change the background color of this slide only. Add a text effect to the slide
            //and apply various color schemes and shadows to the text effect.
            objSlide = objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank);
            objSlide.FollowMasterBackground = MsoTriState.msoFalse;
            objShapes = objSlide.Shapes;
            objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27,
              "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

//PPT自动播放

//Modify the slide show transition settings for all 3 slides in
            //the presentation.
            //int[] SlideIdx = new int[3];
            //for (int i = 0; i < 3; i++) SlideIdx[i] = i + 1;
            //objSldRng = objSlides.Range(SlideIdx);
            //objSST = objSldRng.SlideShowTransition;
            //objSST.AdvanceOnTime = MsoTriState.msoTrue;
            //objSST.AdvanceTime = 3;
            //objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut;

////Prevent Office Assistant from displaying alert messages:
            //bAssistantOn = objApp.Assistant.On;
            //objApp.Assistant.On = false;

////Run the Slide show from slides 1 thru 3.
            //objSSS = objPres.SlideShowSettings;
            //objSSS.StartingSlide = 1;
            //objSSS.EndingSlide = 3;
            //objSSS.Run();

////Wait for the slide show to end.
            //objSSWs = objApp.SlideShowWindows;
            //while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);

////Reenable Office Assisant, if it was on:
            //if (bAssistantOn)
            //{
            //    objApp.Assistant.On = true;
            //    objApp.Assistant.Visible = false;
            //}

//PPT自动播放结束

//保存PPT ,关闭PPT,结束进程

//Close the presentation without saving changes and quit PowerPoint.

//PPT保存静态地址

// objPres.SaveAs("C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\股份公司1950-2013年原油产量变化

//图.xls",PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoFalse);

//PPT保存动态地址

objPres.SaveAs(Context.Server.MapPath(Context.Request.ApplicationPath) + "\\Temp\\Silverlight图表.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoFalse);
            objPres.Save();
            objPres.Close();
            objApp.Quit();
        }

Silverlight visifire Chart图表下载到PPT文件中的更多相关文章

  1. Silverlight 图表下载到Excel文件中

    一.Silverlight xaml.cs文件按钮触发方法 1.//下载图表        private void btnDown_Click(object sender, RoutedEventA ...

  2. 提取PPT文件中的Vba ProjectStg Compressed Atom。Extract PPT VBA Compress Stream

    http://msdn.microsoft.com/en-us/library/cc313106(v=office.12).aspx  微软文档 PartI ********************* ...

  3. scrapy框架来爬取壁纸网站并将图片下载到本地文件中

    首先需要确定要爬取的内容,所以第一步就应该是要确定要爬的字段: 首先去items中确定要爬的内容 class MeizhuoItem(scrapy.Item): # define the fields ...

  4. PPT文件流转为图片,并压缩成ZIP文件输出到指定目录

    实现流程: 接收InputStream流->复制流->InputStream流转为PPT->PPT转为图片->所有图片压缩到一个压缩文件下 注意: 1.PPT文件分为2003和 ...

  5. 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法

    最近客户提出一个需求,就是把页面上的图表导出为pdf文件. 找了很多资料.终于有了点头绪.最主要是参考了HighCharts的做法.http://www.hcharts.cn/ 实现原理:把页面图表的 ...

  6. silverlight visifire控件图表制作——silverlight 后台方法页面事件

    1.返回事件 (1.返回silverlight页面,2.返回web页面) private void button_ClickBack(object sender, RoutedEventArgs e) ...

  7. silverlight visifire控件图表制作——silverlight 后台方法ControlChart.xaml.cs

    一.构造方法ControlChart 1.前台页面控件赋值 //时间下拉框赋值,下拉框赋选定值                for (int ii = DateTime.Today.Year; ii ...

  8. 大咖分享 | 一文解锁首届云创大会干货——下篇(文末附演讲ppt文件免费下载)

    本文承接上一篇:大咖分享 | 一文解锁首届云创大会干货--上篇(文末附演讲ppt文件免费下载),第一届云创大会留下干货太多,这里追加下篇,同样,文末提供大咖们的干货分享,点击附件可免费下载.     ...

  9. 微信小程序云开发-云存储-上传、下载、打开文件文件(word/excel/ppt/pdf)一步到位

    一.wxml文件 <!-- 上传.下载.打开文件一步执行 --> <view class="handle"> <button bindtap=&quo ...

随机推荐

  1. hadoop mapreduce 端参数优化

    在MapReduce执行过程中,特别是Shuffle阶段,尽量使用内存缓冲区存储数据,减少磁盘溢写次数:同时在作业执行过程中增加并行度,都能够显著提高系统性能,这也是配置优化的一个重要依据. 下面分别 ...

  2. Catel帮助手册-Catel.Core(6):日志管理

    1,简介      从2.2版本开始,Catel使用了一个自定义的日志系统,这种方式,针对log4net的引用可以被移除,做这个修改主要是为了不强迫用户使用log4net,同时,log4net看起来很 ...

  3. (原创) jetson tk1 初始化

    1. 相关的网站: 1. Jetson TK1 support   https://developer.nvidia.com/jetson-tk1-support 2.official Wiki fo ...

  4. Jade学习笔记

    初学nodejs,折腾过用handlebars做模板,后来隔了一段重新学习,用了jade,真心简洁……记录一些学习笔记,以备复习. jade是基于缩进的,所以tab与space不能混用: 属性的设置: ...

  5. 在PHP中PDO解决中文乱码问题

    $this->pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true)); $stmt = $th ...

  6. 百度PHP实习一面面试题-算法-二维有序矩阵的查找

    题目描述 有一个二维矩阵,每一行的元素,从左到右保持严格递增,每一列的元素,从上到下保持严格递增.查找给定元素elem,返回NULL或元素位置. 1 3 7 15 16 2 5 8 17 19 3 6 ...

  7. JAVA三大特性之多态

    面向对象的三大特性:封装.继承.多态.从一定角度来看,封装和继承几乎都是为多态而准备的.这是我们最后一个概念,也是最重要的知识点. 多态的定义:指允许不同类的对象对同一消息做出响应.即同一消息可以根据 ...

  8. 树上莫队 wowow

    构建:像线性的莫队那样,依旧是按sqrt(n)为一块分块. int dfs(int x){ ; dfn[x]=++ind; ;i<=;i++) if (bin[i]<=deep[x]) f ...

  9. IEqualityComparer<T>接口

    IEqualityComparer<T>接口的对象的主要作用在于自定义判断两个对象是否相等. 其中最常用的方法: bool Equals(T x, T y); 实现该方法用于比较两个对象是 ...

  10. cxSplitter.HotZone 怎么给分隔条增加值

    请使用它的类名指定HotZoneClassName . cxSplitter1.ResizeUpdate := True; cxSplitter1.HotZoneClassName := 'TcxMe ...