-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
76 lines (62 loc) · 2.7 KB
/
Form1.cs
File metadata and controls
76 lines (62 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
namespace reporting_example_export {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
var report = new XtraReport1();
// Set the DetailReport band's PageBreak property to AfterBand
// to print each product category on a new report page.
report.Bands[BandKind.DetailReport].PageBreak = PageBreak.AfterBand;
// Set the report's RollPaper property to true
// to fit each product category to one report page.
report.RollPaper = true;
// Use SingleFilePageByPage mode
// to export each page of the report to a separate sheet.
var xlsxExportOptions = new XlsxExportOptions {
ExportMode = XlsxExportMode.SingleFilePageByPage,
ShowGridLines = true
};
// Use the label's PrintOnPage event to save the names of all the categories to a list.
var categoriesNames = new List<string>();
report.Bands[BandKind.Detail].Controls["CategoryNameLabel"].PrintOnPage += (s1, e1) => {
var categoryNameLabel = (XRLabel)s1;
categoriesNames.Add(categoryNameLabel.Text);
};
// Use the XlSheetCreated event to change the default name of each sheet
// to the category name.
report.PrintingSystem.XlSheetCreated += (s2, e2) => {
e2.SheetName = categoriesNames[e2.Index];
};
// Export the report to Excel format. Save the exported file
// to the project directory.
var projectDirPath = Path.GetDirectoryName(
Path.GetDirectoryName(
System.IO.Directory.GetCurrentDirectory()
)
);
var xlsxFilePath = Path.Combine(projectDirPath, "ProductCategories.xlsx");
report.ExportToXlsx(xlsxFilePath, xlsxExportOptions);
// Open the exported file in the default Excel viewer.
Process process = new Process();
try {
process.StartInfo.FileName = xlsxFilePath;
process.Start();
process.WaitForInputIdle();
}
catch { }
}
}
}