Reputation: 81
Suppose in Sheet1 I have a range (from B2:C3), having values [[1, 2], [3, 4]]. Now I want to copy this range to another sheet (Sheet2) starting at D5. That is, In Sheet2 I have a range D5:E6 with values
[[='Sheet1'!B2, ='Sheet1'!B3],
[='Sheet1'!C2, ='Sheet1'!C3]].
How can I Do this in Excel using Office.js
Upvotes: 0
Views: 961
Reputation: 5046
Please use the range.copyFrom API. This API is in Preview, so please make sure to install the latest Office Insiders fast and use our BETA CDN endpoint https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
Here is a script lab snippet that shows how to use it.
Here is some sample code (using TypeScript)
async function run() {
await Excel.run(async (context) => {
context.workbook.worksheets.
getActiveWorksheet().getRange("A5")
.copyFrom("H5:H8", Excel.RangeCopyType.all, true, true);
await context.sync();
});
}
. You can paste, values, formulas, format or all.
Upvotes: 1