读取workbook中的数据
时间: 2024-05-12 14:20:57 浏览: 65
数据读取
5星 · 资源好评率100%
要读取workbook中的数据,需要使用Python的第三方库,例如openpyxl或xlrd。
使用openpyxl库读取workbook中的数据:
```python
import openpyxl
# 打开workbook
workbook = openpyxl.load_workbook('example.xlsx')
# 获取worksheet
worksheet = workbook.active
# 遍历worksheet的所有行和列
for row in worksheet.iter_rows():
for cell in row:
print(cell.value)
```
使用xlrd库读取workbook中的数据:
```python
import xlrd
# 打开workbook
workbook = xlrd.open_workbook('example.xlsx')
# 获取worksheet
worksheet = workbook.sheet_by_index(0)
# 遍历worksheet的所有行和列
for row in range(worksheet.nrows):
for col in range(worksheet.ncols):
print(worksheet.cell(row, col).value)
```
阅读全文