Skip to content
This repository was archived by the owner on Nov 4, 2025. It is now read-only.

Commit 482f901

Browse files
committed
[UPDATE]
1. README.md and changelog updated. 2. JSDoc documentation updated.
1 parent 812f703 commit 482f901

2 files changed

Lines changed: 69 additions & 14 deletions

File tree

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,30 @@ Fetch info from one sheet
116116
117117
* @param {String} id Sheets document id
118118
* @param {String} sheetId Worksheet id (use getSheets to fetch them)
119-
* @return {Promise} A promise that resolves to a worksheet info containing id, title, rowCount, colCount and latest update info
119+
* @return {Promise} A promise that resolves to a worksheet info containing id, title, rowCount, colCount
120120
121121
122122
### sheets.getRange(id, sheetId, rangeInfo)
123123
124-
Retrieve cells based on given range
125-
126-
**NOTE:** If there are missing cells (no content) this function adds them there (unlike other functions), thus you'll always have full matrix
127-
124+
Retrieve cells data based on given range
125+
126+
**NOTE:**
127+
* * All below ranges are v4 compatible but full matrix are [SUPPORTED] only for few of them:
128+
*
129+
* - [SUPPORTED] "Sheet1!A1:B2" refers to the first two cells in the top two rows of Sheet1.
130+
* - [SUPPORTED] "A3:" refres to all cells starts from 'A' column and 3rd row.
131+
* - "Sheet1!A:A" refers to all the cells in the first column of Sheet1.
132+
* - "Sheet1!1:2" refers to all the cells in the first two rows of Sheet1.
133+
* - "Sheet1!A5:A" refers to all the cells of the first column of Sheet 1, from row 5 onward.
134+
* - [SUPPORTED]"Sheet1" refers to all the cells in Sheet1.
135+
* - "'My Custom Sheet'!A:A" refers to all the cells in a sheet named "My Custom Sheet."
136+
* Single quotes are required for sheet names with spaces, special characters, or an alphanumeric combination.
137+
*
138+
*
128139
* @param {String} id Sheet document id
129140
* @param {String} sheetId Sheet id
130-
* @param {Mixed} rangeInfo Range info as object or string like `A2:D5` or `A2:`
131-
* @return {Array} Rows containing cells, like `[[{A1}, {B1}], [{A2}, {B2}]]`
141+
* @param {Mixed} rangeInfo Range info
142+
* @return {Array} Rows containing cells
132143
133144
134145
### sheets.getCells(id, sheetId)
@@ -139,8 +150,49 @@ Fetch cell contents from one worksheet
139150
* @param {String} sheetId Worksheet id (use getSheets to fetch them)
140151
* @return {Promise} A promise that resolves to a list of rows
141152
153+
### sheets.getRowAndColCount(data)
154+
155+
Get total count of rows and columns in a data array
156+
157+
* @param {Array} data Title, name of the sheet
158+
* @return {Array<number>} Total count of rows and columns
159+
160+
### sheets.paddedEmptyMatrix(data)
161+
162+
Generate a empty matrix from startRow,startCol
163+
164+
* @param {number} totalRow no of total rows in raw v4 data
165+
* @param {number} totalCol no of total cols in raw v4 data
166+
* @param {number} startRow start row number
167+
* @param {number} startCol start col number
168+
* @return {Array<[{row: number, column: string, content: string}]>} A full empty matrix
169+
170+
### sheets.paddedDataMatrix(data, rangePattern)
171+
172+
Creates a full, padded data matrix
173+
174+
* if the range is like 'A3:' or 'B1:C2' and there are missing
175+
* cells (no content) this function adds them there (unlike other functions),
176+
* thus you'll always have full matrix like B1:C2 -->
177+
* [
178+
[
179+
{ row: 1, column: "B", content: "B1" },
180+
{ row: 1, column: "C", content: "C1" },
181+
],
182+
[
183+
{ row: 2, column: "B", content: "" },
184+
{ row: 2, column: "C", content: "C2" },
185+
],
186+
]
187+
* or in either case it will return raw v4 response like, A:B --> [[A1, B1], ['', B2]]
188+
*
189+
* @param {Array} data Sheet document id
190+
* @param {String} rangePattern Range info
191+
* @return {Array<[]>} A full data matrix
192+
142193
## Changelog
143194

195+
- 1.0.0: Google sheet API migration from v3 to v4
144196
- 0.4.3: Fixed JWT auth issue with recent Google API
145197
- 0.4.2: Updated dependencies / fixed vulnerabilities
146198
- 0.4.1: Fixed the double letter range issue, like: `A1:AA5`

lib/sheets.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Sheets.prototype.getSheets = async function getSheets(docId) {
114114
* Fetch info from one sheet
115115
* @param {String} docId spreadsheet document id
116116
* @param {String} sheetId sheet id (use getSheets to fetch them)
117-
* @return {Promise} A promise that resolves to sheet info containing id, title and latest update info
117+
* @return {Promise} A promise that resolves to sheet info containing id, title, colCount and rowCount
118118
*/
119119
Sheets.prototype.getSheet = async function getSheet(docId, sheetId) {
120120
try {
@@ -202,9 +202,12 @@ Sheets.prototype.getRowAndColCount = (data) => {
202202
}
203203

204204
/**
205-
* Get total count of rows and columns in a data array
206-
* @param {Array} data Title, name of the sheet
207-
* @return {Array<number>} Total count of rows and columns
205+
* Generate a empty matrix from startRow,startCol
206+
* @param {number} totalRow no of total rows in raw v4 data
207+
* @param {number} totalCol no of total cols in raw v4 data
208+
* @param {number} startRow start row number
209+
* @param {number} startCol start col number
210+
* @return {Array<[{row: number, column: string, content: string}]>} A full empty matrix
208211
*/
209212
Sheets.prototype.paddedEmptyMatrix = (totalRow = 0, totalCol = 0, startRow = 1, startCol = 1) => {
210213
return [...Array(totalRow)]
@@ -215,7 +218,7 @@ Sheets.prototype.paddedEmptyMatrix = (totalRow = 0, totalCol = 0, startRow = 1,
215218
}
216219

217220
/**
218-
* Creates a full, padded matrix
221+
* Creates a full, padded data matrix
219222
* if the range is like 'A3:' or 'B1:C2' and there are missing
220223
* cells (no content) this function adds them there (unlike other functions),
221224
* thus you'll always have full matrix like B1:C2 -->
@@ -232,8 +235,8 @@ Sheets.prototype.paddedEmptyMatrix = (totalRow = 0, totalCol = 0, startRow = 1,
232235
* or in either case it will return raw v4 response like, A:B --> [[A1, B1], ['', B2]]
233236
*
234237
* @param {Array} data Sheet document id
235-
* @param {String} rangeInfo Range info
236-
* @return {Array} Rows containing cells
238+
* @param {String} rangePattern Range info
239+
* @return {Array<[]>} A full data matrix
237240
*/
238241
Sheets.prototype.paddedDataMatrix = function (data, rangePattern) {
239242
let noOfCols = 0;

0 commit comments

Comments
 (0)