How to copy data from one column to another column using Office Scripts?

289 views Asked by At

I'm currently working on automating some tasks in Microsoft Excel using Office Scripts, and I'm having trouble figuring out how to copy data from one column to another.

enter image description here

I want to copy Date column(D) data to New_Date column(F).

Any help or code snippets would be greatly appreciated. Thank you!

1

There are 1 answers

0
taller On BEST ANSWER

Below code copy Col Date to Col NewDate.

function main(workbook: ExcelScript.Workbook) {
    // modify table name as needed
    let table1 = workbook.getTable("Table1"); 
    let srcRange = table1.getColumn("Date").getRangeBetweenHeaderAndTotal();
    let targetCell = table1.getColumn("New_Date").getRangeBetweenHeaderAndTotal().getRow(0);
    targetCell.copyFrom(srcRange, ExcelScript.RangeCopyType.all, false, false);
}