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 Project → Add Reference → Browse → Choose the folder contains Spire.XLS for WPF → Bin → .NET 4.0.
- Please make sure the namespace-Spire.Xls being imported.
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.
Workbook myWorkbook = new Workbook(); myWorkbook.Worksheets.Add("My New Worksheet"); myWorkbook.SaveToFile("Result.xls"); System.Diagnostics.Process.Start(myWorkbook.FileName);
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.
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.
Workbook workbook = new Workbook(); workbook.CreateEmptySheet("New Empty Worksheet"); workbook.SaveToFile("Sample.xls"); System.Diagnostics.Process.Start(workbook.FileName);
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.
Step 3: Insert several worksheet at one time
Workbook workbook = new Workbook(); workbook.CreateEmptySheets(6); workbook.SaveToFile("Sample.xls"); System.Diagnostics.Process.Start(workbook.FileName);
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: