-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
59 lines (54 loc) · 2.85 KB
/
Form1.vb
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
Imports System
Imports System.Windows.Forms
Imports DevExpress.DataAccess.Excel
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Configuration
' ...
Namespace BindingReportToExcelWorkbook
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
' Create an empty report.
Dim report As XtraReport = New XtraReport()
' Create a new Excel data source.
Dim excelDataSource As ExcelDataSource = New ExcelDataSource()
excelDataSource.FileName = "..//..//Northwind.xlsx"
' Select a required worksheet.
Dim excelWorksheetSettings As ExcelWorksheetSettings = New ExcelWorksheetSettings()
excelWorksheetSettings.WorksheetName = "Sheet_Categories"
' Specify import settings.
Dim excelSourceOptions As ExcelSourceOptions = New ExcelSourceOptions()
excelSourceOptions.ImportSettings = excelWorksheetSettings
excelSourceOptions.SkipHiddenRows = False
excelSourceOptions.SkipHiddenColumns = False
excelDataSource.SourceOptions = excelSourceOptions
' Create new fields and specify their settings.
Dim fieldCategoryID As FieldInfo = New FieldInfo With {.Name = "CategoryID", .Type = GetType(Double), .Selected = False}
Dim fieldCategoryName As FieldInfo = New FieldInfo With {.Name = "CategoryName", .Type = GetType(String)}
Dim fieldDescription As FieldInfo = New FieldInfo With {.Name = "Description", .Type = GetType(String)}
' Add the created fields to the data source schema in the order that matches the column order in the source file.
excelDataSource.Schema.AddRange(New FieldInfo() {fieldCategoryID, fieldCategoryName, fieldDescription})
' Assign the data source to the report.
report.DataSource = excelDataSource
' Add a detail band to the report.
Dim detailBand As DetailBand = New DetailBand()
detailBand.Height = 50
report.Bands.Add(detailBand)
' Create a new label.
Dim label As XRLabel = New XRLabel()
' Specify the label's binding depending on the data binding mode.
If Settings.Default.UserDesignerOptions.DataBindingMode = DataBindingMode.Bindings Then
label.DataBindings.Add("Text", Nothing, "CategoryName")
Else
label.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[CategoryName]"))
End If
' Add the label to the detail band.
detailBand.Controls.Add(label)
' Show the report's print preview.
report.ShowPreview()
End Sub
End Class
End Namespace