Question about python openpyxl column.

Asked 2 years ago, Updated 2 years ago, 127 views

This is a question about Excel in Python.


import openpyxl

wb = openpyxl.load_workbook('C:\\*/**.xlsx')

ws = wb.active

col_A = ws['A']


for col in col_A:

    print(col.value)

This will output the entire column A well.

I brought the entire column A regardless of the row.

However, do not use the for statement I'm trying to import it to print(col.value) but it doesn't work well due to type or parameter error.

Please help me if I can't find the function that I don't provide.

python openpyxl excel column row

2022-09-21 12:39

1 Answers

for col in col_A:
    print(col.value)

In the above code, col_A is a list that has all the values in column A, and col means the values of the list that are referenced using the for statement.

The reason why error occurs when using col.value only without using for statement is

Because col is not declared.

I don't know because I've never used openpyxl, but there must be a way to refer to only certain values in a different way

Like the list, the method col_A[0].value may be possible.

I looked up ws.cell (row=row, column=column).It seems that it is possible to deliver the desired value to the row and column positions of the value.

I didn't give you a direct answer, but you can do it if you try a little more!


2022-09-21 12:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.