-
set the
Content
property to "Create a Workbook". -
attach an event handler to the
Button
control’sClick
event.
The Infragistics Excel Engine enables you to save data to and load data from Microsoft® Excel®. You can create workbooks and worksheets, input data, and export the data to Excel using the library’s various classes. The Infragistics Excel Engine makes it easy to export the data in your application as an Excel spreadsheet as well as import data from Excel into your application.
You will create a simple workbook and save it as an Excel file.
Create a Microsoft Windows® Presentation Foundation project.
Add a reference to the following NuGet package:
Infragistics.WPF.Excel
For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.
Add a Button
control and…
set the Content
property to "Create a Workbook".
attach an event handler to the Button
control’s Click
event.
In XAML:
<Button Content="Create a Workbook" Click="Button_Click" />
Open the code-behind and add the following namespaces:
In Visual Basic:
Imports Infragistics.Documents.Excel
In C#:
using Infragistics.Documents.Excel;
Add an event handler for the Button
control’s Click
event if a method stub has not been created for you.
In Visual Basic:
Sub Button_Click(sender As Object, e As RoutedEventArgs)
'TODO: Instantiate a Workbook object
'TODO: Add a worksheet to the workbook
'TODO: Add text to the first cell
'TODO: Save the workbook.
End Sub
In C#:
void Button_Click(object sender, RoutedEventArgs e)
{
//TODO: Instantiate a Workbook object.
//TODO: Add a worksheet to the workbook
//TODO: Add text to the first cell
//TODO: Save the workbook.
}
Instantiate a Workbook object.
In Visual Basic:
Dim workbook1 As New Workbook()
In C#:
Workbook workbook1 = new Workbook();
Add a Worksheet object to the workbook.
In Visual Basic:
Dim worksheet1 As Worksheet = workbook1.Worksheets.Add("Sheet 1")
In C#:
Worksheet worksheet1 = workbook1.Worksheets.Add("Sheet 1");
Set the first WorksheetCell object’s Value property to 42.
In Visual Basic:
worksheet1.Rows(0).Cells(0).Value = 42
In C#:
worksheet1.Rows[0].Cells[0].Value = 42;
Save the workbook.
In Visual Basic:
workbook1.Save("Workbook1.xls")
In C#:
workbook1.Save("Workbook1.xls");
Run the project and click the button.