This project has moved. For the latest updates, please go here.

How to read two tables from Excel with C#?

Apr 29, 2014 at 12:28 PM
Edited Apr 29, 2014 at 12:36 PM
Hi all. I have an exercise, to create a program with C# Windows Form, which could convert TWO tables from Excel to a single XML document. I have been writing this problem in about 7 forums (for example: http://www.dreamincode.net/forums/topic/345648-multiple-tables-conversion-from-excel-xls-file-to-xml-with-openxml/), but with no futher luck. But I get a comment, which advices me to use ClosedXML as my main library (I used pure OpenXML, which is very hard to learn and work with).

I was reading a documentation in here, but I didn't really get it, how to actually read two tables in Excel with C# using ClosedXML? My spreadhseet lokks like this:

Image

I need to read those TWO tables in C#, and when, basically, convert them to XML file.

I was thinking that first of all I need to get the actual sheet ( var ws = wk.Worksheet("Sheet1"); ). When somehow I need to define the ranges for both tables (this is how I thinking but don't know how to actually do it).

So the question is how to read those two tables from Excel using C# ClosedXML library? Thank you.
Coordinator
Apr 29, 2014 at 4:34 PM
worksheet.Table(stringTableName)
worksheet.Table(int32TableIndex)
worksheet.Tables = collection of tables in the worksheet