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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:09:29+00:00 2026-05-21T17:09:29+00:00

I need to get data from an Excel file to print them in a

  • 0

I need to get data from an Excel file to print them in a HTML table (using MVC, no gridview) and eventually store them in a Database.

The mapping between table and Excel is as follows:

Excel -> Table

First Row -> Table headers

Other Cells -> Table data

I am using the Interop.Excel library that provides methods to manipulate Excel files in .NET.

With this code I obtain in lworkSheet variable the Nth worksheet of the Excel file:

var lworkSheet = xlWorkBook.Worksheets.get_Item(N);

Let’s assume the Excel file has just one worksheet (N = 1), I can use worksheet specific properties to get Rows, Columns, Cells and Range. These properties return objects of type Interop.Excel.Range.

The problem is that Rows, Columns and Cells return, respectively, all the rows, columns and cells in the Excel file not just those that are filled with data. Therefore in order to get the data I do (the index of the Excel items are 1-based):

var lheaders = xlWorkSheet.Rows.get_Item(1);
var lexcelItems = new Excel.Range[xlWorkSheet.Rows.Count, xlWorkSheet.Columns.Count];

for (var i=0; i < xlWorkSheet.Rows.Count; i++)
{
    for(var j=0; j < xlWorkSheet.Columns.Count; j++)
    {
        lexcelItems[i,j] = xlWorkSheet.Cells.get_Item(i+2, j+1);
    }
}

Besides the computational waste of cycling all rows and columns, these solution is still not acceptable because the get_Item() method returns Range objects!! In order to get the item in the cell I have to use the get_Range(cell_start, cell_end) method and specify the cells in the “A1”, “A2”, etc… format.

QUESTIONS:

1) Any way to identify last item in row and column?

2) Any way to get the value in the cell without specify the range?

3) Any library that implements the Excel.Range increment? (i.e. (A1++) == A2, etc…).

4) If none of the above is feasible, is there an easy way to read Excel with OLEDB?

Thanks

Francesco

  • 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-21T17:09:30+00:00Added an answer on May 21, 2026 at 5:09 pm

    Haven’t worked with this library so I’m just making an educated guess from the MSDN documentation. Are you looking for Worksheet.UsedRange?

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._worksheet.usedrange(v=office.11).aspx

    Once you have the Range, it looks like you can use the Range.Cells property (analogous to the Worksheet.Cells property you’re using) to get a range of a single cell and then use the Range.Value or Range.Value2 property to get that cell’s value:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range_properties(v=office.11).aspx

    To specify the cells within the UsedRange based on position rather than row/column names, use Range.Offset:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range(v=office.11).aspx

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

Sidebar

Related Questions

I'm trying to read an excel file from C# using COM, and can get
I need to figure out how to get the data from D3D textures and
I often have data in Excel or text that I need to get into
I have developed a VB.Net code for retrieving data from excel file .I load
I need to export data from a table in database A, then import it
I need to get data from a database and I need to spit out
I need to get json data from an external domain. I used WebRequest to
I need to get summary data from many many rows. The summary fields are
I have a program that takes data from an excel file and manipulates it
We need to get data out of an older accounting system. We have received

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.