Skip to content

Commit

Permalink
merge/unmerge docs
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim committed Nov 27, 2020
1 parent c19da2b commit a7aabfe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/classes/google-spreadsheet-worksheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,22 @@ Param|Type|Required|Description

-**Side effects** - cache is emptied so props and cells must be re-fetched

#### `mergeCells(range, mergeType)` (async) :id=fn-mergeCells
> merge cells together
Param|Type|Required|Description
---|---|---|---
`range`|[[GridRange](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#GridRange)]|✅|Range of cells to merge, sheetId not required!
`mergeType`|String (enum)<br>[MergeType](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#MergeType|-|defaults to MERGE_ALL

- 🚨 **Warning** - Reading values from merged cells other than the top-left one will show a null value

#### `unmergeCells(range)` (async) :id=fn-unmergeCells
> split merged cells
Param|Type|Required|Description
---|---|---|---
`range`|[[GridRange](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#GridRange)]|✅|Range of cells to unmerge, sheetId not required!

### Updating Sheet Properties

Expand Down
6 changes: 6 additions & 0 deletions lib/GoogleSpreadsheetWorksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ class GoogleSpreadsheetWorksheet {
async mergeCells(range, mergeType = 'MERGE_ALL') {
// Request type = `mergeCells`
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#MergeCellsRequest
if (range.sheetId !== this.sheetId) {
throw new Error('Leave sheet ID blank or set to matching ID of this sheet');
}
await this._makeSingleUpdateRequest('mergeCells', {
mergeType,
range: {
Expand All @@ -568,6 +571,9 @@ class GoogleSpreadsheetWorksheet {
async unmergeCells(range) {
// Request type = `unmergeCells`
// https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UnmergeCellsRequest
if (range.sheetId !== this.sheetId) {
throw new Error('Leave sheet ID blank or set to matching ID of this sheet');
}
await this._makeSingleUpdateRequest('unmergeCells', {
range: {
...range,
Expand Down

0 comments on commit a7aabfe

Please sign in to comment.