python讀取xls文件


#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/10/17 14:41
# @Author  : Sa.Song
# @Desc    : 
# @File    : read_xls.py
# @Software: PyCharm
import sys
from xlrd import open_workbook # xlrd用於讀取xld
import xlwt  # 用於寫入xls
workbook = open_workbook(r'C:\Users\songsa\Desktop\maoyan_comment.xls')  # 打開xls文件
sheet_name= workbook.sheet_names()  # 打印所有sheet名稱,是個列表
sheet = workbook.sheet_by_index(0)  # 根據sheet索引讀取sheet中的所有內容
sheet1= workbook.sheet_by_name('Sheet1')  # 根據sheet名稱讀取sheet中的所有內容
print(sheet.name, sheet.nrows, sheet.ncols)  # sheet的名稱、行數、列數
content = sheet.col_values(7)  # 第六列內容
print(content)

 

想了解更多Python關於爬蟲、數據分析的內容,歡迎大家關注我的微信公眾號:悟道Python

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM