Python reads excle file data

Source: Internet
Author: User

Python reads Excel, uses Google to search Python Excel, clicks the first result http://www.python-excel.org/, and can work with Excel across platforms.

Follow the documentation step-by-step to install three packages:

    • XLRD (for reading Excel);
    • XLWT (for writing Excel);
    • Xlutils (Toolbox for working with Excel)
1  fromXlrdImportOpen_workbook2 ImportRe3 4 #Create a generator to read sheet, generate each row of data sequentially, Row_count to specify how many rows to read, Col_count specify how many columns to read5 defReadsheet (S, Row_count=-1, col_cout=-1):#6     #How many lines does Sheet have?7nrows =s.nrows8     #Sheet How many columns are there?9Ncols =S.ncolsTenRow_count = (row_countifRow_count > 0Elsenrows) OneCol_count = (col_countifCol_count > 0Elsencols) ARow_index =0 -      whileRow_index <Row_count: -         yield[S.cell (Row_index, col). Value forColinchxrange (col_count)] theRow_index + = 1 -  -WB = Open_workbook ('Simple.xls')#Open Excel File - #Read all the sheet in Excel +  forSinchwb.sheets (): -      forRowinchReadsheet (S, 10, 10):#Read Only the first 10 rows of each sheet, the first 10 columns (of course you want to make sure that your data is more than 10 rows, and the extra 10 columns) +         PrintRow

Very simple, mainly used in Xlrd four features Open_workbook, Wb.sheets (), s.nrows-(number of rows), S.ncols-(Number of columns), S.cell (Row, col). value-(Gets the value at the specified unit).

These functions are sufficient for handling general read operations.

Python reads excle file data

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.