0
点赞
收藏
分享

微信扫一扫

Python-----获取excel的所有sheet页,并获取每个sheet页的内容

问题:获取如下excel中的所有sheet页,并且获取到每个sheet页中内容

Python-----获取excel的所有sheet页,并获取每个sheet页的内容_打开文件

 

 

Python-----获取excel的所有sheet页,并获取每个sheet页的内容_数据_02

 

代码的实现如下:

#!/usr/bin/env python
# coding = UTF-8
#Author:Lucky,time:2020/10/27

from xlrd import open_workbook

file_name = "/Users/lucky/Documents/area_biao.csv"

def getdatafromtable(file_name):
table=open_workbook(file_name) #打开文件
get_sheets = table.sheet_names() #获取excel的sheet页的名称,全部打印出来
print(get_sheets)
for i in get_sheets:
get_each_sheet = table.sheet_by_name(i) #获取到每个sheet页的名称,单独打印
print("________________________________________")
print(get_each_sheet.name)
count_rows = get_each_sheet.nrows #获取到当前sheet页的总行数
print(count_rows)
for j in range(count_rows):
# 返回该行所有单元格的数据组成的列表
col_values = get_each_sheet.row_values(j, start_colx=0, end_colx=None)
print(col_values)
getdatafromtable(file_name)

打印结果如上的截图所示

     1.作者:Syw

2,本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

3.如果文中有什么错误,欢迎指出。以免更多的人被误导。



举报

相关推荐

0 条评论