Insert cell into google spreadsheet using Google Apps script

I am working on a Google spreadsheet. I want to know if there is a way to insert a cell into a spreadsheet using a script application.

Example: suppose there is some data from A2 to Y2.

I want to insert cell A2 with some data. So now there will be data from A2 to Z2.

+4
source share
6 answers

I got my answer, there is no way to insert a cell.

+4
source

I don't think there is a way to insert a cell left / right in a cell. If your cells and address are not dynamic, you can do the following

  • Get content in the range A2-Y2 and put in an array
  • 0,
  • 2. A2-Z2.
//Get A2-Y2 in a cellFeed

    URL cellFeedUrl1 = new URI(worksheets.get(WSID).getCellFeedUrl() +"?min-row=2&max-row=2&min-col=1&max-col=1").toURL();
    CellFeed cellFeed1 = googleservice.getFeed(cellFeedUrl1, CellFeed.class);

//store in an Array

       for (CellEntry cell : cellFeed1.getEntries()) 
    {   Array_A2Y2.add(cell.getPlainTextContent());     }

//Add your desired cell Value on the first of that array

//Insert the Array items on the your required row
0

, move :

  • A2: Y2 B2: Z2.
  • A2.

:

function insertCell() {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.getRange("A2:Y2").moveTo(sheet.getRange("B2"));
  sheet.getRange("A2").setValue("New");
}
0

, google, . / /, , / /.

-1

, Class Sheet, GetRange.

:

 mysheet.getRange(1,5,nbrows+BNrows-1,5).setValues(myArray); // my Array concern a column
-1

I was interested in moving the data block down to create a new (empty) row at the top of the table. Knowing that the data in my top row looked in cell A7, and the last column in my table is column H, I only move the columns of the table, leaving the rest of my table where it is.

 function addNewRow() {
     var sheet = SpreadsheetApp.getActiveSpreadsheet();
     sheet.getRange("A7:H1000").moveTo(sheet.getRange("A8"));  
 }
-2
source

Source: https://habr.com/ru/post/1539243/


All Articles