Python 如何以数字形式访问当前表?
如何使用Python 如何以数字形式访问当前表?,python,iwork,sourceforge-appscript,py-appscript,Python,Iwork,Sourceforge Appscript,Py Appscript,如何使用py-appscript以数字形式访问当前表 对于后代,我使用此信息创建的程序将清除当前表中的所有单元格,并将所选内容返回到单元格A1。我使用Automator中的python运行Shell脚本将其转换为服务,并将其附加到数字上 from appscript import * Numbers = app('Numbers') current_table = None for sheet in Numbers.documents.first.sheets(): fo
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'])
它被用来清除我用来临时计算的大数字表
>>> 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()
这实际上对我不起作用。它返回工作表中的第一个表,而不是当前选择的表。具有讽刺意味的是,我自己刚刚得出了这个结论,并准备发布它:)不过,您的解决方案中的语法更清晰。嘿嘿。苹果事件脚本应用程序的奇迹:寻找,你会发现。而且很少有一个明显的方法可以做到这一点。谢谢你的帮助。我还有一个关于appscript的问题,希望你能回答。