Home > Enterprise >  Is there any function by which we can access the specific value from specific cell (excel) from Pyth
Is there any function by which we can access the specific value from specific cell (excel) from Pyth

Time:07-27

I have data in the excel file. So I want to add a three columns in python and add values which are - ["exam ID" : EXAM-001
"Subject" : Maths
"Date" : 30-07-2022]

I have hundreds of excel file and I don't want to hard code. I just want that the function/the code which directly access the value from the cell address of the excel file and display the output in the python.

I have also mentioned the expected result below -

enter image description here

Thanks in Advance !!!

CodePudding user response:

Yeah, you can use xlwings or pyxll. And you still can use the COM approach using the PyWin32 module.

But i suggest a better approach where you'll use EXCEL spreadsheets as a data input support (excel is a very good tool at manipulating and normalizing data). And use Python as your main scripting and data mining tool, that way you'll get a good separation of data and logic. Take a look for IPython, Pandas, numpy, openpyxl and the Anaconda python distribution. Hope it helps. Another Sollution: Excel is a sheet and cell based spreadsheet program which has a programming language included for more complex computations. In my experience the use of VB for Excel is not something most Excel users use.

I have seen attempts to coerce Excel into a full fledged Management tool with lots of VB behind the scenes but it did become an unholy mess, partially because the code was inextricably linked with the layout so even adding a new cell had ripple impacts, and partially because the VB had been organically grown by managers who ignored most of the good rules of design and programming.

Python on the other hand is a general purpose programming language, with no innate knowledge of cells or sheets or formulas or conditional formatting. You can use libraries from Python to build Excel spreadsheets, but Python can do so much more than that, where as Excel will only ever be a spreadsheet application (albeit a powerful one).

CodePudding user response:

There are plenty of libraries. I use openpyxl. Here you should be able to open the workbook, find specific cells wither by ID or by value, can add new cells, append.

https://openpyxl.readthedocs.io/en/stable/

Examples : https://www.softwaretestinghelp.com/python-openpyxl-tutorial/

  • Related