如何使用JXA在Numbers(iWork)中建立范围 [英] How to make a range in Numbers (iWork) using JXA

查看:107
本文介绍了如何使用JXA在Numbers(iWork)中建立范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JXA使用Numbers应用程序自动化流程.我需要选择一定范围的单元以应用宽度,但是JXA不允许我获取它们.

I'm using JXA for automating a process using Numbers app. What I need is to select a range of cells to apply width, but JXA doesn't allow me to get them.

根据

According to apple documentation I only need to use make or push the created object inside of array, but any ones work. This is my code and the Automator error:

选项1:

var Numbers = Application('Numbers');
Numbers.Range({name: 'A2:A20'}).make();

// -> Error: Can't make or move that element into that container

选项2:

var Numbers = Application('Numbers');
var myRange = Numbers.Range({name: 'A2:A20'});
Numbers.documents[0].sheets[0].tables[0].ranges.push(myRange);

// -> Error: Can't create object. 

选项3:

var Numbers = Application('Numbers');
var myRange = Numbers.Range({name: 'A2:A20'});
Numbers.documents[0].sheets[0].tables[0].selectionRange = myRange;

// -> Automator close with an unexpected error

根据AppleScript文档(语法与Javascript非常不同),我可以通过分配代表范围的文本来做到这一点:

According to AppleScript documentation (syntax is very different to Javascript) I can do it assigning text that represent the range:

set selection range of table 1 to range "H5:K8"

但是,如果我使用Javascript做类似的事情,那是行不通的:

But if I do something like that with Javascript, it does not work:

选项4:

var Numbers = Application('Numbers');
Numbers.documents[0].sheets[0].tables[0].selectionRange = 'A2:A20'
// -> Error: Can't convert types.

我已经搜索了它,但是没有找到任何对我有帮助的东西(好的参考文献是关于AppleScript的,而一些包含有关JXA的参考文献是关于邮件的.)

I have searched for it, but I have not found anything that help me (good references are about AppleScript and the few references that contain something about JXA are about Mail).

感谢您的帮助(任何与文档的链接或任何尝试的帮助都将不胜感激.)

Thank you for your help (any link with documentation or any ides to try will be appreciate).

推荐答案

此AppleScript:

This AppleScript:

tell application "Numbers"
    tell table 1 of sheet 1 of document 1
        set selection range to range "A2:A20"
    end tell
end tell

实际上是在将表的选择范围设置为名为"A2:A20"的表的范围.

is actually setting the table's selection range to the table's range named "A2:A20".

以下是等效的JavaScript:

Here is the equivalent JavaScript:

var Numbers = Application("Numbers")
var table = Numbers.documents[0].sheets[0].tables[0]

table.selectionRange = table.ranges["A2:A20"]

这篇关于如何使用JXA在Numbers(iWork)中建立范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆