1. 程式人生 > >Python 讀寫xlsx

Python 讀寫xlsx

div excel 表格 修改 pos 讀寫 開發 int clas

# pip install openpyxl

# openpyxl只能用於處理xlsx,不能用於處理xls
from openpyxl import load_workbook

# 打開文件
ExcelFullName = ‘c://平臺軟件開發部工資報表(2017-6).xlsx‘
wb = load_workbook(ExcelFullName)

# 遍歷表格
for table in wb:
for row in range(1, table.max_row + 1):
for col in range(1, table.max_column + 1):
Data = table.cell(row=row, column=col).value
print(Data)

table.cell(row=1, column=1).value = ‘黃海的修改測試‘
wb.save(filename=ExcelFullName)

Python 讀寫xlsx