【问题标题】:How to access the current table in Numbers?如何访问 Numbers 中的当前表格?
【发布时间】:2009-11-07 19:01:52
【问题描述】:

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


对于后代,我使用此信息创建的程序会清除当前表的所有单元格并将选择返回到单元格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'])

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

【问题讨论】:

    标签: python iwork sourceforge-appscript py-appscript


    【解决方案1】:
    >>> 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()
    

    【讨论】:

    • 这实际上对我不起作用。它返回工作表中的第一个表,而不是当前选定的表。
    • 具有讽刺意味的是,我只是自己得出了这个结论,并且正要发布它:) 不过,您的解决方案中的语法更简洁。
    • 嘿。 Apple Event 可编写脚本的应用程序的奇迹:寻找,你将找到。而且很少有一种明显的方法可以做到这一点。
    • 感谢您的帮助。我还有一个关于 appscript 的问题,希望您能解答。
    猜你喜欢
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    相关资源
    最近更新 更多