office-js API - 获取特定工作表的范围 [英] office-js API - Get ranges of specific sheets

查看:68
本文介绍了office-js API - 获取特定工作表的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel文档的表格是一周中的几天(周日 - 周五) - 需要迭代。

我的问题是:怎么样?



我的代码尝试(全部导致失败):

The Excel document's sheets are the days of the week (Sunday-Friday) - which need to be iterated over.
My question is: How?

My code attempts (which all resulted as a failure):

Excel.run(function(context) {
    const currentSheets = context.workbook.worksheets;
    const worksheetDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    for (let i = 0; i < worksheetDays.length; i++) {
        sheetRanges[worksheetDays[i]] = currentSheets.load("values");
    }
    return context.sync().then(function() {
        console.log(sheetRanges.Sunday.values); // null
    });
});

下一次尝试:

Excel.run(function(context) {
    const worksheetDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    const sheetRanges = {};
    const currentSheets = context.workbook.worksheets;
    for (let i = 0; i < worksheetDays.length; i++) {
         sheetRanges[worksheetDays[i]] = currentSheets.getItem(worksheetDays[i]).load("values");
    }
    return context.sync().then(function() {
        console.log(sheetRanges.Sunday.values); // null
    });
});

下一页:

Excel.run(function(context) {
    const worksheetDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    const sheetRanges = {};
    const currentSheets = context.workbook.worksheets;
    for (let i = 0; i < worksheetDays.length; i++) {
         sheetRanges[worksheetDays[i]] = currentSheets.getItem(worksheetDays[i]).getRange().load("values");
    }
    return context.sync().then(function() {
        console.log(sheetRanges.Sunday.values); // null
    });
});

下一页:

Excel.run(function(context) {
    const worksheetDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    var sheetRanges = {};
    const currentSheets = context.workbook.worksheets;
    for (let i = 0; i < worksheetDays.length; i++) {
        sheetRanges[worksheetDays[i]] = currentSheets.load("name");
    }
})
.then(context.sync)
.then(function () {
     for (let i = 0; i < worksheetDays.length; i++) {
        sheetRanges[worksheetDays] = sheetRanges[worksheetDays].load("values");
    }
}).then(function () {
    console.log(sheetRanges.Sunday.values); // null
});



基本上,我迷路了。我只需要获取所有工作表的单元格值。

如何解决这个问题?

Basically, I'm lost. I just need to get the cell values of all sheets.
How to solve this?


谢谢!

推荐答案


avi12641

尝试使用get cell或get range方法来获取值。

try to use get cell or get range method to fetch the values.

参考下面的例子。

object[] rangeResults = xlservice.GetRangeA1(sessionId, "Sheet1", "B2:D3", true, out outStatus);
foreach (object[] rangeResult in rangeResults)
{
    Console.WriteLine(String.Format("{0} | {1} | {2}", 
        rangeResult[0], rangeResult[1], rangeResult[2]));
}




' Call the GetCell method to retrieve a value from a cell.
' The cell is in the first row and first column; that is, cell A1
Dim rangeResult2() As Object = xlservice.GetCell(sessionId, sheetName, 0, 0, True, outStatus)

参考:

如何:获取价值来自Ranges

另外,我记得你之前的帖子,下面的帖子有什么问题吗?如果没有,我建议你将有用的回复标记为回答
这是关闭线程的方法。

In addition, I remember your previous thread below, is there any issue with below thread? If not, I would suggest you mark the helpful reply as answer which is the way to close the thread here.

Excel JavaScript加载项 - 获取最后编辑的单元格

Excel JavaScript add-in - Get last edited cell

https://social.msdn.microsoft.com/Forums/office/en-US/78ea4998-19e6-4a04-8124-3651ffce2a91/excel-javascript-addin-get -last-edited-cell?forum = exceldev

问候

Deepak


这篇关于office-js API - 获取特定工作表的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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