Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pasteData and appendDimension #574

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/classes/google-spreadsheet-worksheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ Param|Type|Required|Description
---|---|---|---
`range`|Object<br>[GridRange](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#GridRange)]|✅|Range of cells to unmerge, sheetId not required!

#### `pasteData(coordinate, data, delimiter)` (async) :id=fn-pasteData
> Inserts data into the spreadsheet starting at the specified coordinate.

Param|Type|Required|Description
---|---|---|---
`coordinate`|[[GridCoordinate](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#GridCoordinate)]|✅|The coordinate at which the data should start being inserted, sheetId not required!
`data`|String|✅|The data to insert.
`delimiter`|String|✅|The delimiter in the data.
`type`|String (enum)<br>[PasteType](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#PasteType)|-|How the data should be pasted. _defaults to `PASTE_NORMAL`_

#### `appendDimension(dimension, length)` (async) :id=fn-appendDimension
> Appends rows or columns to the end of a sheet.

Param|Type|Required|Description
---|---|---|---
`dimension`|[[Dimension](https://developers.google.com/sheets/api/reference/rest/v4/Dimension)]|✅|Whether rows or columns should be appended.
`length`|number|✅|The number of rows or columns to append.

### Updating Sheet Properties

#### `updateProperties(props)` (async) :id=fn-updateProperties
Expand Down
19 changes: 17 additions & 2 deletions lib/GoogleSpreadsheetWorksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,19 @@ class GoogleSpreadsheetWorksheet {
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateEmbeddedObjectPositionRequest
}

async pasteData() {
async pasteData(coordinate, data, delimiter, type = "PASTE_NORMAL") {
// Request type = `pasteData`
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#PasteDataRequest
await this._makeSingleUpdateRequest("pasteData", {
coordinate: {
rowIndex: coordinate.rowIndex,
columnIndex: coordinate.columnIndex,
sheetId: this.sheetId,
},
data,
delimiter,
type
});
}

async textToColumns() {
Expand All @@ -717,9 +727,14 @@ class GoogleSpreadsheetWorksheet {
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#DeleteRangeRequest
}

async appendDimension() {
async appendDimension(dimension, length) {
// Request type = `appendDimension`
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AppendDimensionRequest
await this._makeSingleUpdateRequest("appendDimension", {
sheetId: this.sheetId,
dimension,
length,
});
}

async addConditionalFormatRule() {
Expand Down