npm package: @snytex/n8n-nodes-excel-form-writer
Description: An n8n node to fill an Excel form template with data and save it as a new file.
Author: snytex
Latest version: 0.2.3

# n8n Excel Form Writer Node

This package provides a custom n8n node to fill data into an existing Excel template file.

## Description

The `ExcelFormWriter` node allows you to:
1.  Load an Excel template (`.xlsx`).
2.  Write values to specific cells based on dynamic input.
3.  Save the result as a new Excel file.

This is useful for automating the creation of reports, invoices, or any other document based on a fixed Excel form.

## Features

- Load an Excel template from a specified path.
- Write data to any number of cells using a dynamic JSON input.
- Save the modified workbook to a new path.
- Advanced options for handling existing output files (overwrite, rename, or error).
- Returns a success message and the path to the newly created file.

## Node Properties

### Template File Path
**Required.** The absolute path to the Excel template file (e.g., `/data/formular.xlsx`). Can be set dynamically using an n8n expression.

### Output File Path
**Required.** The absolute path where the new Excel file will be saved (e.g., `/data/formular-ausgefuellt.xlsx`). Can be set dynamically using an n8n expression.

### Cell Data (JSON)
**Required.** A JSON array of objects, where each object specifies a cell and the value to write. This field is the core of the node and can be populated dynamically using an n8n expression from a previous node.

### Additional Options
Under "Additional Options", you can configure how the node behaves in specific scenarios.
-   **If File Exists**: Determines the action to take if the output file already exists.
    -   `Overwrite`: Replaces the existing file (Default).
    -   `Error`: Throws an error and stops the workflow.
    -   `Rename`: Appends a number to the filename (e.g., `file-1.xlsx`).

## JSON Data Examples

The `Cell Data (JSON)` field expects a valid JSON array. This can be provided directly, or more powerfully, as an expression from a previous node (like a Function node or an HTTP Request node).

### Example 1: Basic Data Entry
This fills out a simple invoice or contact form.

```json
[
  { "cell": "B2", "value": "INV-2024-105" },
  { "cell": "B3", "value": "Max Mustermann" },
  { "cell": "B4", "value": "Musterstraße 1" },
  { "cell": "E2", "value": "2024-10-15" }
]
```

### Example 2: Using Different Data Types
`exceljs` supports numbers, booleans, and dates, not just strings.

```json
[
  { "cell": "A1", "value": "Product Report" },
  { "cell": "B2", "value": 150 },
  { "cell": "C2", "value": 200.50 },
  { "cell": "D2", "value": true },
  { "cell": "E2", "value": { "formula": "B2*C2", "result": 30100 } }
]
```

### Example 3: Dynamic JSON from a Function Node
Imagine a Function node prepares the following data in a field called `excelData`.

```javascript
// In a Function node
const items = [
  { sku: 'X-01', qty: 5 },
  { sku: 'Y-02', qty: 12 },
];

let row = 10; // Start writing at row 10
const excelData = [];

for (const item of items) {
  excelData.push({ cell: `A${row}`, value: item.sku });
  excelData.push({ cell: `B${row}`, value: item.qty });
  row++;
}

return [{ json: { excelData } }];
```
You would then use the expression `{{ $json.excelData }}` in the `Cell Data (JSON)` field of the Excel Form Writer node.

## Example Usage

To use this node, you need to provide the path to your template, the desired output path, and the data to be filled in. The `cellData` parameter accepts an array of objects.

## License

MIT

## Credits

This node is powered by the excellent [exceljs](https://github.com/exceljs/exceljs) library, which handles all the heavy lifting of Excel file manipulation.