2

如何使用 Numbers 访问当前表格py-appscript


对于后代,我使用此信息创建的程序会清除当前表的所有单元格并将选择返回到 cell A1。我在 Automator 中使用 python Run Shell Script 将它变成了一项服务,并将其附加到 Numbers 中。

 from appscript import *

 Numbers = app('Numbers')
 current_table = None
 for sheet in Numbers.documents.first.sheets():
      for table in sheet.tables():
           if table.selection_range():
                current_table = table

 if current_table:
      for cell in current_table.cells():
           cell.value.set('')

      current_table.selection_range.set(to=current_table.ranges[u'A1'])

它用于清除我用于临时计算的大型数字表。

4

1 回答 1

2
>>> d = app('Numbers').documents.first()  # reference to current top document

编辑:似乎没有对当前表的直接单一引用,但看起来您可以通过在当前第一个文档的工作表中搜索具有非空 selection_range 的表来找到它,所以是这样的:

>>> nu = app('Numbers')
>>> for sheet in nu.documents.first.sheets():
...   for table in sheet.tables():
...     if table.selection_range():
...        print table.name()
于 2009-11-07T19:23:32.883 回答