PowerPoint从表格单元格中获取文本

时间:2013-11-27 15:27:42

标签: objective-c scripting powerpoint

我正在尝试使用Objective C中的脚本从PowerPoint幻灯片上的表格单元格中获取文本。

在AppleScript中执行此操作没有问题:

set hasTable to has table of aShape

if hasTable then
   -- if table, get text from first cell
   set numRows to number of rows of aShape
   set numCols to number of columns of aShape

   set aTable to table object of aShape
   set firstCell to first cell of first row of aTable
   set aTextFrame to text frame of shape of firstCell
   set hasText to has text of aTextFrame
   if hasText then
      set theText to content of text range of aTextFrame
   end if
end if

但是,目标C中似乎相同的内容似乎不起作用:

// if table present, get text from first cell
if( shape.hasTable )
{
   PowerPointShapeTable *shapeTable = (PowerPointShapeTable *)shape.get;

   NSLog(@"Shape has %ld x %ld table", shapeTable.numberOfRows, shapeTable.numberOfColumns);

   PowerPointTable *table = shapeTable.tableObject;

   NSLog(@"Table has %ld rows and %ld columns and orientation %u", table.rows.count, table.columns.count, table.tableDirection);

   PowerPointCell *cell = [table getCellFromRow:0 column:0];
   PowerPointShape *cellShape = cell.shape;

   PowerPointTextFrame *textFrame = cellShape.textFrame;
   if( textFrame.hasText )
   {
      NSLog(@"First cell is %@", textFrame.textRange.content);
   }
}

ShapeTable的numberOfRows和numberOfColumns属性返回0(零),Table对象的rows和columns属性的大小为零。关于行和列数组被破坏的可能性我尝试了直接访问方法。这也不起作用。

有人有这个工作吗? 感谢。

OSX 10.9(小牛队), Xcode 5.0.1, Microsoft PowerPoint 2011

0 个答案:

没有答案