select certain slide from ppt presentation and paste excel chart(从ppt演示文稿中选择特定幻灯片并粘贴excel图表)
本文介绍了从ppt演示文稿中选择特定幻灯片并粘贴excel图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码打开工作表、复制一个图表、打开演示文稿并粘贴它。
它可以很好地处理一个图表和一张幻灯片,但是在XLSM中有8个图表,所以8张pptx格式的幻灯片,我不知道如何选择第二个图表并将其粘贴到演示文稿的第二张或第三张幻灯片中。
使用PowerPoint.Slide curSlide=pptApp.ActiveWindow.View.Slide;可选择当前幻灯片或幻灯片1。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Core;
using xlNS = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
xlNS.Application excelApplication = null;
xlNS.Workbook excelWorkBook = null;
xlNS.Worksheet targetSheet = null;
xlNS.ChartObjects chartObjects = null;
xlNS.ChartObject existingChartObject = null;
String Excelpath = "C:\Users\Diego\Desktop\Indicador Mensal.xlsm";
excelApplication = new xlNS.Application();//Instancia o excel e abre o XLSM
excelWorkBook = excelApplication.Workbooks.Open(Excelpath,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
PowerPoint.Application pptApp = new PowerPoint.Application();
pptApp.Presentations.Open("C:\Users\Diego\Desktop\Teste.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); //Abre o PPTX
PowerPoint.Slide curSlide = pptApp.ActiveWindow.View.Slide;
xlNS.Worksheet Ws = new xlNS.Worksheet();
Ws = (xlNS.Worksheet)excelWorkBook.Worksheets[1];//Número da Planilha que contém o gráfico
Ws.Activate();
targetSheet = (xlNS.Worksheet)(excelWorkBook.Worksheets["Assumidos no Prazo"]);
chartObjects = (xlNS.ChartObjects)(targetSheet.ChartObjects(Type.Missing));
existingChartObject = (xlNS.ChartObject)(chartObjects.Item(1));
existingChartObject.Copy();
curSlide.Shapes.Paste();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
MessageBox.Show("Finalizado");
}
}
}
}
推荐答案
使用此代码解决了问题:
p = pptApp.ActivePresentation;
slides = p.Slides;
slides[3].Select();
Ppt.Slide slide3 = pptApp.ActiveWindow.View.Slide;
这篇关于从ppt演示文稿中选择特定幻灯片并粘贴excel图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:从ppt演示文稿中选择特定幻灯片并粘贴excel图表


猜你喜欢
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01