Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to create excel file with multiple sheet name based on modules?

How to create excel file with multiple sheet name based on modules?

How to create excel file with multiple sheet name based on modules?

I work on c# desktop app I Can't export data to excel file with multiple tab(multi sheet).

only that i can do create excel file with only sheet based on data exist on data table module field.

I use open XML library

Data table data as below :

Divide Output Excel File To Multi Tab based On Module

PartId Company Files Tab Module
1222 micro Abc source 1
1321 silicon Abc source 1
1444 cd2 Abc types 2
1321 cd3 Abc types 2
1541 tvs Abc types 2
Expected Result :

Create File ABC.xlsx with two sheet first sheet name source and second sheet name types based on module and load data related to every sheet based on data exist on data table.

so if I have two modules meaning I have two sheet .

What I have tried:

CODE --> c#

public Boolean createExcelFile(DataTable Table,String FullFilePathName)
          Boolean IsDone = false;
              FileInfo CreatedFile = new FileInfo(FullFilePathName);
              Boolean ISNew = false;
              if (!CreatedFile.Exists)

                  ISNew = true;
              using (var pck = new ExcelPackage(CreatedFile))
                  ExcelWorksheet ws;
                  if (ISNew == true)
                      ws = pck.Workbook.Worksheets.Add("Sheet");

                      ws.Cells[1, 1].LoadFromDataTable(Table, ISNew, OfficeOpenXml.Table.TableStyles.Light8);

                       ws = pck.Workbook.Worksheets.FirstOrDefault();
                       ws.Cells[2, 1].LoadFromDataTable(Table, ISNew);
                  IsDone = true;

          catch (Exception ex)

              throw ex;
          return IsDone;
but problem code above create one files with one sheet only

so How to create file with multi sheet based on module ?

RE: How to create excel file with multiple sheet name based on modules?

This creates a sheet called "Sheet"


ws = pck.Workbook.Worksheets.Add("Sheet"); 
The next sheet you create cannot have the same name so what you could do is


int sheets = 0;
sheets += 1;
ws = pck.Workbook.Worksheets.Add("Sheet"+sheets.ToString()); 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close