“工作表"对象没有属性“max_col" [英] 'Worksheet' object has no attribute 'max_col'
本文介绍了“工作表"对象没有属性“max_col"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在其他项目中多次使用 max_col 属性,但不断收到错误 'Worksheet' object has no attribute 'max_col'
I have used the max_col attribute numerous times in other projects, but keep getting the error 'Worksheet' object has no attribute 'max_col'
我特别困惑,因为我在它的正上方使用了 max_row,没有错误.我查了文档,max_col 好像还是正确的?
I'm especially confused because I use max_row right above it, with no error. I checked the documentation, and max_col still seems to be correct?
#!/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
(官方文档)
The attribute is max_column
not max_col
(official documentation)
这篇关于“工作表"对象没有属性“max_col"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文