A microservice that generates filled Excel spreadsheets from JSON data using a template. Designed to be called from n8n workflows.
- Accepts JSON sections data and fills an Excel template
- Preserves existing formatting, styles, and formulas
- Rehydrates row formulas when a section needs more rows than the template originally provided
- Suppresses heading-like rows that leak through from summary-report documents
- Deterministically reroutes obvious miscategorized rows such as credit cards, tax liabilities, and business interests
- Normalizes debt rows into column B as negative values when the payload clearly represents a liability
- Handles various input formats (array, object, nested)
- Dynamically inserts rows when needed
- Returns binary XLSX file
- Node.js 18+
- npm
npm installnpm startThe server will start on http://localhost:3000 (or PORT environment variable).
npm run devGET /health
Response:
{ "ok": true }POST /generate-mediation-xlsx
Content-Type: application/json
Request Body Formats:
Format A - Direct object:
{
"sections": {
"Real Property": [...],
"Bank Accounts": [...]
}
}Format B - Array (from n8n):
[
{
"sections": {
"Real Property": [...],
"Bank Accounts": [...]
}
}
]Format C - Nested json:
{
"json": {
"sections": {
"Real Property": [...]
}
}
}Row Object Structure:
{
"description": "Property description",
"market_value": 350000,
"debt_balance": -120000,
"notes": "Additional notes"
}Available Section Keys:
Real PropertyBank AccountsBusiness InterestsRetirement BenefitsStock OptionsPersonal PropertyLife Insurance / AnnuitiesVehiclesCredit CardsBonusesOther Debts & LiabilitiesFederal Income TaxesAttorney's & Expert FeesSpouse 1's Separate PropertySpouse 2's Separate PropertyChildren's Property
The service also accepts a small set of alias section names from the sample
summary reports, including Real Properties, Cash and Accounts with Financial Institutions, Insurance And Annuities, and Motor Vehicles, Boats, Airplanes, Cycles, etc.
Before writing any rows into the template, the service now applies a narrow set of deterministic safeguards:
- Drops rows whose descriptions are clearly document headings such as
Real Properties,Credit Cards,Community Assets,Defined Contribution Plans, and similar non-data labels seen in the sample reports. - Reroutes obvious credit-card rows into
Credit Cards. - Reroutes obvious tax rows into
Federal Income Taxes. - Reroutes obvious business-interest rows into
Business Interests. - Moves debt amounts into column B and forces them negative for rows that are clearly liabilities.
Response:
- Success: Binary XLSX file with appropriate headers
- Error 400: Invalid/missing sections
- Error 500: Processing errors with details
Run the automated workbook regression tests:
npm testCreate payload.json:
[
{
"sections": {
"Real Property": [
{
"description": "4526 Treasure Trail, Sugar Land, Texas, 77479",
"market_value": 350000,
"debt_balance": -120000,
"notes": "County: Fort Bend | Mortgage Holder: Wells Fargo"
}
],
"Bank Accounts": [
{
"description": "Chase Bank (Checking Account)",
"market_value": 5324,
"debt_balance": 0,
"notes": "Acct (redacted): 012456869 | Balance: 5324"
}
]
}
}
]curl -X POST http://localhost:3000/generate-mediation-xlsx \
-H "Content-Type: application/json" \
--data @payload.json \
--output output.xlsxcurl http://localhost:3000/health# Initialize git (if not already)
git init
# Add files
git add .
# Commit
git commit -m "Initial commit: Spreadsheet Builder API"
# Add your GitHub remote
git remote add origin https://github.com/YOUR_USERNAME/spreadsheet-builder.git
# Push
git push -u origin main-
Go to Render Dashboard
-
Click New > Web Service
-
Connect your GitHub repository
-
Configure the service:
- Name:
spreadsheet-builder(or your choice) - Region: Choose closest to your location
- Branch:
main - Runtime:
Node - Build Command:
npm install - Start Command:
npm start - Instance Type: Free (or paid for better performance)
- Name:
-
Click Create Web Service
Once deployed, Render will provide a URL like https://spreadsheet-builder-xxxx.onrender.com
Test the health endpoint:
curl https://spreadsheet-builder-xxxx.onrender.com/healthExpected response:
{ "ok": true }-
Add an HTTP Request node in your n8n workflow
-
Configure the node:
- Method:
POST - URL:
https://your-render-url.onrender.com/generate-mediation-xlsx - Authentication: None (or add if you implement auth)
- Send Headers: Yes
- Header Name:
Content-Type - Header Value:
application/json
- Header Name:
- Send Body: Yes
- Body Content Type:
JSON - Body: Use expression
{{ $json }}(or{{ $json.sections }}wrapped in the expected format) - Response Format:
File - Put Output in Field:
data
- Method:
-
If your Code node outputs the sections directly, format the body as:
{ "sections": {{ $json }} }Or if your Code node already outputs the full structure:
{{ $json }}
After the HTTP Request node, add a Google Drive node:
- Configure Google Drive node:
- Operation:
Upload - Binary Data: Yes
- Input Binary Field:
data - File Name:
MediationSpreadsheet-{{ $now.format('yyyy-MM-dd-HHmm') }}.xlsx - Parent Folder: Select your target folder
- Operation:
[Your Data Source]
↓
[Code Node - Format sections object]
↓
[HTTP Request Node - POST to /generate-mediation-xlsx]
↓
[Google Drive Node - Upload binary file]
If you need to format your data into the sections structure:
// Assuming $input contains your parsed data
const sections = {
"Real Property": [],
"Bank Accounts": [],
// ... other sections
};
// Process your input data and populate sections
// ...
return {
sections: sections
};"Section header not found" error:
- The section key must match exactly (case-sensitive)
- Check the section mapping in the code
Empty or corrupted output:
- Verify the template file exists at
src/template/2025.07.30.Inventory-MediationSpreadsheetMaster.xlsx - Check that the worksheet name matches exactly:
Prop Distr - KB Preferred - Use
n8n shows binary garbled text:
- Ensure Response Format is set to
File, notTextorJSON
400 Bad Request:
- Check that your request body contains a valid
sectionsobject - Verify JSON syntax is correct
Check Render logs for detailed error messages:
- Go to your Render service dashboard
- Click Logs tab
- Look for error messages during request processing
Data is written to these columns:
- Column A:
market_value - Column B:
debt_balance - Column D:
description - Column G:
notes
ISC