Insert Excel Worksheets in WPF

2012-06-21 06:32:57 Written by  support iceblue
Rate this item
(0 votes)

Are there multiple choices for creating Excel worksheets in WPF with quick and steady performance? The answer is definitely positive. The post presents different choices for creating Excel worksheets in WPF.

Each solution will be managed within several lines of code; meanwhile the performance will be perfect for any kind of user. All the solution will be built base on Spire.Xls for WPF, which enables developers to fast generate, edit Excel files. Developers can control Excel on cell formatting, page setup, data sort and filter, chart and formulas. Besides, developers can use this component to import data into Excel from database and export data from Excel to database.

Spire.Xls for WPF is always welcome to any kind of trial and evaluation. So now please feel free to download Spire.XLS for WPF and then follow our guide to easily insert Excel worksheets WPF or try other function of Spire.Xls for WPF.

Friendly Reminder:

  • Before we code to insert Excel worksheet in WPF, please add spire.xls dll as reference by Clicking ProjectAdd ReferenceBrowseChoose the folder contains Spire.XLS for WPF → Bin.NET 4.0.
  • Please make sure the namespace-Spire.Xls being imported.
Next we will demonstrate the following choices for creating Excel worksheet.

Step 1: Insert a worksheet to Excel in WPF

In this method, we will insert a worksheet to Excel in WPF by calling Workbook.Worksheet.add(string sheetname) function, please check my code examples.

[C#]
Workbook myWorkbook = new Workbook();
myWorkbook.Worksheets.Add("My New Worksheet");
myWorkbook.SaveToFile("Result.xls");
System.Diagnostics.Process.Start(myWorkbook.FileName);
[VB.NET]
Dim myWorkbook As New Workbook()
myWorkbook.Worksheets.Add("My New Worksheet")
myWorkbook.SaveToFile("Result.xls")
System.Diagnostics.Process.Start(myWorkbook.FileName)

Effective Screenshot shows we have successfully inserted Excel worksheet in WPF.

Insert Excel Worksheet

Step 2: Create empty Excel worksheet in WPF

In this method, we will insert a worksheet to Excel in WPF using Workbook.CreateEmptySheet(string sheetname) function, please check my code examples.

[C#]
Workbook workbook = new Workbook();
workbook.CreateEmptySheet("New Empty Worksheet");
workbook.SaveToFile("Sample.xls");
System.Diagnostics.Process.Start(workbook.FileName);
[VB.NET]
Dim workbook As New Workbook()
workbook.CreateEmptySheet("New Empty Worksheet")
workbook.SaveToFile("Sample.xls")
System.Diagnostics.Process.Start(workbook.FileName)

Effective Screenshot shows we have successfully inserted Excel worksheet in WPF.

Insert Excel Worksheet

Step 3: Insert several worksheet at one time

[C#]
Workbook workbook = new Workbook();
workbook.CreateEmptySheets(6);
workbook.SaveToFile("Sample.xls");
System.Diagnostics.Process.Start(workbook.FileName);
[VB.NET]
Dim workbook As New Workbook()
workbook.CreateEmptySheets(6)
workbook.SaveToFile("Sample.xls")
System.Diagnostics.Process.Start(workbook.FileName)

Five worksheet have been inserted at one time, please check the effective screenshot:

Insert Excel Worksheet

Additional Info

  • tutorial_title: Insert Excel Worksheets in WPF
Last modified on Friday, 24 September 2021 09:48