OPENXML 2.0 Reading Excel

Source: Internet
Author: User

There are 7 types of data in Excel cells:

Boolean, Date, Error, inlinestring, number, sharedstring, String

Read the source code:

1list<string> returnlist =Newlist<string>();2             using(Spreadsheetdocument spreadsheetdocument = spreadsheetdocument.open (filename,false))3             {4                 foreach(Sheet SheetinchSpreadsheetdocument.workbookpart.workbook.descendants<sheet>())5                 {6 Returnlist.add (sheet. Name);7                 }8 9                 foreach(Sheet SheetinchSpreadsheetdocument.workbookpart.workbook.descendants<sheet>())Ten                 { Oneienumerable<sheet> Ienumerablesheet = spreadsheetdocument.workbookpart.workbook.descendants<sheet> (). Where (s = = S.name = =sheet. Name); AWorksheetpart Worksheetpart =(Worksheetpart) spreadsheetDocument.WorkbookPart.GetPartById (Ienumerablesheet.first (). ID); -ienumerable<row> rows = worksheetpart.worksheet.descendants<row>(); -Sharedstringtable sharedstringtable =spreadsheetDocument.WorkbookPart.SharedStringTablePart.SharedStringTable; the                     foreach(Row rowinchrows) -                     { -                         foreach(Cell cellinchRow. Descendants<cell>()) -                         { +                             if(Cell. Childelements.count = =0) -                             { +  A                             } at                             Else -                             { -                                 if(Cell. DataType! =NULL) -                                 { -                                      //get the shared data type -                                     if(Cell. Datatype.value = =cellvalues.sharedstring) in                                     { -                                        stringCellvalue = sharedstringtable.childelements[int. Parse (cell. Cellvalue.innertext)]. InnerText; to Returnlist.add (cellvalue); +                                     } -                                 } the                             } *  $                         }Panax Notoginseng                     } -                 } the                 returnreturnlist; +}

where bool type data 0 is processed to false 1 is processed to true;

The most difficult data to deal with is time date;

Only shared data is currently processed because of job requirements

OPENXML 2.0 Reading Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.