How to add more sheets to the Excel file using C#

0

How to add more sheets to the Excel file using C sharp (2)

Index

Introduction

In the previous article we discussed how to create an excel sheet using C# from dataset MsSql, the core part of how to create and add items to excel sheet have been discussed in the part 2 of the article, in this article we will discuss how to add an excel sheet using C#.

The main aim of this article is to produce the following output.

How to add more sheets to the Excel file using C sharp

 

The above picture depicts 3 sheets formed in excel [testSheet1, testSheet2, testSheet3] programatically using C#.

Steps to  add more sheets to the Excel file using C#

Step 1 : Create a memory stream and call a static memory stream method to return the memory stream

The above code depicts that create a normal method toExcel() or you can call the method on pageLoad and create a memory stream and call another method which contains the core part of the code of this article. Step 2 : Once you have done this, create an ExcelPackage [which creates the core components of the EPPlus dll file to access various methods]

Step 3 : Create an excel worksheet by using the object of ExcelPage, the complete flow of creating an excel sheet is given below

Step 4 : Now save the ExcelSheet pack created, to the memory stream.

Now the ExcelSheet has been created and saved in the memory stream, now we have to output the memory stream to the excel sheet, the content type of the httpContext should be “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet” , and then you can add the header where the file will be transferred to the downloads.

The complete code for the above steps is given as

In the next article we will discuss how to style the excel sheet using C#. Any comments/suggestions related to the above article can be commented below.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge