python操作excel

python操作excel

 

pip install openpyxl

  

写:

import openpyxl

# Load the workbook
workbook = openpyxl.load_workbook('path/to/file.xlsx')

# Select the worksheet
worksheet = workbook['Sheet1']

# Write data to the worksheet
worksheet['A1'] = 'Hello, world!'

# Save the workbook
workbook.save('path/to/file.xlsx')

  

读:

import openpyxl

# Load the workbook
workbook = openpyxl.load_workbook('path/to/file.xlsx')

# Select the worksheet
worksheet = workbook['Sheet1']

# Read the data from the worksheet
for row in worksheet.iter_rows(values_only=True):
    print(row)

  

 

 

 

######################

posted @ 2023-04-13 22:54  西北逍遥  阅读(19)  评论(0编辑  收藏  举报