This guide explains how to author ExcelTemplate workbooks (.xlsx) that can be converted into the ExcelReport DSL and rendered to final reports.
ExcelTemplate is an authoring style where you design report structure in Excel and let ExcelTemplateConverter translate it into DSL (urn:excelreport:v2).
Conversion flow:
- Read workbook (
.xlsx) - Extract sheets, cell values/formulas, component boundaries, and optional workbook metadata
- Convert to DSL
- Render final workbook with
ReportGenerator
- Any sheet that does not start with
__component_is treated as a normal output sheet template.
- Component sheets must be named:
__component_<ComponentName> - Example:
__component_ItemRow - Use these sheets via
{{use:ItemRow}}triggers from other sheets.
- Use sheet name:
__sheet_meta - Place one shape with fixed name:
__workbook_meta - Put workbook-level XML in the shape text (see section 4).
- A regular cell value is copied as a DSL
cell@value. - A formula cell is copied as a DSL
cell@formula.
@foo-> normalized to@(root.Foo)@item.Name-> normalized to@(item.Name)
Use this form in a cell text:
{{use:ComponentName}}
Repeat-use form:
{{use:ComponentName, from:@items, var:item}}
With style overflow option:
{{use:ComponentName, from:@items, var:item, styleOverflow:edge}}
Notes:
fromandvarmust be specified together in use-trigger repeat.- Repeat direction is normalized to
down.
Inside __sheet_meta -> shape __workbook_meta, place XML like this:
<workbook>
<sheets>
<sheet templateSheet="InvoiceTemplate"
name="@(grp.Name)"
from="@(root.Groups)"
var="grp" />
</sheets>
</workbook>Rules:
templateSheetis required.nameis required.fromis optional.varis optional.- If
varis specified,fromis required. - If
fromis specified andvaris omitted, runtime uses the default variable nameitem.
__component_Header__component_ItemRowInvoiceTemplate__sheet_meta(contains shape__workbook_meta)
In InvoiceTemplate:
A1 = @grp.NameA3 = {{use:Header}}A5 = {{use:ItemRow, from:@grp.Items, var:item, styleOverflow:edge}}
<workbook>
<sheets>
<sheet templateSheet="InvoiceTemplate"
name="@(grp.Name)"
from="@(root.Groups)"
var="grp" />
</sheets>
</workbook>var data = new
{
Groups = new[]
{
new
{
Name = "North",
Items = new[]
{
new { Name = "Mouse", Qty = 2, Price = 1200 },
new { Name = "Keyboard", Qty = 1, Price = 980 }
}
},
new
{
Name = "South",
Items = new[]
{
new { Name = "Display", Qty = 1, Price = 24500 }
}
}
}
};Expected result:
- Sheet
Northgenerated fromInvoiceTemplate - Sheet
Southgenerated fromInvoiceTemplate
var converter = new ExcelTemplateConverter();
var conversion = converter.ConvertToDsl("template.xlsx");
Console.WriteLine(conversion.Text);
foreach (var issue in conversion.Issues)
{
Console.WriteLine($"[{issue.Severity}] {issue.Kind}: {issue.Message}");
}var generator = new ExcelTemplateReportGenerator();
var result = generator.GenerateFromExcelTemplate("template.xlsx", data);
if (result.Succeeded)
{
File.WriteAllBytes("report.xlsx", result.Output!.ToArray());
}sheet '__sheet_meta' is missing fixed shape '__workbook_meta'- Meta XML root is not
<workbook> workbook/sheets/sheetis missingtemplateSheetdoes not exist in workbook- Duplicate
templateSheetdefinitions varspecified withoutfrom
- Keep one responsibility per component sheet (
__component_*). - Keep
__workbook_metafocused on workbook-level concerns (such as sheet repeat). - Prefer explicit expressions (
@(root.X)) for readability when templates grow. - Validate generated DSL in CI via unit/integration tests.