Meilleur auteur de réponses
Génération powerpoint avec Graphique en C#

Question
-
Bonjour,
Je souhaite créer un document Powerpoint à partir d'un programme C#.
Mais je rencontre le problème suivant lorsque je créé un graphique et que j'essai de le récuperer pour le modifier.
Je ne comprend pas, si quelqu'un à une idée. Merci d'avance//Create a new PowerPoint application
PowerPoint.
Application ppApp = new PowerPoint.Application();
// Create a new PowerPoint presentation.
PowerPoint.
_Presentation objPres = ppApp.Presentations.Add(MsoTriState.msoTrue);
// Add a slide to the presentation.
PowerPoint.
_Slide objSlide = objPres.Slides.Add (1, PowerPoint.PpSlideLayout.ppLayoutBlank);
//Add a chart to the slide
PowerPoint.
Shape objShape = objSlide.Shapes.AddOLEObject(0, 0, 150, 150, "MSGraph.Chart", "", 0, "", 0, "", 0);
Graph.
Chart objChart;
objChart = (Graph.
Chart)objShape.OLEFormat.Object;
// Save the presentation
objPres.SaveAs(
"C:\\ChartTest.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en type d'interface 'Graph.Chart'. Cette opération a échoué, car l'appel QueryInterface sur le composant COM pour l'interface avec l'IID '{000208FB-0000-0000-C000-000000000046}' a échoué en raison de l'erreur suivante : Cette interface n'est pas prise en charge (Exception de HRESULT : 0x80004002 (E_NOINTERFACE)).
Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en type d'interface 'Graph.Chart'. Cette opération a échoué, car l'appel QueryInterface sur le composant COM pour l'interface avec l'IID '{000208FB-0000-0000-C000-000000000046}' a échoué en raison de l'erreur suivante : Cette interface n'est pas prise en charge (Exception de HRESULT : 0x80004002 (E_NOINTERFACE)).
Réponses
-
Salut Rastanet,
Ce code fonctionne sur mon ordinateur.
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 PowerPoint = Microsoft.Office.Interop.PowerPoint; using Graph = Microsoft.Office.Interop.Graph; using Core = Microsoft.Office.Core; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Create a new PowerPoint application PowerPoint.Application ppApp = new PowerPoint.Application(); // Create a new PowerPoint presentation. PowerPoint.Presentation objPres = ppApp.Presentations.Add(Core.MsoTriState.msoTrue); // Add a slide to the presentation. PowerPoint.Slide objSlide = objPres.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutBlank); //Add a chart to the slide PowerPoint.Shape objShape = objSlide.Shapes.AddOLEObject(0, 0, 150, 150, "MSGraph.Chart", "", 0, "", 0, "", 0); Graph.Chart objChart; objChart = (Microsoft.Office.Interop.Graph.Chart)objShape.OLEFormat.Object; // Save the presentation objPres.SaveAs("C:\\ChartTest.ppt",PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,Core.MsoTriState.msoTrue); objPres.Close(); } } }
Ce pourrait être un problème avec les références?
Tu as ajouté toutes les références en utilisant l'onglet .NET?
Cordialement,
Marius- Proposé comme réponse Gabriel MongeonModerator vendredi 11 septembre 2009 16:55
- Marqué comme réponse Rémy Maillard lundi 14 septembre 2009 07:35
Toutes les réponses
-
Salut Rastanet,
Ce code fonctionne sur mon ordinateur.
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 PowerPoint = Microsoft.Office.Interop.PowerPoint; using Graph = Microsoft.Office.Interop.Graph; using Core = Microsoft.Office.Core; namespace WindowsFormsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //Create a new PowerPoint application PowerPoint.Application ppApp = new PowerPoint.Application(); // Create a new PowerPoint presentation. PowerPoint.Presentation objPres = ppApp.Presentations.Add(Core.MsoTriState.msoTrue); // Add a slide to the presentation. PowerPoint.Slide objSlide = objPres.Slides.Add(1,PowerPoint.PpSlideLayout.ppLayoutBlank); //Add a chart to the slide PowerPoint.Shape objShape = objSlide.Shapes.AddOLEObject(0, 0, 150, 150, "MSGraph.Chart", "", 0, "", 0, "", 0); Graph.Chart objChart; objChart = (Microsoft.Office.Interop.Graph.Chart)objShape.OLEFormat.Object; // Save the presentation objPres.SaveAs("C:\\ChartTest.ppt",PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,Core.MsoTriState.msoTrue); objPres.Close(); } } }
Ce pourrait être un problème avec les références?
Tu as ajouté toutes les références en utilisant l'onglet .NET?
Cordialement,
Marius- Proposé comme réponse Gabriel MongeonModerator vendredi 11 septembre 2009 16:55
- Marqué comme réponse Rémy Maillard lundi 14 septembre 2009 07:35
-
-
Salut Marius,
Je n'avais pas vu ta réponse, je n'ai pas encore essayé ton code.
Je le ferais Lundi.
Pour ce qui est des références, je n'ai pas utilisés les .NET mais les COM pour PowerPoint et Graph.
Peut-être que sa viens de là. je test et je te tien au courant.
En tout cas merci pour ton aide. -
-