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 6044957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:04:17+00:00 2026-05-23T07:04:17+00:00

I am creating Excel using DocumentFormat.OpenXml in ASP.Net. Can anybody have idea how can

  • 0

I am creating Excel using DocumentFormat.OpenXml in ASP.Net.

Can anybody have idea how can create Multiple worksheet in Excel.

For ex. Sheet1, Sheet2, Sheet3…… sheetn

  • 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-23T07:04:17+00:00Added an answer on May 23, 2026 at 7:04 am

    Try the following method:

            /// <summary>
            /// Add a blank worksheet to the workbook
            /// </summary>
            /// <param name="workbookPart">Wookbook part</param>
            public static void InsertBlankWorksheet(WorkbookPart workbookPart)
            {
                // Add a blank WorksheetPart.
                WorksheetPart newWorksheetPart = workbookPart.AddNewPart<WorksheetPart>();
    
                // Create the new worksheet
                Worksheet worksheet = new Worksheet();
                worksheet.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
                SheetDimension sheetDimension1 = new SheetDimension() { Reference = "A1" };
    
                SheetViews sheetViews1 = new SheetViews();
                SheetView sheetView1 = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
    
                sheetViews1.Append(sheetView1);
                SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties() { DefaultRowHeight = 15D };
                SheetData sheetData1 = new SheetData();
                PageMargins pageMargins1 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
                PageSetup pageSetup1 = new PageSetup() { Orientation = OrientationValues.Portrait, Id = "rId1" };
    
                worksheet.Append(sheetDimension1);
                worksheet.Append(sheetViews1);
                worksheet.Append(sheetFormatProperties1);
                worksheet.Append(sheetData1);
                worksheet.Append(pageMargins1);
                worksheet.Append(pageSetup1);
    
                newWorksheetPart.Worksheet = worksheet;
                newWorksheetPart.Worksheet.Save();
    
                Sheets sheets = workbookPart.Workbook.GetFirstChild<Sheets>();
                string relationshipId = workbookPart.GetIdOfPart(newWorksheetPart);
    
                // Get a unique ID for the new worksheet.
                uint sheetId = 1;
                if (sheets.Elements<Sheet>().Count() > 0)
                {
                    sheetId = sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1;
                }
    
                // Give the new worksheet a name.
                string sheetName = "Sheet" + sheetId;
    
                // Append the new worksheet and associate it with the workbook.
                Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
                sheets.Append(sheet);
                workbookPart.Workbook.Save();
            }
    

    EDIT

    Here is the class that contains the method:

    public static class ExcelHelpers
    {
        public static void InsertBlankWorksheet(WorkbookPart workbookPart)
        {...}
    }
    

    Open up your excel document like this and call the method:

    public static void Export(string document)
    {
        using (SpreadsheetDocument doc = SpreadsheetDocument.Open(document, true))
        {
            ExcelHelpers.InsertBlankWorksheet(doc.WorkbookPart);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.