Custom Report Templates
Custom Report Templates in SQL Server Reporting Services (SSRS) allow developers to customize the look and feel of a report. By applying a custom template, you can add your organization's branding and design elements to reports.
Syntax
Custom Report Templates are created using a combination of standard HTML, CSS, and elements which are specific to SSRS. You can define styles for each element and then apply those styles to your report using the style
attribute.
Example
Consider the following report:
To customize this report with a specific branding, you can create a custom report template which includes the necessary CSS and HTML elements.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Custom Report Template</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
}
.report-title {
font-size: 24px;
color: #336699;
margin: 5px;
font-weight: bold;
}
.company-logo {
float: left;
width: 80px;
height: 80px;
margin: 0 15px 15px 0;
}
.page-number {
text-align: right;
margin-top: 15px;
font-style: italic;
}
</style>
</head>
<body>
<div class="company-logo">
<img src="https://i.imgur.com/K7KsOPE.png" alt="Company Logo">
</div>
<h1 class="report-title">Custom Report Title</h1>
<div class="report-content">
$ReportBody$
</div>
<div class="page-number">
Page $PageNumber$ of $TotalPages$
</div>
</body>
</html>
The above custom report template includes a company logo, a custom report title, and styling for the page numbering.
Once this template is created, it can be applied to the report by modifying the report's .rdl
file:
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition">
<.........
<......
<........
<.........
<CustomReportItems>
<CustomReportItem>
<Type>Embedded</Type>
<Name>CustomReportTemplate</Name>
<Value>
<![CDATA[
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Custom Report Template</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
}
.report-title {
font-size: 24px;
color: #336699;
margin: 5px;
font-weight: bold;
}
.company-logo {
float: left;
width: 80px;
height: 80px;
margin: 0 15px 15px 0;
}
.page-number {
text-align: right;
margin-top: 15px;
font-style: italic;
}
</style>
</head>
<body>
<div class="company-logo">
<img src="https://i.imgur.com/K7KsOPE.png" alt="Company Logo" />
</div>
<h1 class="report-title">Custom Report Title</h1>
<div class="report-content">
$ReportBody$
</div>
<div class="page-number">
Page $PageNumber$ of $TotalPages$
</div>
</body>
</html>
]]>
</Value>
<Height>2cm</Height>
<Width>2cm</Width>
</CustomReportItem>
</CustomReportItems>
</........
</........
</......
<........
</Report>
This will apply the custom template to the report, resulting in the following output:
Explanation
In the example above, we first created a custom HTML template custom-template.html
that includes the desired styling for the report. In this case, we defined a custom report title, a logo and styled a page numbering element.
Then, we added the CustomReportTemplate
element to an existing .rdl
file, the main element in which XML elements are defined. This CustomReportTemplate
specifies the type of the report element, its name, value (i.e. the contents of our HTML file), height, and width.
Finally, once this template is applied to the report it is rendered with its customized layout and style.
Use
Custom Report Templates can be used to apply a customized layout and styling to your reports. They can help you add your organization's branding and design elements and create a more professional look and feel for your reports.
Important Points
- Custom Report Templates require knowledge of HTML and CSS.
- Custom templates are added to the report using the
CustomReportItems
element in the.rdl
file. - Custom templates can be useful for creating branded or company-specific reports.
Summary
Custom Report Templates provide developers the ability to customize the look and feel of SSRS reports. By applying a custom template, you can add your organization's branding and design elements to reports. These templates are created using HTML, CSS, and specific SSRS elements. After creating the template, it can be applied to a report using the report's .rdl
file.