简体   繁体   English

使用Office-JS链接读写

[英]Chaining Read-Writes with Office-JS

I am having a problem working out how to chain syncs in Office JS - I think I have to do one sync to read the values then another sync to write them back - must be simple but I can't find a chaining example. 我在解决如何在Office JS中链接同步时遇到问题-我想我必须先进行一次同步才能读取值,然后进行另一次同步才能将其写回-必须很简单,但我找不到链接示例。

Basically I am trying to code the equivalent of this VBA code which does a read and a write via an array 基本上,我正在尝试编写与此VBA代码等效的代码,该代码通过数组进行读取和写入

Application.ScreenUpdating = False
d1 = MicroTimer
Set rng1 = Worksheets("Sheet1").Range("A1:A1000")
Set rng2 = Worksheets("Sheet1").Range("D1:D1000")
var = rng1.Value2
rng2.Value2 = var
d2 = (MicroTimer - d1) * 1000

MsgBox d2

or even simpler 甚至更简单

Worksheets("Sheet1").Range("D1:D1000").Value2=Worksheets("Sheet1").Range("A1:A1000").Value2

To copy the values from one range to another, you can use the following code: 要将值从一个范围复制到另一个范围,可以使用以下代码:

Excel.run(function(context) {
    var range1 = context.workbook.worksheets.getItem("Sheet1").getRange("A1:A1000").load('values');
    return context.sync()
        .then(() => {
            var range2 = context.workbook.worksheets.getItem("Sheet1").getRange("D1:D1000");
            range2.values = range1.values;
            return context.sync();
        });
});

You can use the Range-Class OfficeJS gives you. 您可以使用Range-Class OfficeJS给您。 Here is the full doc: https://dev.office.com/reference/add-ins/excel/range (Also have a look at the examples given there) 这是完整的文档: https : //dev.office.com/reference/add-ins/excel/range (也可以查看此处给出的示例)

To copy the Range, you need to create both ranges and copy the .values[][] from the source to the dest. 要复制范围,您需要创建两个范围并将.values[][]从源复制到dest。

For how to copy a two-dimensional array (in this case: values[][] ), you should use google. 有关如何复制二维数组(在本例中为values[][] ),则应使用google。

To Determine the time, you can use the Date() -Class Java gives you. 要确定时间,可以使用Date() -Java Java给您提供。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM