Openpyxl "Numbers Stored as Text"
As you are getting Numbers Stored as Text error, I believe that the value you are adding in the Excel worksheet is String. Please confirm this by displaying type of your variable.
type(variable_name)
If it is <class'str'>
, then add int
while passing the variable to Excel sheet.
your_number = '412.5876'
ws['A1'] = float(your_number)
This should fix your problem.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on June 05, 2022Comments
-
Admin about 2 years
I've done some extensive searching on StackOverflow as well as many other sites and can't seem to find a solution that will work for me.
Background: - New to Python (and coding in general) - Using Pycharm w/ Openpyxl - I work a lot in Excel and have been trying to automate some small daily tasks using python to increase my understanding of the language
Situation: - I am trying to modify an existing xlsx sheet, and have been able to successfully change formatting like column width, zoom, etc. - However, I am really struggling with the dreaded "Numbers stored as text" scenario. There is a specific range of columns (Z:AZ) that always contain numbers, but they are stored as text by default.
Question: - Has anyone had experience converting text to numbers within an existing worksheet?
Any insight would be greatly appreciated!