python - Excel表格

from openpyxl import load_workbook

wb = load_workbook(r'C:\Users\admin\Desktop\数据筛选.xlsx')

# print(wb.get_sheet_names())

# 数据表1
sheet = wb.get_sheet_by_name('Sheet1')
# print(a1_sheet)

# b1 = a1_sheet['B1']
# 列数,行数,数值
# print(b1.column,b1.row,b1.value)

# c1 = a1_sheet.cell(row=1,column=3)
# print(c1.value)

# 最大行,最大列
# print(sheet.max_row)
# print(sheet.max_column)

# 所有行
# for row in sheet.rows:
#     for cell in row:
#         print(cell.value)

# 所有列
# for column in sheet.columns:
#     for cell in column:
#         print(cell.value)

# 哪一行
# for cell in list(sheet.rows)[0]:
#     print(cell.value)

# 哪一列
for cell in list(sheet.columns)[3]:
    try:
        a1,a2,a3 = cell.value.split(' ')
        print(a1,a2,a3)
    except Exception as e:
        pass


# 获取一个矩阵
# for i in range(1, 4):
#     for j in range(1, 4):
#         print(sheet.cell(row=i, column=j).value)

# for row_cell in sheet['A1':'B3']:
#     for cell in row_cell:
#         print(cell)


# from openpyxl.utils import get_column_letter, column_index_from_string
# # 根据列的数字返回字母
# print(get_column_letter(2)) # B
# # 根据字母返回列的数字
# print(column_index_from_string('D')) # 4

# --------------------------------------------------------------

# 写入数据

#
sheet['D14'] = a1
from openpyxl import Workbook
# 创建一个新的表
# wb = Workbook()

# 创建一个新的工作区 # wb.create_sheet(
'Data', index=1) # wb.save(r'C:\Users\admin\Desktop\数据筛选2.xlsx') # wb.close() # # 删除某个工作表 # wb.remove(sheet) # del wb[sheet]

 

相关文章:

https://www.cnblogs.com/276815076/p/8028127.html

转载于:https://www.cnblogs.com/Anec/p/10657998.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值