Skip to content

Commit

Permalink
docs: docs cleanup and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Ephraim committed Jun 29, 2023
1 parent c306dc0 commit 882bd73
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _the following examples are meant to give you an idea of just some of the things
### The Basics
```js
import { GoogleSpreadsheet } from 'google-spreadsheet';
import { JWT } from 'google-auth-library'
import { JWT } from 'google-auth-library';


// Initialize auth - see https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication
Expand Down
14 changes: 7 additions & 7 deletions docs/classes/google-spreadsheet-worksheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ You do not initialize worksheets directly. Instead you can load the sheets from

```javascript
const doc = new GoogleSpreadsheet('<YOUR-DOC-ID>', auth);
await doc.loadInfo(); // loads sheets
await doc.loadInfo(); // loads sheets and other document metadata

const firstSheet = doc.sheetsByIndex[0]; // in the order they appear on the sheets UI
const otherSheet = doc.sheetsById[123]; // accessible via ID if you already know it
const sheet123 = doc.sheetsById[123]; // accessible via ID if you already know it

const newSheet = await doc.addSheet(); // adds a new sheet
```
Expand Down Expand Up @@ -333,16 +333,16 @@ Param|Type|Required|Description

?> The authentication method being used must have write access to the destination document as well

### Export
### Exports

Several export methods are available, which are the same as using the `File > Download` menu in the Google Sheets UI. The formats listed below export only a single sheet. See [GoogleSpreadsheet > Export](classes/google-spreadsheet?id=export) formats which include the entire document.
See [Exports guide](guides/exports) for more info.

#### `downloadAsCSV(returnStreamInsteadOfBuffer)` (async) :id=fn-downloadAsCSV
> Export worksheet in CSV format
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing CSV data

Expand All @@ -352,7 +352,7 @@ Param|Type|Required|Description
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing TSV data

Expand All @@ -362,7 +362,7 @@ Param|Type|Required|Description
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing PDF data

Expand Down
8 changes: 4 additions & 4 deletions docs/classes/google-spreadsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ Param|Type|Required|Description

### Exports

Several export methods are available, which are the same as using the `File > Download` menu in the Google Sheets UI. The formats listed below export all sheets in the document. See [GoogleSpreadsheetWorksheet > Export](classes/google-spreadsheet-worksheet?id=export) formats which export only a single sheet.
See [Exports guide](guides/exports) for more info.

#### `downloadAsHTML(returnStreamInsteadOfBuffer)` (async) :id=fn-downloadAsHTML
> Export entire document in HTML format (zip file)
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing HTML data (in a zip file)

Expand All @@ -181,7 +181,7 @@ Param|Type|Required|Description
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing XLSX data

Expand All @@ -191,7 +191,7 @@ Param|Type|Required|Description
Param|Type|Required|Description
---|---|---|---
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer
`returnStreamInsteadOfBuffer`|Boolean|-|Set to true to return a stream instead of a Buffer<br/>_See [Exports guide](guides/exports) for more details_

- ↩️ **Returns** - Buffer (or stream) containing ODS data

Expand Down
25 changes: 14 additions & 11 deletions docs/guides/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ Some of these formats export the entire document, while others are only a single

These are the available formats:

File Type|File Extension|Full Document|Method|Notes
---|---|---|---|---
Web Page | zip | ✅ | [`doc.downloadAsHTML()`](classes/google-spreadsheet?id=fn-downloadAsHTML) | _unzips to folder containing html file(s)_
Microsoft Excel | xlsx | | [`doc.downloadAsXLSX()`](classes/google-spreadsheet?id=fn-downloadAsXLSX) |
OpenDocument | ods | | [`doc.downloadAsODS()`](classes/google-spreadsheet?id=fn-downloadAsODS) |
Comma Separated Values | csv | | [`sheet.downloadAsCSV()`](classes/google-spreadsheet-worksheet?id=fn-downloadAsCSV) |
Tab Separated Values | tsv | | [`sheet.downloadAsTSV()`](classes/google-spreadsheet-worksheet?id=fn-downloadAsTSV) |
PDF | pdf | | [`sheet.downloadAsPDF()`](/classes/google-spreadsheet-worksheet?id=fn-downloadAsPDF) |
File Type|File Extension|Contents|Method
---|---|---|---
Web Page | zip > html+css | document | [`doc.downloadAsHTML()`](classes/google-spreadsheet?id=fn-downloadAsHTML)
Microsoft Excel | xlsx | document | [`doc.downloadAsXLSX()`](classes/google-spreadsheet?id=fn-downloadAsXLSX)
OpenDocument | ods | document | [`doc.downloadAsODS()`](classes/google-spreadsheet?id=fn-downloadAsODS)
Comma Separated Values | csv | worksheet | [`sheet.downloadAsCSV()`](classes/google-spreadsheet-worksheet?id=fn-downloadAsCSV)
Tab Separated Values | tsv | worksheet | [`sheet.downloadAsTSV()`](classes/google-spreadsheet-worksheet?id=fn-downloadAsTSV)
PDF | pdf | worksheet | [`sheet.downloadAsPDF()`](/classes/google-spreadsheet-worksheet?id=fn-downloadAsPDF)


All of these methods by default fetch an ArrayBuffer, but can be passed an optional parameter to return a stream instead.

## ArrayBuffer mode (default)

This means you are dealing with the entire document at once. Usually you'd want to write this to a file, for example:

```javascript
const doc = new GoogleSpreadsheet('<YOUR-DOC-ID>', auth);

Expand All @@ -28,14 +31,14 @@ All of these methods by default fetch an ArrayBuffer, but can be passed an optio

## Stream mode

Dealing with streams can be useful to do things like upload the file directly to somewhere else, or to handle a large CSV.
Dealing with [streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) means you are dealing with a stream of data rather than the entire file at once. This can be useful to do things like upload the file to somewhere else without saving it locally first, or to handle a large CSV when you want to do something else with each entry.

This example doesn't get into the details, but this simple example should at least get you started.
This example doesn't get into the details of using streams, but this simple example should at least get you started:

```javascript
const doc = new GoogleSpreadsheet('<YOUR-DOC-ID>', auth);

const csvStream = await doc.downloadAsCSV(true);
const csvStream = await doc.downloadAsCSV(true); // this `true` arg toggles to stream mode
const writableStream = fs.createWriteStream('./my-export-stream.csv');

writableStream.on('finish', () => {
Expand Down

0 comments on commit 882bd73

Please sign in to comment.