在网上找到的一段代码,经测试可以使用,不过需要已经安装了office的ppt软件。
下面吧代码拿出来和大家分享:
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace testPPTtoJPG
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace testPPTtoJPG
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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();
}
}
}