Add delete operation to GoogleSheets-Node

This commit is contained in:
Jan Oberhauser
2019-11-30 23:55:22 +01:00
parent 8bf90e6496
commit 2a802256ca
2 changed files with 254 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { IDataObject } from 'n8n-workflow';
import { google } from 'googleapis';
import { google, sheets_v4 } from 'googleapis';
import { JWT } from 'google-auth-library';
import { getAuthenticationClient } from './GoogleApi';
@@ -24,6 +24,18 @@ export interface ILookupValues {
lookupValue: string;
}
export interface IToDeleteRange {
amount: number;
startIndex: number;
sheetId: number;
}
export interface IToDelete {
[key: string]: IToDeleteRange[] | undefined;
columns?: IToDeleteRange[];
rows?: IToDeleteRange[];
}
export type ValueInputOption = 'RAW' | 'USER_ENTERED';
export type ValueRenderOption = 'FORMATTED_VALUE' | 'FORMULA' | 'UNFORMATTED_VALUE';
@@ -85,6 +97,44 @@ export class GoogleSheet {
}
/**
* Returns the sheets in a Spreadsheet
*/
async spreadsheetGetSheets() {
const client = await this.getAuthenticationClient();
const response = await Sheets.spreadsheets.get(
{
auth: client,
spreadsheetId: this.id,
fields: 'sheets.properties'
}
);
return response.data;
}
/**
* Sets values in one or more ranges of a spreadsheet.
*/
async spreadsheetBatchUpdate(requests: sheets_v4.Schema$Request[]) { // tslint:disable-line:no-any
const client = await this.getAuthenticationClient();
const response = await Sheets.spreadsheets.batchUpdate(
{
auth: client,
spreadsheetId: this.id,
requestBody: {
requests,
},
}
);
return response.data;
}
/**
* Sets the cell values
*/