Home > Software engineering >  Copy everything from one column to another in Apps Script
Copy everything from one column to another in Apps Script

Time:08-19

I'm trying to programmatically copy everything (data, cells borders, format (%), color) from one set of columns to another.

function myFunction(){
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const sheet = sheet.getSheets()[1];
    const range = sheet.getRange('A1:C5').getValues();
    const newrange = sheet.getRange('D1:F5');

    sheet.insertColumnsAfter(3,3);    
    newrange.setValues(range);
    [...]

Here the data as well as the color are copied correctly to the new location. However, I could not figure out how to replicate:

  • The cell border lines (to draw a table)
  • The format of my cells in percentage (including the sign %).

I've tried the following for the percentage - but did not worked:

const percentageRange = sheet.getRange('A1:C5');
percentageRange.setNumberFormat('00.00"%"');

Not sure how should I do for the border

CodePudding user response:

Try this:

range.copyTo(newrange); 

this will copy range completely.

Reference: https://stackoverflow.com/a/44967382/555121

  • Related