python读取列数据_openpyxl读取所有列数据之columns属性

sheet的rows属性是一行行的输出数据,columns属性是一列列的输出数据,其返回值也是生成器。文档如下:If you need to iterate through all the rows or columns of a file, you can instead use the Worksheet.rows property or the Worksheet.columns prope...
摘要由CSDN通过智能技术生成

sheet的rows属性是一行行的输出数据,columns属性是一列列的输出数据,其返回值也是生成器。文档如下:

If you need to iterate through all the rows or columns of a file, you can instead use the Worksheet.rows property or the Worksheet.columns property

# -*- coding: utf-8 -*-

from openpyxl import load_workbook

wb = load_workbook('test.xlsx',data_only=True)

for sheet in wb:

sheet_name = sheet.title

# 生成器

data_all = sheet.columns

print('sheet名:',sheet_name)

print(data_all)

sheet名: 上海

sheet名: 杭州

直接遍历生成器或者将其转为元组,单元格的value属性来输出单元格值

# -*- coding: utf-8 -*-

from openpyxl import load_workbook

wb = load_workbook('test.xlsx',data_only=True)

for sheet in wb:

sheet_name = sheet.title

# 生成器

data_all = sheet.columns

print('sheet名:',sheet_name)

# 生成器转为元组

d

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值