OpenXml excel choose sheets

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi to all.
i have a function that open a excel file and copy the values of rows into a sql server
the problem is that my funtion choose only the fisrt sheet of hte excel.
now i want to choose whitch of the sheets to be inserted
my code:
using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(fileName, false)) { string seperator = ""; WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart; IEnumerable<Sheet> sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>(); string relationshipId = sheets.First().Id.Value; WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(relationshipId); Worksheet workSheet = worksheetPart.Worksheet; SheetData sheetData = workSheet.GetFirstChild<SheetData>(); IEnumerable<Row> rows = sheetData.Descendants<Row>();
foreach (Row row in rows) //this will also include your header row...
{
...
through sheets.Count() i know how many sheets i have and i have make a loop and insert items into listbox for (int i=0; i<sheets.Count(); i++)
{
sheetsLB.Items.Add(i.ToString());
}
how can i choose the relationshipId of each sheet i have checked?
thanks in advance

View the full article
 
Back
Top