Skip to main content

Generate Excel Reports

Create dynamic Excel spreadsheets from templates with data tables, formulas, and formatting.

Overview

RenderDoc Excel generation is perfect for:

  • Financial reports - P&L statements, balance sheets, budgets
  • Data exports - Customer lists, transaction histories, inventory
  • Analytics reports - Sales data, metrics dashboards
  • Operational documents - Timesheets, schedules, rosters

Quick Start

import { RenderDoc } from '@renderdoc/sdk';

const client = new RenderDoc({ apiKey: process.env.RENDERDOC_API_KEY });

const result = await client.documents.generate({
templateId: 'monthly-sales-report',
format: 'xlsx',
variables: {
reportTitle: 'Sales Report - January 2025',
generatedDate: new Date().toISOString(),
salesData: [
{ region: 'North', sales: 125000, target: 100000 },
{ region: 'South', sales: 98000, target: 110000 },
{ region: 'East', sales: 156000, target: 140000 },
{ region: 'West', sales: 112000, target: 120000 }
],
totalSales: 491000,
totalTarget: 470000
}
});

console.log('Excel report ready:', result.downloadUrl);

Creating Excel Templates

1. Create Template in Dashboard

  1. Go to Templates > Create Template
  2. Select Excel Template
  3. Use the spreadsheet designer to create your layout

2. Define Variables

Excel templates support:

  • Cell values: {{variableName}}
  • Row iteration: {{#each items}}...{{/each}}
  • Conditional content: {{#if condition}}...{{/if}}

3. Template Structure

Example template structure for a sales report:

| A              | B           | C          | D           |
|----------------|-------------|------------|-------------|
| {{reportTitle}}| | | |
| Generated: | {{date}} | | |
| | | | |
| Region | Sales | Target | Variance |
| {{#each salesData}} |
| {{region}} | {{sales}} | {{target}} | ={{B}}-{{C}}|
| {{/each}} |
| | | | |
| Total | {{total}} | {{target}} | ={{B}}-{{C}}|

Working with Data Tables

Simple Table

variables: {
employees: [
{ name: 'Alice', department: 'Engineering', salary: 85000 },
{ name: 'Bob', department: 'Marketing', salary: 72000 },
{ name: 'Carol', department: 'Sales', salary: 68000 }
]
}

Nested Data

variables: {
departments: [
{
name: 'Engineering',
employees: [
{ name: 'Alice', role: 'Senior Developer' },
{ name: 'David', role: 'Junior Developer' }
]
},
{
name: 'Marketing',
employees: [
{ name: 'Bob', role: 'Marketing Manager' }
]
}
]
}

Formatting Options

Number Formatting

Template cells can include Excel number formats:

  • Currency: $#,##0.00
  • Percentage: 0.00%
  • Date: MM/DD/YYYY

Preserving Formulas

RenderDoc preserves Excel formulas in templates. Use relative references that adjust as rows are inserted:

| Product | Quantity | Price | Total |
|---------|----------|-------|-------|
| Widget | 10 | 25.00 | =B2*C2|
| Gadget | 5 | 50.00 | =B3*C3|

Real-World Example: Financial Report

async function generateFinancialReport(month, year) {
const client = new RenderDoc({ apiKey: process.env.RENDERDOC_API_KEY });

// Fetch data from your systems
const revenue = await getRevenueData(month, year);
const expenses = await getExpenseData(month, year);
const projections = await getProjections(month, year);

const result = await client.documents.generate({
templateId: 'financial-report',
format: 'xlsx',
variables: {
reportTitle: `Financial Report - ${month} ${year}`,
preparedBy: 'Finance Team',
preparedDate: new Date().toLocaleDateString(),

// Revenue section
revenueItems: revenue.items,
totalRevenue: revenue.total,

// Expense section
expenseCategories: expenses.categories.map(cat => ({
name: cat.name,
items: cat.items,
subtotal: cat.subtotal
})),
totalExpenses: expenses.total,

// Summary
netIncome: revenue.total - expenses.total,
profitMargin: ((revenue.total - expenses.total) / revenue.total * 100).toFixed(2),

// Projections
nextMonthProjection: projections.nextMonth,
quarterProjection: projections.quarter,
yearProjection: projections.year
},
filename: `financial-report-${month}-${year}`
});

return result.downloadUrl;
}

Multiple Sheets

For multi-sheet workbooks, structure your variables by sheet:

variables: {
sheets: {
summary: {
title: 'Executive Summary',
metrics: [...]
},
details: {
title: 'Detailed Data',
transactions: [...]
},
appendix: {
title: 'Appendix',
notes: [...]
}
}
}

Batch Excel Generation

Generate multiple Excel reports efficiently:

const result = await client.documents.generateBatch({
templateId: 'sales-report',
format: 'xlsx',
documents: regions.map(region => ({
variables: {
regionName: region.name,
salesData: region.sales,
targets: region.targets
},
filename: `sales-report-${region.code}`
}))
});

Best Practices

1. Pre-calculate Totals

Calculate totals in your code rather than relying solely on Excel formulas:

const items = [...];
const total = items.reduce((sum, item) => sum + item.amount, 0);

variables: {
items,
total // Pre-calculated
}

2. Format Dates Before Sending

variables: {
reportDate: new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
}

3. Handle Large Datasets

For very large datasets, consider:

  • Pagination in the template
  • Multiple sheets
  • Summary views with detailed data in separate sheets
const PAGE_SIZE = 1000;
const pages = chunk(allData, PAGE_SIZE);

variables: {
pages: pages.map((pageData, index) => ({
pageNumber: index + 1,
data: pageData
})),
totalPages: pages.length
}

4. Test with Sample Data

Before generating production reports, test with sample data:

const testVariables = {
reportTitle: 'TEST REPORT',
salesData: [
{ region: 'Test Region', sales: 12345, target: 10000 }
]
};

const testResult = await client.documents.generate({
templateId: 'sales-report',
format: 'xlsx',
variables: testVariables
});

// Download and verify the output

Common Use Cases

Inventory Report

variables: {
warehouseId: 'WH-001',
reportDate: new Date().toISOString(),
inventory: [
{ sku: 'SKU-001', name: 'Widget', quantity: 150, reorderPoint: 50 },
{ sku: 'SKU-002', name: 'Gadget', quantity: 25, reorderPoint: 30 }
],
lowStockItems: 1,
totalValue: 45000
}

Employee Timesheet

variables: {
employeeName: 'John Doe',
payPeriod: 'Jan 1-15, 2025',
entries: [
{ date: '2025-01-01', project: 'Project A', hours: 8 },
{ date: '2025-01-02', project: 'Project B', hours: 6 }
],
totalHours: 70,
regularHours: 70,
overtimeHours: 0
}

Sales Pipeline

variables: {
pipelineDate: new Date().toISOString(),
opportunities: [
{ company: 'Acme Corp', value: 50000, stage: 'Proposal', probability: 60 },
{ company: 'Beta Inc', value: 75000, stage: 'Negotiation', probability: 80 }
],
totalPipeline: 125000,
weightedPipeline: 90000
}

Next Steps