9

I am wondering how do I extract data out of a 2007 excel file? I am using asp.net mvc 3. My plan is to have a upload section that you choose a file and hit upload. I have no clue after that what kind of format it will be or what I need to do to extract the values out.

Thanks

4 Answers 4

12

Once you have the spreadsheet uploaded and you save it to a file on the web server it is quite easy to use LINQ to select the rows from the spreadsheet. Check this out for more info.

http://code.google.com/p/linqtoexcel/

Sign up to request clarification or add additional context in comments.

1 Comment

Super easy to use and has a nuget package as well.
4

The easiest way to read excel spread sheets IMO is to use a DataAdapter and an OleDB connection as shown in this code project sample. The good thing about this is it does not have any dependencies on COM or the MS office libraries.

Comments

3

For reading Excel files, I learned to love Koogra. It's an open source library that reads both xls and xlsx files, and is very easy to use.

http://sourceforge.net/projects/koogra/

Comments

1

I've used NPOI and it's quite simple to use:

Using Xlfile As FileStream = New FileStream(FileName, FileMode.Open, FileAccess.Read)
    Using XLBook As HSSFWorkbook = New HSSFWorkbook(Xlfile)
        Using XLSheet As NPOI.SS.UserModel.Sheet = XLBook.GetSheetAt(0)

            Dim CurrentRow As NPOI.HSSF.UserModel.HSSFRow
                        Dim CurrentCell As NPOI.SS.UserModel.Cell
                        Dim RowEnum As IEnumerator = XLSheet.GetRowEnumerator()

            While RowEnum.MoveNext
                          If (RowEnum.Current IsNot Nothing) Then
                              CurrentRow = TryCast(RowEnum.Current, NPOI.HSSF.UserModel.HSSFRow)
                    Select Case CurrentCell.CellType
                        Case NPOI.SS.UserModel.CellType.STRING
                            ' CurrentCell.StringCellValue
                        Case NPOI.SS.UserModel.CellType.NUMERIC
                            ' CurrentCell.NumericCellValue.ToString()
                    End Select
            End While
        End Using
    End Using
    Xlfile.Close()
End Using

4 Comments

I was looking at and found something called "Excel package" excelpackage.codeplex.com do you know if they still develop this?
@chobo2: Yes, I had tried that one a couple of years ago but then I've given up cause it seems that the project has been abandoned. I would suggest you to try NPOI cause it's really simple and it works. I reads and writes all excel versions.
@LeftyX: Is there is any way in NPOI to get all charts in excel sheet.
@PankajAgarwal: I am afraid I can't help. Have never done anything like that. I would suggest you to open a new question, anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.