C # Instrument data file parsing-excel file (xls, xlsx)

Source: Internet
Author: User

Many instrument workstations can export data as Excel files, including 97-2003 versions of XLS files and 2007+ xlsx files.

Collecting Excel files is easier than capturing PDF files, and the program is more robust, after all, the data in Excel has a clear definition of rows and columns, which facilitates data parsing.

The format of the earlier XLS file in Excel and later the xlsx file is not the same, XLS is a binary-specific format file, and xlsx is a zip-compressed package where the data is defined using XML. Although the two file format definitions are different, parsing the file data can be done through the middleware, so as long as you understand the concepts of the Excel file's workbooks, sheet pages, rows, columns, cells, and so on, you do not need to know the details of how their files are defined.

The common ways to collect Excel file data are:

1. Through OLE DB, the Excel file is queried as a database to obtain the data;

2. Use the MS Excel application to read Excel file data;

3. Use the WPS application to read;

4. Use other Office software to read;

5. Use MS Open XML to read;

6. Use the Npoi component to read;

7 .....

There are many ways, but there are pros and cons, such as the MS Excel application has a copyright problem, WPS and other applications even if free also need to install, in addition, through the application of DCOM calls to configure permissions;

Without an application, the components that use XML to read Excel, such as Npoi, MS Open XML, generally only support Excel 2007+, after all, the version of Excel file is XML;

Npoi, however, can read XLS and xlsx files and operate in the same way.

The following code opens an Excel file and reads its sheet page, row, cell value:

FileStream FileStream = new FileStream (FileName, FileMode.Open, FileAccess.Read); xssfworkbook = new Xssfworkbook ( FileStream); Isheet sheetat = Xssfworkbook.getsheetat (num); IRow row = Sheetat.getrow (rownum); Icell cell = row. Cells[index];

 

C # Instrument data file parsing-excel file (xls, xlsx)

Related Article

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.