The Report Writer is a class library that is used to export the RDL report with popular file formats like PDF, Microsoft Word, Microsoft CSV, and Microsoft Excel without previewing the report on a webpage. This section describes how to export the RDL report in UWP application using the Report Writer
.
3. Change the project name, and then click Create.
Select the target and minimum platform version Windows 10, version 1809(10.0; Build 17763) from the dropdown, and then click OK.
Set the same version for the target and the minimum platform version.
Right-click the project or solution on the Solution Explorer tab and choose Manage NuGet Packages. Alternatively, select Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Refer to the NuGet Packages to learn more details about installing and configuring the Report writer NuGet packages. You can add the reports from the Syncfusion installation location. For more information, refer to the samples and demos section.
Search for BoldReports.UWP
NuGet package and install them in your UWP application.
Package | Purpose |
---|---|
BoldReports.UWP |
Contains UWP Reporting controls (Report Writer) to preview and export the reports. |
In this tutorial, the
Product List.rdlc
report is used, and it can be downloaded at this link.
Resources
in your application to store the RDLC reports.Initialize the Report Writer export type inside the <Grid>
tag as shown below in the MainWindow.xaml
file,
<Page
....
....
....
xmlns:BoldReports="using:BoldReports.UI.Xaml"
....>
<Grid Margin="0" Name="grd_controlPanel" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Name="pagePanel" Grid.Row="1" Margin="20,40,0,0" Background="White">
<TextBlock FontSize="15" FontFamily="Segoe UI Regular" TextWrapping="Wrap" Padding="5,5,5,5" >
<TextBlock.Text>This sample shows the capability of exporting a RDLC report into various file formats like PDF, WORD, EXCEL and HTML using Local export mode of Report Writer. Choose a file format and click generate button to view the selected document generated from report file.</TextBlock.Text>
</TextBlock>
<StackPanel Margin="0,10,0,0" Orientation="Vertical">
<RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="PDF" HorizontalAlignment="Left" Margin="20,10,0,0" x:Name="pdf" IsChecked="true" VerticalAlignment="Top"/>
<RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="Word" HorizontalAlignment="Left" Margin="20,10,0,0" x:Name="word" VerticalAlignment="Top"/>
<RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="Excel" HorizontalAlignment="Left" Margin="20,10,0,0" x:Name="excel" VerticalAlignment="Top"/>
<RadioButton FontSize="15" FontFamily="Segoe UI Regular" Content="HTML" x:Name="html" VerticalAlignment="Top" Margin="20,10,0,0" Width="90"/>
<Button Click="Button_Click" HorizontalAlignment="Left" Margin="20,10,0,0" VerticalAlignment="Bottom" BorderBrush="LightBlue" Background="#8bb54a">
<StackPanel Orientation= "Horizontal" Background="#8bb54a" Width="144">
<TextBlock Foreground="#ffffff" FontSize="16" FontFamily="Segoe UI Bold" Text="Generate" HorizontalAlignment="Right" Margin="30,5,0,0" Width="110" VerticalAlignment="Center" Height="27"/>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
</Grid>
</Page>
Open the MainWindow.xaml.cs
file and add the following using statement.
using BoldReports.Writer;
using Windows.Storage.Pickers;
using System.Reflection;
using Windows.Storage.Streams;
using Windows.Storage;
using Windows.UI.Popups;
using System.Collections;
Create a class and methods that returns business object data collection. Use the following code in your application.
public class ReportData
{
public string ProdCat { get; set; }
public string SubCat { get; set; }
public double? OrderYear { get; set; }
public string OrderQtr { get; set; }
public double? Sales { get; set; }
public static IList GetData()
{
List<ReportData> datas = new List<ReportData>();
ReportData data = null;
data = new ReportData()
{
ProdCat = "Accessories",
SubCat = "Helmets",
OrderYear = 2002,
OrderQtr = "Q1",
Sales = 4945.6925
};
datas.Add(data);
data = new ReportData()
{
ProdCat = "Components",
SubCat = "Road Frames",
OrderYear = 2002,
OrderQtr = "Q3",
Sales = 957715.1942
};
datas.Add(data);
data = new ReportData()
{
ProdCat = "Components",
SubCat = "Forks",
OrderYear = 2002,
OrderQtr = "Q4",
Sales = 23543.1060
};
datas.Add(data);
data = new ReportData()
{
ProdCat = "Bikes",
SubCat = "Road Bikes",
OrderYear = 2002,
OrderQtr = "Q1",
Sales = 3171787.6112
};
datas.Add(data);
data = new ReportData()
{
ProdCat = "Accessories",
SubCat = "Helmets",
OrderYear = 2002,
OrderQtr = "Q3",
Sales = 33853.1033
};
datas.Add(data);
return datas;
}
}
Initialize the ReportWriter by using the following code example in the MainWindow.xaml.cs
file export button click event.
async void Button_Click(object sender, RoutedEventArgs e)
{
FileSavePicker fileSavePicker = new FileSavePicker();
WriterFormat format = WriterFormat.PDF;
if (pdf.IsChecked == true)
{
fileSavePicker.FileTypeChoices.Add("PDF", new List<string> { ".pdf" });
fileSavePicker.DefaultFileExtension = ".pdf";
format = WriterFormat.PDF;
}
else if (excel.IsChecked == true)
{
fileSavePicker.FileTypeChoices.Add("Excel", new List<string> { ".xlsx" });
fileSavePicker.DefaultFileExtension = ".xlsx";
format = WriterFormat.Excel;
}
else if (word.IsChecked == true)
{
fileSavePicker.FileTypeChoices.Add("Word", new List<string> { ".docx" });
fileSavePicker.DefaultFileExtension = ".docx";
format = WriterFormat.Word;
}
else if (html.IsChecked == true)
{
fileSavePicker.FileTypeChoices.Add("Html", new List<string> { ".html" });
fileSavePicker.DefaultFileExtension = ".html";
format = WriterFormat.HTML;
}
fileSavePicker.SuggestedFileName = "ExportReport";
var savedItem = await fileSavePicker.PickSaveFileAsync();
if (savedItem != null)
{
MemoryStream exportFileStream = new MemoryStream();
Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
// Ensure the report loaction and application name.
Stream reportStream = assembly.GetManifestResourceStream("<application name>.Resources.Product List.rdlc");
BoldReports.UI.Xaml.ReportDataSourceCollection datas = new BoldReports.UI.Xaml.ReportDataSourceCollection();
datas.Add(new BoldReports.UI.Xaml.ReportDataSource { Name = "Sales", Value = ReportData.GetData() });
ReportWriter writer = new ReportWriter(reportStream, datas);
writer.ExportMode = ExportMode.Local;
writer.ExportCompleted += Writer_ExportCompleted;
await writer.SaveASync(exportFileStream, format);
try
{
using (IRandomAccessStream stream = await savedItem.OpenAsync(FileAccessMode.ReadWrite))
{
// Write compressed data from memory to file
using (Stream outstream = stream.AsStreamForWrite())
{
byte[] buffer = exportFileStream.ToArray();
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
exportFileStream.Dispose();
}
catch { }
}
}
private void Writer_ExportCompleted(object sender, byte[] e)
{
MessageDialog msgDialog = new MessageDialog("Report exporting completed successfully");
msgDialog.ShowAsync();
}
Congratulations! You have completed your first UWP Writer application! Click here to download the already created UWP Report Writer application.
Note: You can refer to our feature tour page for the UWP Report Writer to see its innovative features.