blah blah

Automating Powerpoint with C#

며칠전 올렸던 Ruby 소스의 C# 버전.
역시나 온라인에서 기본 샘플 찾아서 살짝 수정한건데 Office Primary Interop Assembly 참조하는 법 때문에 그래도 꽤 고생했다 ^^;

using System; using System.IO; using System.Text.RegularExpressions; using Microsoft.Office.Core; using Microsoft.Office.Interop.PowerPoint; namespace ExtractImage { class Program { [STAThread] static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: {0} powerpoint.ppt", System.Windows.Forms.Application.ExecutablePath); return; } string fileName = args[0]; FileInfo info = new FileInfo(fileName); ExtractImage(info.FullName); } static void ExtractImage(string fileName) { ApplicationClass app = new ApplicationClass(); Presentation ppt = app.Presentations.Open(fileName, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); Regex re = new Regex(@".ppt$", RegexOptions.IgnoreCase); string imgFile = re.Replace(fileName, ""); for (int i = 0; i < ppt.Slides.Count; ++i) { ppt.Slides[i + 1].Export(imgFile + i + ".png", "PNG", 960, 720); } ppt.Close(); app.Quit(); } } }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s