This is the final part of the blog series that shows how to use RadSpreadProcessing in a complete Spreadsheet scenario. In parts 1 and 2 we created an Expense report from scratch, entered a document’s data and beautified the content using workbook themes, styles and images. In case you missed the previous posts, make sure to catch up and read Part 1 and Part 2, or download the source code from the SDK example.
In this post, our aim is to generate PDF reports that contain the expenses of each department individually. So, we will produce three documents: Sales, Marketing and Engineering reports. To achieve this, we can filter the worksheet by different criteria and export it to PDF files.
Let’s get started!
Before we apply any filters, we need to specify the range of cells to be filtered. In our case, this is the range between the column headers row and the total expenses row. After setting this range to the worksheet FilterRange property, we should apply a ValuesCollectionFilter to the first column of our range. This type of filter is used to specify the values you want visible. For example, to show only the expenses of the Sales department and the total rows, you need to add the values “Sales,” “Sales Expenses” and “Total Expenses” to the ValuesCollectionFilter instance. As a result, all rows that contain different values in the department column will be hidden. Here is how our document looks with the filter applied:
To filter easily by any department name, we can create a FilterByDepartment() method. The following code shows a sample implementation:
CellRange(5, 1, 31, 4);
 valuesToShow =
IFilter departmentFilter =
If later we want to clear the filter and see all document rows, we can set the filter range to null. Resetting the range will remove all applied filters and display previously hidden rows.
We already know how to display only the expenses of a single department. Now, how can we export this data to PDF documents? Well, with RadSpreadProcessing this really is a piece of cake.
First, set the page size and the centering option of the worksheet using the WorksheetPageSetup property. The next snippet sets the size of the pages to A4 and makes the page content centered horizontally.
worksheet.WorksheetPageSetup.PaperType = PaperTypes.A4;
Using the PdfFormatProvider, we can pass a file stream and export the report to a PDF file. The following method can be used to save a file with a specific name:
(Stream fileStream =
PdfFormatProvider provider =
That's it! We have all we need to create expense reports for each department. Now, we can apply filters and export the workbook:
The result from the code above is three separate PDF files with the file names: “SalesExpenses.pdf,” “MarketingExpenses.pdf” and “EngineeringExpenses.pdf.” Each of the files contains the expense data for the corresponding department. The result PDF reports may be seen in the image below:
In this blog post we learned how to filter and export the contents of the worksheet to PDF. The combination of powerful spreadsheet features with the UI-independent PDF export makes RadSpreadProcessing a perfect solution for both client- and server-side scenarios.
If you need a more detailed view on the source code of this blog post series, please download it from our SDK repository here.
Stay tuned for more RadSpreadProcessing tips and tricks!
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.