We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Create spreadsheet from existing template in C#, VB.NET

Platform: WinForms |
Control: XlsIO |
Published Date: April 30, 2011 |
Last Revised Date: June 13, 2019

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 new 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

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

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

Read Excel file in C#, VB.NET

Note:

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.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon