E
E
Elena Yakimets2020-11-04 18:04:35
Python
Elena Yakimets, 2020-11-04 18:04:35

How to write a function in Python for an Excel file?

Good evening!
I'm learning Python and currently working with Excel.
I have an excel file, I have already learned how to print the sheet name:

from openpyxl import load_workbook
filename = "data.xlsx"
if __name__ == "__main__":
wb = load_workbook(filename)
print(wb.sheetnames)

Now I need to write a function that will take the cell number and values ​​and make changes to the file by the cell number, if there are experts, please help! I study myself, there is no one to ask my friends (((Help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zexer, 2020-11-04
@zexer

Openpyxl can perform various operations on a cell, row, column, or all of these at the same time.
Depending on what you need to do, you need to delve into this particular functionality. Without specifics it is difficult to answer the question, study this library, there is excellent documentation, and there are many examples on the Internet

A
Alexey Nevazhny, 2020-11-04
@LeFroys

You can write / read a value from a cell, for example, in this way Accordingly, where sheet is the name of the sheet, row and column are the numbers of rows and columns. It's better to first plan the program you want to write, and then look for solutions for various parts of it. sheet.cell(row=1, column=1).value

E
Elena Yakimets, 2020-11-04
@ElenaMightyDoe

It turns out that I have an Excel file (the file is not loaded, but it consists of 2 columns), I have already made it so that I have user input in the cells ktk / am and DT, and the file is saved in the same way. Now we need a function for convenience, to write to a specific cell. To use multiple times

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question