Export a Word template to RDL
Save a Word document as a Reporting Services report definition. Merge fields become dataset expressions, so the result opens in Report Builder as a template you connect to data and run. It is a template, not a picture of the document.
Note
This page is about turning a Word document into an .rdl. To load, run and export existing reports, see Run an SSRS report.
Export
This exports the invoice template from the mail-merge tutorial:
using DocWright;
using DocWright.Core.Diagnostics;
using DocWright.Core.Formats;
using DocWright.Dom;
using DocWright.Formats.Rdl;
var converter = new DocWrightConverter();
using FileStream input = File.OpenRead("invoice-template.docx");
using WordDocument template = converter.Load(input);
// The simple route: RDL 2016, default names.
using (FileStream rdl = File.Create("invoice.rdl"))
{
converter.Save(template, rdl, ".rdl");
}
// Or configure the writer: the older schema, and your own dataset name.
var writer = new RdlWriter(new RdlWriteSettings
{
SchemaVersion = RdlSchemaVersion.Rdl2010,
DataSetName = "Orders",
});
using (FileStream rdl = File.Create("invoice-2010.rdl"))
{
writer.Write(template, rdl, new DocumentWriteOptions(), NullConversionDiagnostics.Instance);
}
What was generated (invoice.rdl):
Dataset fields: Amount, CustomerAddress, CustomerName, Description, OrderDate, OrderNumber, Quantity, TableEnd_Items, TableStart_Items, Total, UnitPrice
Expressions: =Fields!CustomerName.Value, =Fields!CustomerAddress.Value, =Fields!OrderNumber.Value, =Fields!OrderDate.Value
- A merge field
«CustomerName»becomes=Fields!CustomerName.Value, with a matching dataset field. PAGEandNUMPAGESbecomeGlobals!PageNumberandGlobals!TotalPages.- A field name that isn't a valid identifier, such as
«Last Name», is sanitized in the expression (Last_Name) while the dataset still reads the original column. - The data source and dataset have no connection string and an empty query. Nothing is invented: you wire up the data in Report Builder.
Warning
Mail-merge region markers («TableStart:Items» … «TableEnd:Items») are exported as ordinary fields, visible above as TableStart_Items, rather than as a repeating table bound to a dataset. Remove them from the template, or edit the table's grouping in Report Builder afterwards.
Settings
RdlWriteSettings |
Settings key | Default |
|---|---|---|
SchemaVersion |
rdl:schemaVersion |
Rdl2016 (SSRS 2016+, Power BI Report Server). Rdl2010 for SSRS 2008 R2–2014. |
ReportKind |
rdl:reportKind |
Server. client writes an .rdlc for a ReportViewer control. Saving with the .rdlc extension does the same. |
DataSetName |
rdl:dataSetName |
DocWrightData |
DataSourceName |
rdl:dataSourceName |
DocWrightDataSource |
ReportId |
rdl:reportId |
none. Report Designer writes a new GUID on every save; DocWright won't. Supply a stable id. |
EmbedImages |
rdl:embedImages |
true |
The key constants are on RdlFormatSettingKeys. A settings-dictionary value overrides the writer instance's.