In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about how to extract Excel text box content from Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
To tell you the truth, this demand is encountered for the first time, and I believe it is also the first time for most friends. "extract the contents of the excel text box", yes, you heard me correctly! I don't know if you've ever encountered it, but it's really a good question from a friend.
To be honest, there are many libraries for Python to manipulate excel, but I have hardly found an api to implement this requirement. For example, the openpyxl library I use most often doesn't have this feature either.
Finally, check it out, only xlwings this library! The latest version! The latest version! Otherwise, there are some methods you can't use.
# Open the cmd window and install the xlings library pip install xlwings # before using the xlwings library, you need to import the relevant knowledge of the import xlwings as xwxlwings library in advance
First, the xw.App () we see is a function in the xlwings library.
Xw.App (visible=False,add_book=False)
Where:
Visible:True indicates that the program window is displayed after starting the excel program. If False, the program window runs in the background after the excel program is started
Add_book:True means to create a new blank workbook after starting the excel program. If False, the workbook will not be created after starting the excel program
App.books.open (file path)
The above function is used to help us open the workbook, which has a parameter passed in the path of the local excel, which is used to open the local workbook.
Complete code
Because this article only gives a brief introduction to the use of the xlwings library, some properties and methods are similar to openpyxl, so I won't go into detail here. The Excel text box is as follows:
Go directly to the code:
Import xlwings as xw app = xw.App (visible=False,add_book=False) wb = app.books.open ('test1.xlsx') for sheet in wb.sheets: for shape in sheet.shapes: if "TextBox" in shape.name: print (shape.text) # make sure the latest version of xlwings, the old version does not have the text method wb.close () app.quit ()
The results are as follows:
Of course, this is for a certain table, master the method, give you multiple tables, is not just a loop to read it?
The above is the editor for you to share the Python how to extract Excel text box content, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.