# 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()](https://boxlang.ortusbooks.com/boxlang-framework/boxlang-plus/modules/bx-spreadsheet/reference/built-in-functions/spreadsheetnew) - Create spreadsheet
* [SpreadsheetRead()](https://boxlang.ortusbooks.com/boxlang-framework/boxlang-plus/modules/bx-spreadsheet/reference/built-in-functions/spreadsheetread) - 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
