python-3.x - “工作表”对象没有属性“max_col”
问题描述
我在其他项目中多次使用 max_col 属性,但不断收到错误'Worksheet' object has no attribute 'max_col'
我特别困惑,因为我在它上面使用了 max_row ,没有错误。我检查了文档,max_col 似乎仍然正确?
#!/usr/bin/python
# excelToCSV.py - Converts all excel files in a directory to CSV, one file
# per sheet
import openpyxl
import csv
import os
for excelFile in os.listdir('.'):
#Skip non-xlsx files, load the workbook object.
if excelFile.endswith('.xlsx'):
wbA = openpyxl.load_workbook(excelFile)
#Loop through each sheet in the workbook
for sheet in wbA.worksheets: #Note: changing wb to wb.worksheets
sheetName = sheet.title
sheetA = wbA.get_sheet_by_name(sheetName)
# Create the CSV filename from the excel filename and sheet title
excelFileStripped = excelFile.strip('.xlsx')
csvFilename = excelFileStripped + '_' + sheetName + '.csv'
# Create the csv.writer object for this csv file
csvFile = open(csvFilename, 'w', newline='')
csvWriter = csv.writer(csvFile)
# Loop through every row in the sheet
maxRow = sheetA.max_row
maxCol = sheetA.max_col
解决方案
属性max_column
不是max_col
(官方文档)
推荐阅读
- maven - Mocking of concrete class failing with Spock 2.0
- javascript - 安全地检查从另一个窗口发布的消息的来源
- c++ - 为什么我的数组以不正确的大小传递?
- json - 在 Thingsboard 仪表板中绘制 JSON 数据
- javascript - 您如何将用户 ID 从名称列表更改为不和谐的用户名和歧视?
- python - 在 Django for Windows 中运行 IBM DB2 连接的问题
- javascript - 未显示包含地点详细信息的信息窗口(Google Places API)
- mysql - 使数据库远程
- c++ - C ++将字符串与单词进行比较
- spring-batch - 春季批处理中的 XA 事务