Aspose. Cells reads an excel file, aspose. cellsexcel

Source: Internet
Author: User

[Convert] Aspose. Cells reads the excel file, aspose. cellsexcel

 

Aspose is a powerful control that can be used to operate files such as word, excel, and ppt files. It is very convenient to use this control to import and export data. Among them, Aspose. Cells is used to operate Excel and has many functions. I use the most basic function to read Excel Data and import it to Dataset or database. The code for reading data from an Excel table is as follows:
First introduce the namespace: using Aspose. Cells;

Workbook workbook = new Workbook (); workbook. open ("C: \ test.xlsx"); Cells cells = workbook. worksheets [0]. cells; for (int I = 0; I <cells. maxDataRow + 1; I ++) {for (int j = 0; j <cells. maxDataColumn + 1; j ++) {string s = cells [I, j]. stringValue. trim (); // read data in one row. You can also insert the database code here }}

  

Returned Datatable:

Cells cells = workbook. worksheets [1]. cells; System. data. dataTable ableable1 = cells. exportDataTable (1, 0, cells. maxDataRow, cells. maxColumn); // noneTitleSystem. data. dataTable ableable2 = cells. exportDataTableAsString (0, 0, cells. maxDataRow + 1, cells. maxColumn, true); // showTitle // ExportDataTableAsString prevents the field of the date type from being read into a numeric string, such as "4859.321"

  

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.