google-spreadsheet
Advanced tools
Comparing version 3.1.15 to 3.2.0
@@ -36,2 +36,3 @@ // https://eslint.org/docs/user-guide/configuring | ||
}], | ||
'no-multiple-empty-lines': 0, // sometimes helpful to break up sections of code | ||
}, | ||
@@ -38,0 +39,0 @@ overrides: [ |
@@ -302,3 +302,3 @@ const _ = require('lodash'); | ||
const response = await this._makeSingleUpdateRequest('addSheet', { | ||
properties: _.omit(properties, 'headers', 'headerValues'), | ||
properties: _.omit(properties, 'headers', 'headerValues', 'headerRowIndex'), | ||
}); | ||
@@ -310,4 +310,5 @@ // _makeSingleUpdateRequest already adds the sheet | ||
// allow it to work with `.headers` but `.headerValues` is the real prop | ||
if (properties.headerValues || properties.headers) { | ||
await newSheet.setHeaderRow(properties.headerValues || properties.headers); | ||
const headers = properties.headerValues || properties.headers; | ||
if (headers) { | ||
await newSheet.setHeaderRow(headers, properties.headerRowIndex); | ||
} | ||
@@ -314,0 +315,0 @@ |
@@ -205,3 +205,2 @@ const _ = require('lodash'); | ||
return { | ||
@@ -208,0 +207,0 @@ updateCells: { |
@@ -23,2 +23,4 @@ const _ = require('lodash'); | ||
this._headerRowIndex = 1; // assume "header row" (for row-based calls) is in first row | ||
// basic properties | ||
@@ -55,2 +57,3 @@ this._rawProperties = properties; | ||
this.headerValues = null; | ||
this._headerRowIndex = 1; | ||
this._cells = []; | ||
@@ -179,3 +182,2 @@ } | ||
async loadCells(sheetFilters) { | ||
@@ -289,7 +291,7 @@ // load the whole sheet | ||
// ROW BASED FUNCTIONS /////////////////////////////////////////////////////////////////////////// | ||
async loadHeaderRow() { | ||
const rows = await this.getCellsInRange(`A1:${this.lastColumnLetter}1`); | ||
async loadHeaderRow(headerRowIndex) { | ||
if (headerRowIndex !== undefined) this._headerRowIndex = headerRowIndex; | ||
const rows = await this.getCellsInRange(`A${this._headerRowIndex}:${this.lastColumnLetter}${this._headerRowIndex}`); | ||
if (!rows) { | ||
@@ -305,3 +307,3 @@ throw new Error('No values in the header row - fill the first row with header values before trying to interact with rows'); | ||
async setHeaderRow(headerValues) { | ||
async setHeaderRow(headerValues, headerRowIndex) { | ||
if (!headerValues) return; | ||
@@ -318,5 +320,7 @@ if (headerValues.length > this.columnCount) { | ||
if (headerRowIndex) this._headerRowIndex = headerRowIndex; | ||
const response = await this._spreadsheet.axios.request({ | ||
method: 'put', | ||
url: `/values/${this.encodedA1SheetName}!1:1`, | ||
url: `/values/${this.encodedA1SheetName}!${this._headerRowIndex}:${this._headerRowIndex}`, | ||
params: { | ||
@@ -327,3 +331,3 @@ valueInputOption: 'USER_ENTERED', // other option is RAW | ||
data: { | ||
range: `${this.a1SheetName}!1:1`, | ||
range: `${this.a1SheetName}!${this._headerRowIndex}:${this._headerRowIndex}`, | ||
majorDimension: 'ROWS', | ||
@@ -379,3 +383,3 @@ values: [[ | ||
method: 'post', | ||
url: `/values/${this.encodedA1SheetName}!A1:append`, | ||
url: `/values/${this.encodedA1SheetName}!A${this._headerRowIndex}:append`, | ||
params: { | ||
@@ -434,3 +438,3 @@ valueInputOption: options.raw ? 'RAW' : 'USER_ENTERED', | ||
const firstRow = 2 + options.offset; // skip first row AND not zero indexed | ||
const firstRow = 1 + this._headerRowIndex + options.offset; | ||
const lastRow = firstRow + options.limit - 1; // inclusive so we subtract 1 | ||
@@ -644,5 +648,31 @@ const lastColumn = columnToLetter(this.headerValues.length); | ||
async insertDimension() { | ||
async insertDimension(columnsOrRows, range, inheritFromBefore = null) { | ||
// Request type = `insertDimension` | ||
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest | ||
if (!columnsOrRows) throw new Error('You need to specify a dimension. i.e. COLUMNS|ROWS'); | ||
if (!_.isObject(range)) throw new Error('`range` must be an object containing `startIndex` and `endIndex`'); | ||
if (!_.isInteger(range.startIndex) || range.startIndex < 0) throw new Error('range.startIndex must be an integer >=0'); | ||
if (!_.isInteger(range.endIndex) || range.endIndex < 0) throw new Error('range.endIndex must be an integer >=0'); | ||
if (range.endIndex <= range.startIndex) throw new Error('range.endIndex must be greater than range.startIndex'); | ||
// default inheritFromBefore to true - unless inserting in the first row/column | ||
if (inheritFromBefore === null) { | ||
inheritFromBefore = range.startIndex > 0; | ||
} | ||
// do not allow inheritFromBefore if inserting at first row/column | ||
if (inheritFromBefore && range.startIndex === 0) { | ||
throw new Error('Cannot set inheritFromBefore to true if inserting in first row/column'); | ||
} | ||
return this._makeSingleUpdateRequest('insertDimension', { | ||
range: { | ||
sheetId: this.sheetId, | ||
dimension: columnsOrRows, | ||
startIndex: range.startIndex, | ||
endIndex: range.endIndex, | ||
}, | ||
inheritFromBefore, | ||
}); | ||
} | ||
@@ -649,0 +679,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "Google Sheets API (v4) -- simple interface to read/write data and manage sheets", | ||
"version": "3.1.15", | ||
"version": "3.2.0", | ||
"license": "Unlicense", | ||
@@ -30,5 +30,5 @@ "keywords": [ | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"axios": "^0.21.4", | ||
"google-auth-library": "^6.1.3", | ||
"lodash": "^4.17.20" | ||
"lodash": "^4.17.21" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -47,4 +47,6 @@ # google-spreadsheet | ||
// Initialize Auth - see more available options at https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication | ||
// Initialize Auth - see https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication | ||
await doc.useServiceAccountAuth({ | ||
// env var values are copied from service account credentials generated by google | ||
// see "Authentication" section in docs for more info | ||
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL, | ||
@@ -51,0 +53,0 @@ private_key: process.env.GOOGLE_PRIVATE_KEY, |
Sorry, the diff of this file is not supported yet
74933
14
1440
154
Updatedaxios@^0.21.4
Updatedlodash@^4.17.21