# google-spreadsheet
> The most popular [Google Sheets API](https://developers.google.com/sheets/api/guides/concepts) wrapper for javascript / typescript
- multiple auth options (via [google-auth-library](https://www.npmjs.com/package/google-auth-library)) - service account, OAuth, API key, ADC, etc
- cell-based API - read, write, bulk-updates, formatting
- row-based API - read, update, delete (based on the old v3 row-based calls)
- managing worksheets - add, remove, resize, update properties (ex: title), duplicate to same or other document
- managing docs - create new doc, delete doc, basic sharing/permissions
- export - download sheet/docs in various formats
- automatic retries with exponential backoff for failed/rate-limited requests (powered by [ky](https://github.com/sindresorhus/ky), [customizable](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet#fn-newGoogleSpreadsheet))
**Docs site -**
Full docs available at [https://theoephraim.github.io/node-google-spreadsheet](https://theoephraim.github.io/node-google-spreadsheet)
---
> **Installation** - `npm i google-spreadsheet`
(or `pnpm`/`yarn`/`bun`/etc...)
## Examples
_The following examples are meant to give you an idea of just some of the things you can do_
> **IMPORTANT NOTE** - To keep the examples concise, I'm calling await [at the top level](https://v8.dev/features/top-level-await) which is not allowed in some older versions of node. If you need to call await in a script at the root level and your environment does not support it, you must instead wrap it in an async function like so:
```javascript
(async function () {
await someAsyncFunction();
})();
```
### The Basics
```
…
```
More info:
- [GoogleSpreadsheet](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet)
- [GoogleSpreadsheetWorksheet](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-worksheet)
- [Authentication](https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication)
### Working with rows
```
…
```
Row methods support explicit TypeScript types for shape of the data
```typescript
type UsersRowData = {
name: string;
email: string;
type?: 'admin' | 'user';
};
const userRows = await sheet.getRows();
userRows[0].get('name'); // <- TS is happy, knows it will be a string
userRows[0].get('badColumn'); // <- will throw a type error
```
More info:
- [GoogleSpreadsheetWorksheet > Working With Rows](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-worksheet#working-with-rows)
- [GoogleSpreadsheetRow](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-row)
### Working with cells
```
…
```
More info:
- [GoogleSpreadsheetWorksheet > Working With Cells](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-worksheet#working-with-cells)
- [GoogleSpreadsheetCell](https://theoephraim.github.io/node-google-spreadsheet/#/classes/google-spreadsheet-cell)
### Managing docs and sharing
```
…
```
## Why?
> **This module provides an intuitive wrapper around Google's API to simplify common interactions**
While Google's v4 sheets API is much easier to use than v3 was, the official [googleapis npm module](https://www.npmjs.com/package/googleapis) is a giant autogenerated meta-tool that handles _every Google product_. The module and the API itself are awkward and the docs are pretty terrible, at least to get started.
**In what situation should you use Google's API directly?**
This module makes trade-offs for simplicity of the interface.
Google's API provides a mechanism to make many requests in parallel, so if speed and efficiency are extremely important to your use case, you may want to use their API directly. There are also many lesser-used features of their API that are not implemented here yet.
## Support & Contributions
This module was written and is actively maintained by [Theo Ephraim](https://theoephraim.com).
**Are you actively using this module for a commercial project? Want to help support it?**
[Buy Theo a beer](https://paypal.me/theoephraim)
### Sponsors
None yet - get in touch!
### Contributing
Contributions are welcome, but please follow the existing conventions, use the linter, add relevant tests, and add relevant documentation.
The docs site is generated using [docsify](https://docsify.js.org). To preview and run locally so you can make edits, run `npm run docs:preview` and head to http://localhost:3000
The content lives in markdown files in the docs folder.
The package manager for this project is `bun`.
## License
This project is released under the MIT license. Previously it was using the "Unlicense". TLDR do whatever you want with it.