我正在尝试提取PowerPoint文件每张幻灯片中的所有文本。由于某种原因,我只得到一些文本,而不是全部。我在幻灯片中循环浏览所有形状,并检查文本框和表格。但是一些带有文本的幻灯片将无法打印任何内容。
代码
foreach (PowerPoint.Slide _slide in pptPresentation.Slides) {
foreach(PowerPoint.Shape _shape in _slide.Shapes) {
//check for textframes
if (_shape.HasTextFrame == MsoTriState.msoTrue) {
var textFrame = _shape.TextFrame;
if (textFrame.HasText == MsoTriState.msoTrue) {
var textRange = textFrame.TextRange;
PrintAllParagraphs(textRange);
}
}
//check for tables
if(_shape.HasTable == MsoTriState.msoTrue) {
var slideTable = _shape.Table;
int rowCount = slideTable.Rows.Count;
int colCount = slideTable.Columns.Count;
for(int y = 1; y <= rowCount; y++) {
for(int x = 1; x <= colCount; x++) {
var tRange = slideTable.Cell(y, x).Shape.TextFrame.TextRange;
PrintAllParagraphs(tRange);
}
}
}
} //loop shapes
} //loop slides
打印功能
public void PrintAllParagraphs(PowerPoint.TextRange textRange) {
for (int i = 1; i <= textRange.Paragraphs().Count; i++) {
PowerPoint.BulletFormat bulletFormat = textRange.Paragraphs(i).ParagraphFormat.Bullet;
Console.WriteLine( (bulletFormat.Type == PowerPoint.PpBulletType.ppBulletNone) ? textRange.Paragraphs(i).Text.ToString() : "* " + textRange.Paragraphs(i).Text.ToString());
}
}
在幻灯片的形状内,我还应该检查其他事项吗?任何帮助,将不胜感激。谢谢。