c# - How to read the firstSheet records from excel file -




i doing task, read data excel file using open xml sdk.

i can open excel sheet , read data. m struggling in reading first sheet fist time.. code starts reading data final sheet in excel file.

for example, excel file(records.xlsx) having 3 sheets(sheet1,sheet2 , sheet3). these 3 sheets having records.!st sheet having 10 records , 2nd sheet having 10 records , 3rd sheet having 10 records.

my code,at starting stage read data 3rd sheet records. want read records 1st sheet , go 2nsd , 3rs... that..

this code:

 list<string> materialdefinitionscolumnnames = new list<string>(); //used save each column values in single row.              spreadsheetdocument document = spreadsheetdocument.open(myfile, true);             sharedstringtable sharedstringtable = document.workbookpart.sharedstringtablepart.sharedstringtable;             string cellvalue = null;              foreach (worksheetpart worksheetpart in document.workbookpart.worksheetparts)             {                 foreach (sheetdata sheetdata in worksheetpart.worksheet.elements<sheetdata>())                     {                         foreach (row row in sheetdata.elements<row>())                         {                             foreach (cell cell in row.elements<cell>())                             {                                 cellvalue = cell.innertext;                                  if ((cell.innertext) != null)                                 {                                     if (cell.datatype == cellvalues.sharedstring)                                     {                                         materialdefinitionscolumnnames.add(sharedstringtable.elementat(int32.parse(cellvalue)).innertext);                                     }                                 }                             }                         }                     }              } 

i want read records first sheet. way , wrong code?. helps appreciated !! :)





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -