# SpreadsheetWrite

Writes a spreadsheet object into a file.

## Method Signature

```
SpreadsheetWrite(spreadsheetObj=[any], filename=[any], password=[any], overwrite=[any])
```

### Arguments

| Argument         | Type      | Required | Description                                              | Default |
| ---------------- | --------- | -------- | -------------------------------------------------------- | ------- |
| `spreadsheetObj` | `ANY`     | `true`   | The spreadsheet object to write.                         |         |
| `filename`       | `STRING`  | `true`   | The path where the file should be saved.                 |         |
| `password`       | `STRING`  | `false`  | Password to protect the spreadsheet (optional).          |         |
| `overwrite`      | `BOOLEAN` | `false`  | Whether to overwrite an existing file. Default is false. |         |

## Examples

Write a spreadsheet to file:

```js
// Create and save spreadsheet
var spreadsheet = SpreadsheetNew();
SpreadsheetAddRow( spreadsheet, [ "Name", "Email" ] );
SpreadsheetAddRow( spreadsheet, [ "John Doe", "john@example.com" ] );

SpreadsheetWrite( spreadsheet, "/path/to/output.xlsx" );
println( "Spreadsheet saved successfully" );
```

Export data with overwrite:

```js
// Export and overwrite existing file
var spreadsheet = SpreadsheetRead( "/path/to/original.xlsx" );
SpreadsheetAddRow( spreadsheet, [ "New Row", "Data" ] );

// Write back to same location (overwrite = true by default)
SpreadsheetWrite( spreadsheet, "/path/to/original.xlsx", "", true );
```

Save with password protection:

```js
// Save encrypted spreadsheet
var spreadsheet = SpreadsheetNew();
SpreadsheetAddRows( spreadsheet, [ [ "A", "B" ], [ "1", "2" ] ] );

SpreadsheetWrite(
    spreadsheet,
    "/path/to/secure.xlsx",
     "myPassword",
    true
);
```

## Related

* [SpreadsheetNew()](/boxlang-+-++/modules/bx-spreadsheet/built-in-functions/spreadsheetnew.md) - Create spreadsheet
* [SpreadsheetRead()](/boxlang-+-++/modules/bx-spreadsheet/built-in-functions/spreadsheetread.md) - Read spreadsheet files
* [SpreadsheetWriteBinary()](https://github.com/ortus-boxlang/boxlang-docs/blob/v1.x/boxlang-framework/boxlang-plus/modules/bx-spreadsheet/reference/built-in-functions/SpreadsheetWriteBinary.md) - Write binary format
* [File Handling Guide](https://github.com/ortus-boxlang/boxlang-docs/blob/v1.x/boxlang-framework/boxlang-plus/modules/bx-spreadsheet/file-handling.md) - File operations
* [I/O Operations](https://github.com/ortus-boxlang/boxlang-docs/blob/v1.x/boxlang-framework/boxlang-plus/modules/bx-spreadsheet/io-operations.md) - Reading and writing


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-spreadsheet/built-in-functions/spreadsheetwrite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
