请在这之前安装OFFICE 2007。
PS:第一版程序忘了p.Close(),也就是关闭当前打开的幻灯片,导致最终内存占用达到1.5G,运行速度爆满,超级寒~~~
using
System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace PPT_to_JPEG
{
class Program
{
[STAThread]
static void Main( string [] args)
{
ApplicationClass ac = new ApplicationClass();
string srcRoot;
string dstRoot;
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = " Select root folder " ;
if (fbd.ShowDialog() != DialogResult.OK) return ;
srcRoot = fbd.SelectedPath;
fbd.Description = " Select destination folder " ;
fbd.ShowNewFolderButton = true ;
if (fbd.ShowDialog() != DialogResult.OK) return ;
dstRoot = fbd.SelectedPath;
string [] pptFiles = Directory.GetFiles(srcRoot, " *.ppt " , SearchOption.AllDirectories);
string [] potFiles = Directory.GetFiles(srcRoot, " *.pot " , SearchOption.AllDirectories);
string [] pptxFiles = Directory.GetFiles(srcRoot, " *.pptx " , SearchOption.AllDirectories);
Console.WriteLine( " Find " + (
pptxFiles.GetUpperBound( 0 ) + 1 +
potFiles.GetUpperBound( 0 ) + 1 +
pptxFiles.GetUpperBound( 0 ) + 1 ) + " Files " );
foreach ( string ppt in pptFiles)
{
string dir = ppt.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, dir);
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting PPT File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open(ppt,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
foreach ( string pot in potFiles)
{
string dir = pot.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, dir);
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting POT File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open(pot,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
foreach ( string pptx in pptxFiles)
{
string dir = pptx.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, Path.GetFileName(dir));
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting PPTX File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open2007(pptx,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
Console.WriteLine( " All done, press enter key to exit " );
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace PPT_to_JPEG
{
class Program
{
[STAThread]
static void Main( string [] args)
{
ApplicationClass ac = new ApplicationClass();
string srcRoot;
string dstRoot;
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = " Select root folder " ;
if (fbd.ShowDialog() != DialogResult.OK) return ;
srcRoot = fbd.SelectedPath;
fbd.Description = " Select destination folder " ;
fbd.ShowNewFolderButton = true ;
if (fbd.ShowDialog() != DialogResult.OK) return ;
dstRoot = fbd.SelectedPath;
string [] pptFiles = Directory.GetFiles(srcRoot, " *.ppt " , SearchOption.AllDirectories);
string [] potFiles = Directory.GetFiles(srcRoot, " *.pot " , SearchOption.AllDirectories);
string [] pptxFiles = Directory.GetFiles(srcRoot, " *.pptx " , SearchOption.AllDirectories);
Console.WriteLine( " Find " + (
pptxFiles.GetUpperBound( 0 ) + 1 +
potFiles.GetUpperBound( 0 ) + 1 +
pptxFiles.GetUpperBound( 0 ) + 1 ) + " Files " );
foreach ( string ppt in pptFiles)
{
string dir = ppt.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, dir);
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting PPT File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open(ppt,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
foreach ( string pot in potFiles)
{
string dir = pot.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, dir);
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting POT File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open(pot,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
foreach ( string pptx in pptxFiles)
{
string dir = pptx.Substring(srcRoot.Length + 1 );
string fullDir = Path.Combine(dstRoot, Path.GetFileName(dir));
fullDir = fullDir.Substring( 0 , fullDir.Length - 4 );
Directory.CreateDirectory(fullDir);
Console.WriteLine( " Converting PPTX File ( " + fullDir + " ) " );
Presentation p = ac.Presentations.Open2007(pptx,MsoTriState.msoCTrue,MsoTriState.msoCTrue,MsoTriState.msoFalse,MsoTriState.msoFalse);
p.SaveAs(fullDir, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoCTrue);
p.Close();
}
Console.WriteLine( " All done, press enter key to exit " );
Console.ReadLine();
}
}
}