xlwings – Extract the contents of the excel text box 

What is xlwings

xlwings (Open Source) is a BSD-licensed Python library that makes it easy to call Python from Excel and vice versa.

Numpy arrays and Pandas Series/DataFrames are fully supported. xlwings-powered workbooks are easy to distribute and work on Windows and Mac.

Prerequisites

xlwings is only compatible with Windows and macOS because it requires the installation of Excel. UDFs (User Defined Functions) are presently not supported on macOS.

xlwings may now be installed on Linux servers and used with Google Sheets or Excel on the web since version 0.26.0.

xlwings requires at least Python 3.7.

Installation

using pip

pip install xlwings

or conda

conda install xlwings

Now come to the main point, to extracting textbox or any element from excel file you must use xlwings library.

This is my TestExcel.xlsx file where i have 2 textbox.

Now write a code to extract textbox value from excel sheet.

>>> import xlwings as xw 
>>> app = xw.App(visible=False,add_book=False)  
>>> wb = app.books.open('TestExcel.xlsx')  
>>> print(wb) 
<Book [TestExcel.xlsx]>
>>> for sheet in wb.sheets: 
...     print(sheet)
... 
<Sheet [TestExcel.xlsx]Sheet1>

In above code we can see the no. of sheet printed here. now we will print the textbox values

>>> wb = app.books.open('TestExcel.xlsx') :
>>> for sheet in wb.sheets:
...     for shape in sheet.shapes:
...             print(shape.text)
...



Key 1
Key 2
Key 3


Key 4



Key 1 Vaue 356894
Key 2 Value Test Value
Key 3  test value
Key 3 appended test value

This how you can extract shape’s value from excel file and store values into some variables.

That is it for today, hope it helps.
If you have any suggestion for this article please make a comment in comment section below.

If you like this article, you can buy me a coffee. Thanks!

xlwings – Extract the contents of the excel text box 

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top