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

  • SEARCH
  • Home
  • 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 7672285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:15:02+00:00 2026-05-31T16:15:02+00:00

I’ve read a bunch of stuff on the web about how to get at

  • 0

I’ve read a bunch of stuff on the web about how to get at cell data using the OpenXML API. But there’s really not much out there that’s particularly straightforward. Most seems to be about writing to SpreadsheetML, not reading… but even that doesn’t help much.
I’ve got a spreadsheet that has a table in it. I know what the table name is, and I can find out what sheet it’s on, and what columns are in the table. But I can’t figure out how to get a collection of rows back that contain the data in the table.

I’ve got this to load the document and get a handle to the workbook:

SpreadsheetDocument document = SpreadsheetDocument.Open("file.xlsx", false);
WorkbookPart workbook = document.WorkbookPart;

I’ve got this to find the table/sheet:

Table table = null;
foreach (Sheet sheet in workbook.Workbook.GetFirstChild<Sheets>())
{
    WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheet.Id);
    foreach (TableDefinitionPart tableDefinitionPart in worksheetPart.TableDefinitionParts)
    {
        if (tableDefinitionPart.Table.DisplayName == this._tableName)
        {
            table = tableDefinitionPart.Table;
            break;
        }
    }
}

And I can iterate over the columns in the table by foreaching over table.TableColumns.

  • 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-31T16:15:03+00:00Added an answer on May 31, 2026 at 4:15 pm

    To read an Excel 2007/2010 spreadsheet with OpenXML API is really easy. Somehow even simpler than using OleDB as we always did as quick & dirty solution. Moreover it’s not just simple but verbose, I think to put all the code here isn’t useful if it has to be commented and explained too so I’ll write just a summary and I’ll link a good article. Read this article on MSDN, it explain how to read XLSX documents in a very easy way.

    Just to summarize you’ll do this:

    • Open the SpreadsheetDocument with SpreadsheetDocument.Open.
    • Get the Sheet you need with a LINQ query from the WorkbookPart of the document.
    • Get (finally!) the WorksheetPart (the object you need) using the Id of the Sheet.

    In code, stripping comments and error handling:

    using (SpreadsheetDocument document = SpreadsheetDocument.Open(fileName, false))
    {
       Sheet sheet = document.WorkbookPart.Workbook
          .Descendants<Sheet>()
          .Where(s => s.Name == sheetName)
          .FirstOrDefault();
    
       WorksheetPart sheetPart = 
          (WorksheetPart)(document.WorkbookPart.GetPartById(theSheet.Id));
    }
    

    Now (but inside the using!) what you have to do is just to read a cell value:

    Cell cell = sheetPart.Worksheet.Descendants<Cell>().
        Where(c => c.CellReference == addressName).FirstOrDefault();
    

    If you have to enumerate the rows (and they are a lot) you have first to obtain a reference to the SheetData object:

    SheetData sheetData = sheetPart.Worksheet.Elements<SheetData>().First();
    

    Now you can ask for all the rows and cells:

    foreach (Row row in sheetData.Elements<Row>())
    {
       foreach (Cell cell in row.Elements<Cell>())
       {
          string text = cell.CellValue.Text;
          // Do something with the cell value
       }
    }
    

    To simply enumerate a normal spreadsheet you can use Descendants<Row>() of the WorksheetPart object.

    If you need more resources about OpenXML take a look at OpenXML Developer, it contains a lot of good tutorials.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.