question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can you Quickly Get the Worksheet Names?

See original GitHub issue

Do you want to request a feature or report a bug?

  • [] Bug
  • Feature

Version of ClosedXML

0.94.2

What is the current behavior?

When I want to get all names of the WorkSheets I create a new XLWorkbook and then iterate over the worksheets to get their names. My Excel File is rather big and it takes some time to create a XLWorkbook just for reading the sheetnames. I wonder if there is a way to just read the sheetnames without loading the whole content for better performance.

What is the expected behavior or new feature?

Get all sheetnames without reading all of their content (quick access).

Reproducibility

Code to reproduce problem:

public void Main()
{
    var names = new List<string>();
    // Takes some time to load just to get sheet names...
    using (var wb = new XLWorkbook("File.xlsx"))
    {
        foreach (var sheet in wb.Worksheets)
        {
            names.Add(sheet.Name);
        }
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
igiturcommented, Feb 4, 2020

@igitur was faster again 😄

Only because my day job’s project is running unit tests for 15min and I’m idling while monitoring my Gmail inbox 😉

0reactions
ll9commented, Feb 4, 2020

Thanks you have pointed me towards the right direction. I have used OpenXML in order to acchieve my goal (takes 200ms compared to loading the whole workbook with closedXML in 4s). Here is the code for for anyone who is interested:

private static List<string> GetNamesNative()
{
    var names = new List<string>();

    using (var spreadSheetDocument = SpreadsheetDocument.Open(Path, false))
    {
        int sheetIndex = 0;
        foreach (var worksheetpart in spreadSheetDocument.WorkbookPart.WorksheetParts)
        {
            string sheetName = spreadSheetDocument.WorkbookPart.Workbook.Descendants<Sheet>().ElementAt(sheetIndex).Name;
            names.Add(sheetName);

            sheetIndex++;
        }
    }

    return names;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Quick Ways to Get a List of All Worksheet Names in an ...
Method 1: Get List Manually ... Next, press “Ctrl + C” to copy the name. ... Then, press “Ctrl + V” to paste...
Read more >
How To Generate A List Of Sheet Names From A Workbook ...
How To Generate A List Of Sheet Names From A Workbook Without VBA · Go to the Formulas tab. · Press the Define...
Read more >
How to Get All Worksheet Names in Excel (2 Easy Ways)
Getting Sheet Names in Excel Using Formula · Go to the Formulas tab and click on the Name Manager in the Defined Names...
Read more >
How to create a list of all worksheet names from a workbook?
Get a list of all worksheet names from a workbook with a useful feature · 1. Click Kutools Plus > Worksheet > Create...
Read more >
Microsoft Excel: Create an automated list of worksheet names
A. Yes, you can create a list of your Excel workbook's worksheet names as follows. From the Formulas tab, select Defined Names, Define...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found