Home » excel » office js – I want to replace particular columns data in a excel table

office js – I want to replace particular columns data in a excel table

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am working on office.js using jquery in Visual Studio 2015

enter image description here

I want to replace only some of the column data with new data in table and i don’t want to change other columns.

Can i do that?

How to&Answers:

You just need to get a Range object reference to the range you want to change and assign a two-dimensional array of values to it. If the position of the table is hardcoded, you can get the Range object you need with an explicit address like this:

var myRange = worksheet.getRange("A2:D9");

If you won’t know the table’s position at coding-time, another way to do it is to get the table’s data range and then cut off the rightmost column.

var myRange = myTable.getDataBodyRange().getResizedRange(0,-1);

Either way, you set the myRange.values property to an a two-dimensional array of the new values:

myRange.values = [ 
[30/06/2018, "Test11", 6000.31, 18/06/2016],

 … // and so on for all the rows
]