2012年3月1日 星期四

Convert Powerpoint to images

1. Add reference

// Add Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
// Add Microsoft Office 14.0 Object Library (@COM)
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
2. Prepare myppt.pptx in debug or release folder
3. ConsoleMode program (Open vs2010 by administrator role)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Add Micorsoft.Office.Iterop.PowerPoint v 14.0.0.0
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ApplicationClass ppt = new ApplicationClass();
            Presentation pptPresentation = ppt.Presentations.Open(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            for (int i = 1; i <= pptPresentation.Slides.Count ; i++)
            {
                pptPresentation.Slides[i].Export(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\slide" + i.ToString() + ".jpg", "jpg", 320, 240);
            }
           
        }
    }
}

4. Change both of  properties in
    Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
    Microsoft Office 14.0 Object Library (@COM)
    Embed Interop Type -> False


5. Note: 1. The default directory of Slides[].Export is My Document
              2. It seems not to work without excuted by administrator role.


沒有留言:

張貼留言