none
Export von Handzetteln aus PPT nach Word automatisieren RRS feed

  • Frage

  • Ich suche eine Möglichkeit den Export von Handzetteln aus Powerpoint 2007 nach Word via VSTO zu automatisieren.
    Mittwoch, 14. Juli 2010 06:29

Antworten

  • Hallo Bigpoint,

    Ich dachte mir, dass erstmals muss man an diese Handzetteln zugreifen und deshalb im folgendem Code werden sie aus einer beibiegen PowerPoint Datei, als Text, extrahiert. Sicher, jetzt bleibt nur noch der Schritt diesen Text in Word einfügen.

    Verweise wurden auf C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll und Microsoft.Office.Core (Microsoft Office 12.0 Object Library) gelegt.

    [Form1.cs]

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;
    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.PowerPoint;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    namespace WindowsFormsApplication1
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
          Microsoft.Office.Interop.PowerPoint.Presentations objPresSet;
          Microsoft.Office.Interop.PowerPoint._Presentation objPres = null;
          Microsoft.Office.Interop.PowerPoint.Slides objSlides;
    
    
          try
          {
            
            objPresSet = PptToTextPresentationApp.PpApp.Presentations;
            objPres = objPresSet.Open("C:\\...\\MeinePowerPointDatei.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);
            objSlides = objPres.Slides;
    
    
            ///*
            // -----------------Notizenseite auslesen-----------------
            // Schleife durch alle Slides
            for (int pos = 1; pos <= objSlides.Count; pos++)
            {
              string notesText = "";
              notesText = notesText + "Slide" + objPres.Slides[pos].SlideIndex + "\n";
              Microsoft.Office.Interop.PowerPoint.Shapes sld = objPres.Slides[pos].NotesPage.Shapes;
    
              // Schleife durch alle Shapes
              foreach (Microsoft.Office.Interop.PowerPoint.Shape s in sld)
              {
                if (s.HasTextFrame == MsoTriState.msoTrue)
                  if (s.TextFrame.HasText == MsoTriState.msoTrue)
                  {
                    notesText = notesText + s.TextFrame.TextRange.Text;
                  }
              }
              notesText = notesText + "\n";
              Debug.WriteLine("NOTES-TEXT: " + notesText);
            }
            //-----------------------------------------------
            //*/
    
            
    
          }
          catch (Exception mye)
          {
            throw new ArgumentException(mye.Message);
          }
          finally
          {
            (objPres as _Presentation).Close();//Close(ref objFalse, ref missing, ref missing);
          }
    
        }
      }
    }
    

    [PptToTextPresentationApp.cs]

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace WindowsFormsApplication1
    {
      public class PptToTextPresentationApp
      {
        private static Microsoft.Office.Interop.PowerPoint.Application ppApp = null;
    
        public static Microsoft.Office.Interop.PowerPoint.Application PpApp
        {
          get
          {
            if (ppApp == null)
              ppApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            return ppApp;
          }
        }
    
        public static void Close()
        {
          (PpApp as Microsoft.Office.Interop.PowerPoint._Application).Quit();
          ppApp = null;
        }
      }
    
    }
    

    Grüße,

    Robert

    Dienstag, 20. Juli 2010 17:10
    Moderator

Alle Antworten

  • Hallo Bigpoint,

    Ich dachte mir, dass erstmals muss man an diese Handzetteln zugreifen und deshalb im folgendem Code werden sie aus einer beibiegen PowerPoint Datei, als Text, extrahiert. Sicher, jetzt bleibt nur noch der Schritt diesen Text in Word einfügen.

    Verweise wurden auf C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.PowerPoint.dll und Microsoft.Office.Core (Microsoft Office 12.0 Object Library) gelegt.

    [Form1.cs]

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;
    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.PowerPoint;
    using System.Windows.Forms;
    using System.Diagnostics;
    
    namespace WindowsFormsApplication1
    {
      public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
          Microsoft.Office.Interop.PowerPoint.Presentations objPresSet;
          Microsoft.Office.Interop.PowerPoint._Presentation objPres = null;
          Microsoft.Office.Interop.PowerPoint.Slides objSlides;
    
    
          try
          {
            
            objPresSet = PptToTextPresentationApp.PpApp.Presentations;
            objPres = objPresSet.Open("C:\\...\\MeinePowerPointDatei.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);
            objSlides = objPres.Slides;
    
    
            ///*
            // -----------------Notizenseite auslesen-----------------
            // Schleife durch alle Slides
            for (int pos = 1; pos <= objSlides.Count; pos++)
            {
              string notesText = "";
              notesText = notesText + "Slide" + objPres.Slides[pos].SlideIndex + "\n";
              Microsoft.Office.Interop.PowerPoint.Shapes sld = objPres.Slides[pos].NotesPage.Shapes;
    
              // Schleife durch alle Shapes
              foreach (Microsoft.Office.Interop.PowerPoint.Shape s in sld)
              {
                if (s.HasTextFrame == MsoTriState.msoTrue)
                  if (s.TextFrame.HasText == MsoTriState.msoTrue)
                  {
                    notesText = notesText + s.TextFrame.TextRange.Text;
                  }
              }
              notesText = notesText + "\n";
              Debug.WriteLine("NOTES-TEXT: " + notesText);
            }
            //-----------------------------------------------
            //*/
    
            
    
          }
          catch (Exception mye)
          {
            throw new ArgumentException(mye.Message);
          }
          finally
          {
            (objPres as _Presentation).Close();//Close(ref objFalse, ref missing, ref missing);
          }
    
        }
      }
    }
    

    [PptToTextPresentationApp.cs]

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace WindowsFormsApplication1
    {
      public class PptToTextPresentationApp
      {
        private static Microsoft.Office.Interop.PowerPoint.Application ppApp = null;
    
        public static Microsoft.Office.Interop.PowerPoint.Application PpApp
        {
          get
          {
            if (ppApp == null)
              ppApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            return ppApp;
          }
        }
    
        public static void Close()
        {
          (PpApp as Microsoft.Office.Interop.PowerPoint._Application).Quit();
          ppApp = null;
        }
      }
    
    }
    

    Grüße,

    Robert

    Dienstag, 20. Juli 2010 17:10
    Moderator
  • Hallo Bigpoint,

    Hat Dir die Antwort geholfen?

    Grüße,
    Robert

    Mittwoch, 21. Juli 2010 15:38
    Moderator