python - Excel表格

时间:2023-03-09 16:49:12
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=,column=)
# 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)[]:
# print(cell.value) # 哪一列
for cell in list(sheet.columns)[]:
try:
a1,a2,a3 = cell.value.split(' ')
print(a1,a2,a3)
except Exception as e:
pass # 获取一个矩阵
# for i in range(, ):
# for j in range(, ):
# 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()) # B
# # 根据字母返回列的数字
# print(column_index_from_string('D')) # # -------------------------------------------------------------- # 写入数据

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

# 创建一个新的工作区
# wb.create_sheet('Data', index=)
# 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