0

in openpyxl, when I try to find out the length of a specific column, I get the length of the longest column . how do I determine the length of a certain column

```python
from openpyxl import load_workbook
file_name = "spreadsheet.xlsx"
wb = load_workbook(file_name)
sheet = wb.active #grab the first active sheet
print("length of column A is", len(sheet["A"])) # expected answer 1
print("length of column B is", len(sheet["B"])) # expected answer 3
print("length of column C is", len(sheet["C"])) # expected answer 2
```

here is the output of the code

```output
length of column A is 3
length of column B is 3
length of column C is 3
```

this is the excel spreadsheet I used.

if openpyxl doesn't have a feature to do this, is there any other librarry that can be used?

  • Read the Entire Column as list and find its length, then it will give you the correct answer – Vignesh Jun 23 '20 at 07:40
  • 1
    Please don't post images of your code, instead, try pasting the code directly in here, formatted within codeblocks – Chase Jun 23 '20 at 07:53
  • Does this answer your question? [How to find the last row in a column using openpyxl normal workbook?](https://stackoverflow.com/questions/33541692/how-to-find-the-last-row-in-a-column-using-openpyxl-normal-workbook) – Charlie Clark Jun 23 '20 at 09:15

0 Answers0