Trouble Viewing Images? Right-click on any image and select "Open in new tab" to view a larger version. You can also zoom in using Ctrl + Mouse Wheel for easier readability.
Article Goal
Set up Finished Reports to name Excel worksheet tabs dynamically based on group values during export, using scripts and configuration options.
What Is This For?
When exporting reports to Excel, VDM normally places each page into its own tab with generic naming. By using a script and capturing group values, you can customize each Excel tab name to reflect its respective group ID or label—making the exported report far easier to navigate.
Why Use Dynamic Sheet Naming?
Improves usability and professionalism in exported reports
Automatically assigns relevant names to tabs (e.g., by Employee ID, Region, etc.)
Reduces manual renaming of sheets
Helps users identify grouped data at a glance
Tip: This method is especially helpful in reports where each group spans multiple pages but should still be exported as a single tab.
Step-by-Step: Export To Excel with Sheet Names
Step 1: Add a “Before Print” Script to the Report
1. Click on Scripts at the top right of the Finished Report Designer
2. In the properties panel, select XtraReport Report from the drop down
3. Expand Scripts, then add a new script under “Before Print”
4. Paste the following line inside the BeforePrint subroutine:
Step 2: Add Global Code at the Top of the Script Page
At the top of your script editor (Line 1), insert the following code block:
using System;
using System.Collections.Generic;
public List<string> GroupValues = new List<string>();
void PrintingSystem_XlSheetCreated(object sender, XlSheetCreatedEventArgs e) {
for (int i = 0; i < GroupValues.Count; i++)
{
if (e.Index == i)
e.SheetName = GroupValues[i].ToString();
}
}
Important Note: This script builds a list of group values to be used as sheet names and assigns them one-by-one as Excel sheets are created.
Important Note: This script builds a list of group values to be used as sheet names and assigns them one-by-one as Excel sheets are created.
Step 3: Add a Page Break and “Before Print” Script to the Group Label
You need to add each group value to the list before the report is printed.
1. Click back on Designer (Top right of VDM)
2. Select the Group Header that has your label in it, then expand the Group Header Tasks and add a Page Break.
3. Identify and select the label that returns your grouping field (e.g., ClientID)
4. Add a Before Print script to that label
5. Insert the following line of code (modify label name as needed):
GroupValues.Add(Convert.ToString(label2.Text));
Step 4: Set the Excel Export Mode
To ensure each group is exported to its own worksheet:
1. Go to the Report’s Export Options in the Properties Panel and expand Export Options
2. Under XLSX Export Options, set Export Mode to: Single File (Page-by-Page)
Tip: This ensures that each page becomes a separate tab within the same Excel file.
Step 5: Set a Custom Page Height (Optional)
If each group spans multiple pages, you may want to prevent the group from being split into multiple tabs.
1. Go to the Report’s Page Settings, then set Paper Kind to Custom
2. Set a large page height (999999) to ensure all grouped content fits on a single page
Note: This setting has no impact on Excel layout, only on how page breaks are handled during export.
Article Summary
By combining a Before Print event, a script that tracks group values, and a custom export configuration, you can dynamically name Excel sheet tabs based on report group values. This is especially useful for users reviewing grouped datasets in Excel and improves clarity across large multi-page exports.
Use Case: Generate a report grouped by Client ID and have each Excel tab clearly labeled with the corresponding Client ID or Name - automatically.
Comments
0 comments
Please sign in to leave a comment.