Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6999909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:36:10+00:00 2026-05-27T20:36:10+00:00

How to create excel file with multiple sheets from DataSet using C#? I have

  • 0

How to create excel file with multiple sheets from DataSet using C#?

I have successfully created an excel file with single sheet. But I am not able to do that for multiple sheets.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:36:10+00:00Added an answer on May 27, 2026 at 8:36 pm

    Here is a simple C# class that programatically creates an Excel WorkBook and adds two sheets to it, and then populates both sheets. Finally, it saves the WorkBook to a file in the application root directory so that you can inspect the results…

    public class Tyburn1
    {
        object missing = Type.Missing;
        public Tyburn1()
        {
            Excel.Application oXL = new Excel.Application();
            oXL.Visible = false;
            Excel.Workbook oWB = oXL.Workbooks.Add(missing);
            Excel.Worksheet oSheet = oWB.ActiveSheet as Excel.Worksheet;
            oSheet.Name = "The first sheet";
            oSheet.Cells[1, 1] = "Something";
            Excel.Worksheet oSheet2 = oWB.Sheets.Add(missing, missing, 1, missing) 
                            as Excel.Worksheet;
            oSheet2.Name = "The second sheet";
            oSheet2.Cells[1, 1] = "Something completely different";
            string fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)        
                                    + "\\SoSample.xlsx";
            oWB.SaveAs(fileName, Excel.XlFileFormat.xlOpenXMLWorkbook,
                missing, missing, missing, missing,
                Excel.XlSaveAsAccessMode.xlNoChange,
                missing, missing, missing, missing, missing);
            oWB.Close(missing, missing, missing);
            oXL.UserControl = true;
            oXL.Quit();
        }
    }
    

    To do this, you would need to add a reference to Microsoft.Office.Interop.Excel to your project (you may have done this already since you are creating one sheet).

    The statement that adds the second sheet is…

    Excel.Worksheet oSheet2 = oWB.Sheets.Add(missing, missing, 1, missing) 
                                as Excel.Worksheet;
    

    the ‘1’ argument specifies a single sheet, and it can be more if you want to add several sheets at once.

    Final note: the statement oXL.Visible = false; tells Excel to start in silent mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to create the Excel file using HTMLTextwriter, but the returned file
I have the this code that will create excel file and work sheet then
I'm trying to create a new Excel file using jxl, but am having a
I am trying to create a excel file from Mysql using php. I found
I need to create an excel file via C#. I have read a few
I have to create an excel file with POI-3.2-Final (can't upgrade to 3.5+, for
I want to create XML file from my Excel file through .NET (c#). My
I created a link server using SQL Server 2008 R2 to an Excel File.
I am developing a simple Java program to create an Excel file using (Apache
I'm trying to create an Excel file with C# COM interop but seems it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.