如何以数字形式访问当前表?

2024-04-20 01:29:59 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用py-appscript访问当前的数字表


对于后代,我使用此信息创建的程序将清除当前表中的所有单元格,并将所选内容返回到单元格A1。我使用Automator中的python运行Shell脚本将其转换为服务,并将其附加到数字上

 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'])

它被用来清除我用来临时计算的大数字表


Tags: inpyforifa1tablecellrange
1条回答
网友
1楼 · 发布于 2024-04-20 01:29:59
>>> d = app('Numbers').documents.first()  # reference to current top document

编辑:似乎没有对当前表的直接引用,但您似乎可以通过搜索当前第一个文档的工作表来查找具有非空选择范围的表,例如:

>>> nu = app('Numbers')
>>> for sheet in nu.documents.first.sheets():
...   for table in sheet.tables():
...     if table.selection_range():
...        print table.name()

相关问题 更多 >