theoephraim / node-google-spreadsheet

Google Sheets API wrapper for Javascript / Typescript
https://theoephraim.github.io/node-google-spreadsheet
The Unlicense
2.3k stars 389 forks source link

insert row at specific index #615

Open pravinfullstack opened 1 year ago

pravinfullstack commented 1 year ago

I am using insertDimension to insert row on top on my sheet, but unable to comprehend range in the documentation. An example would be appreciated. Thanks This is what I am trying to do

const excel = new GoogleSpreadsheet('17GO6WMRuhdqdVy_vqpBZCkSo5X99eCseTZGJTx3asQnA');
    await excel.useServiceAccountAuth(require('../googlesheet.json'));
    await excel.loadInfo(); // loads document properties and worksheets
    const sheet = excel.sheetsByIndex[0]; // or use doc.sheetsById[id]
    const today = new Date();

    await sheet.insertDimension('ROWS', {
        Name: user.name, 
        Email: user.email
    } , 1, 1)
fuongduyuid commented 1 year ago
await sheet.insertDimension('COLUMNS', {
      startIndex: currentCol,
      endIndex: headers.length,
    });

You can you this. If you want to insert ROWS, just replace 'COLUMNS' by 'ROWS'

theoephraim commented 1 year ago

currently insertDimension just inserts empty rows/columns. There is not functionality to insert a row at a specific index like I can see you are trying to do. This would be possible but would take some work.