Python imports data from Microsoft Excel files

Source: Internet
Author: User

The suffixes in Excel are CSV and XLS, and the differences are as follows:
1. The XLS file is the file format for Microsoft Excel spreadsheets.
2, CSV is the most common file format, it can be easily imported into a variety of PC tables and databases. This file, which is a row of the data table. The generated data table fields are separated by commas.
CSV is a text file that can be opened with Notepad, and XLS is a binary file that can only be played with Excel
A CSV file is an ASCII file that separates each field column with a comma-delimited symbol.
The CSV (*.csv) file format can save only the text and values displayed by cells in the active worksheet. All data rows and characters in the worksheet are saved.
The data columns are separated by commas, and each row of data ends with a carriage return. If a cell contains a comma, the contents of the cell are enclosed in double quotation marks.

In the previous section we had a good ability to import CSV files, but the XLS file would be cumbersome to import one by one. So today's handsome little flower will teach you how to read Excel files.

Step One:

Import the XLRD module. XLS file read library, readable only. If the write, to use XLWT, meaning: xls file write storage. You can implement a read of a specified form, a specified cell.

Step Two:

Finds the worksheet by name, reading the contents of the cell based on the number of rows (nrows) and the number of columns (ncols). It uses a For loop, first locks the first line, and then one, calls Ws.cell (R,C). Value reads the data for each cell, connected to the data list.

The code is as follows:

Python imports data from Microsoft Excel files

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.