我正在尝试提取 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());
}
}
我还应该在幻灯片的形状内检查其他东西吗?任何帮助,将不胜感激。谢谢。