.net 讀取 Powerpoint 文字

the same, in VS 2005 IDE

?

Add reference: in COM tab, find "Microsoft PowerPoint blahblah"

Example code:

OpenFileDialog openFile = new OpenFileDialog();
openFile.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

if (openFile.ShowDialog() == DialogResult.Cancel)
{
??? return;
}

string fileName = openFile.FileName;
PowerPoint.Application x = new PowerPoint.ApplicationClass();
PowerPoint.Presentation d;

object nothing = System.Reflection.Missing.Value;

d = x.Presentations.Open(fileName, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, Office.MsoTriState.msoFalse);
string str = "";

foreach (PowerPoint.Slide slide in d.Slides)
{
??? foreach (PowerPoint.Shape shape in slide.Shapes)
??? {
??????? try
??????? {
??????????? str = str + " " + shape.TextFrame.TextRange.Text;
??????? }
??????? catch (Exception ex)
??????? {
??????????? //MessageBox.Show(ex.Message);
??????? }
??? }
}

MessageBox.Show(str);

if (d != null)
{
??? d.Close();
??? d = null;
}

if (x != null)
{
??? x.Quit();
??? x = null;
}