Create spreadsheet from existing template in C#, VB.NET
Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can create spreadsheet from existing template in C#, VB.NET.
You can create spreadsheet from existing template by using the ‘Workbooks.Open’ method. A template is a workbook whose formatting will be inherited by the new workbook created. The template may be designed either through the code or through the Microsoft Excel designer. It is even easier to create the template using the Microsoft Excel designer.
Steps to create spreadsheet from existing template, programmatically:
Step 1: Create a new C# console application project.
Create a new C# console application
Step 2: Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
Install NuGet package
Step 3: Include the following namespaces in the Program.cs file.
C#
using Syncfusion.XlsIO;
using System.IO;
using System.Reflection;
VB.NET
Imports Syncfusion.XlsIO
Imports System.IO
Imports System.Reflection
Step 4: Use the following code snippet to create spreadsheet from existing template in C#, VB.NET.
C#
//Create Excel engine
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Instantiate the application object
IApplication application = excelEngine.Excel;
//Create spreadsheet from existing template
IWorkbook workbook = application.Workbooks.Open("Template.xlsx");
//The first worksheet object in the worksheets collection is accessed
IWorksheet worksheet = workbook.Worksheets[0];
//A text is set in the first cell of the worksheet
worksheet[1, 1].Text = "Syncfusion Essential Studio®";
//Save the spreadsheet
workbook.SaveAs("Output.xlsx");
}
VB.NET
'Create Excel engine
Using excelEngine As ExcelEngine = New ExcelEngine()
'Instantiate the application object
Dim application As IApplication = excelEngine.Excel
'Create spreadsheet from existing template
Dim workbook As IWorkbook = application.Workbooks.Open("Template.xlsx")
'The first worksheet object in the worksheets collection is accessed
Dim worksheet As IWorksheet = workbook.Worksheets(0)
'A text is set in the first cell of the worksheet
worksheet(1, 1).Text = "Syncfusion Essential Studio®"
'Save the spreadsheet
workbook.SaveAs("Output.xlsx")
End Using
A complete Windows Forms working example of how to create spreadsheet from existing template in C#, VB.NET can be downloaded from create-spreadsheet-from-existing-template.zip.
By executing the program, you will get the output as below.
Output Excel document
Refer here to explore the rich set of Syncfusion Excel (XlsIO) library features.
See Also:
Create simple spreadsheet in C#, VB.NET using XlsIO
Does the XlsIO component support Excel spreadsheets that have VBA code in them?
How to create an Excel file in Windows Forms
How do I protect certain cells in a spreadsheet?
How do I create a workbook with the specified number of worksheets?
How to edit an existing Excel file in C#, VB.NET
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
ZetExcel is an excellent excel SDK for.Net framework. This is very useful for developing high-performance applications to create, edit, convert or print excel spreadsheet file formats without requiring Microsoft. I have used this Excel Spreadsheet Programming API from (https://zetexcel.com/). you can try.