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]

 

相关文章:html

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