The Google script copy function with PASTE_COLUMN_

2019-02-19 13:27发布

问题:

In my Google script I want to extend a range of columns and make their column widths identical to an existing set of columns the manual Sheets command to paste only columns widths works fine but the script:

copyTo(columnRange,SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS)

does not work. It copies values and formats instead of just column widths.

Does anyone have a workaround for this?

回答1:

sheet.getRange('B:B').copyTo(sheet.getRange('C1'),SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS,false);

You also need to specify transposed : the third argument to false (which probably defaults to true).

SYNTAX: copyTo(destination, copyPasteType, transposed)