Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 wrap_text with openpyxl. How to use documentation to resolve deprecation warning?
Hi All,

I run the following openpyxl command to wrap text in all rows after row 9. It works fine but throws a deprecation warning. I'd love to figure out how to use documentation such as to determine the current, non-deprecated, way to wrap_text. But I always find the documentation confusing and unhelpful. For example, if I search for wrap_text I get this:

But that tells me nothing about how to wrap text. Do I simply not know how to use the documentation? Is there some great mystery I am to unravel so I don't have to endlessly google for examples on how to use openpyxl? How does one look at such documentation and figure out out how to wrap_text in a cell?

Here is the code:
from openpyxl import load_workbook
from openpyxl.styles import Alignment

file1 = "C:\\folder\\inputFile1.xlsx"
ws =
for rows in ws.iter_rows(min_row=10, max_row=None, min_col=None, max_col=None):
    for cell in rows:
       cell.alignment =  cell.alignment.copy(wrapText=True)'C:\\folder\file1_wrap.xlsx')    
here is the deprecation warning:
C:\Users\Jcurran\AppData\Local\Continuum\anaconda3\lib\site-packages\ DeprecationWarning: Call to deprecated function copy (Use copy(obj) or cell.obj = cell.obj + other).
# Remove the CWD from sys.path while we load stuff.

How might I figure out the way to find the information required to use the current (non-deprecated) approach to wrapping text in cells via the documentation at

I am using Jupyter for my environment. Shift tab or tab doesn't give me anything useful.

Any suggestions? I crave self sufficiency but can't grasp how to navigate the documentation for answer. There must be some clue somewhere? Some source code perhaps that I do not know how to locate?
because they advise you to use copy.copy()

look also
Through sheer trial and error I got this to work. But I'd like to understand how I can approach without trial and error:

from openpyxl import load_workbook
from openpyxl.styles import Alignment

HISorigFile = "C:\\Users\\Jcurran\\OneDrive - Wolters Kluwer\\Desktop\\Desktop\\weekly reports draft\\Inpatient HIS Use by Vendor Live Only Landscape Margins Width Freeze Filter.xlsx"
ws =
for rows in ws.iter_rows(min_row=10, max_row=None, min_col=None, max_col=None):
    for cell in rows:
        cell.alignment = Alignment(wrapText=True)


OK. So I should not be looking at openpyxl docs I should be looking at python docs for copy and deprecation I guess. I am trying to understand how you knew to look there.

the deprecation warning says:

(Use copy(obj) or cell.obj = cell.obj + other).

But I don't understand how you took that warning and then determined that copy.copy is the new approach.

Of course through trial and error I got this to work with no copy or copy.copy.

cell.alignment = Alignment(wrapText=True)
but this does not work:

cell.alignment =  cell.alignment.copy.copy(wrapText=True)
as it gives this:

AttributeError: 'function' object has no attribute 'copy'

So I still don't know how one approaches this through documentation and not rely on trial and error.
(Oct-09-2019, 11:54 AM)curranjohn46 Wrote: I am trying to understand how you knew to look there.
simply by reading the warning:
Use copy(obj) or cell.obj = cell.obj + other)

if you are still uncertain you can look also at the docs and source code

in the source you can see copy() method is more or less wrapper around copy.copy()
I learned that I did not have the latest openpyxl version. pip install openpyxl installed 2.5. I upgraded it to 3.0.
Now when I look at it makes more sense :-)

I now know that the "Working with Styles" section of the openpyxl 3.0 documentation is the place to go for formatting data.

So I click that, and go to

That page show me this:

>>> alignment=Alignment(horizontal='general',
... vertical='bottom',
... text_rotation=0,
... wrap_text=False,
... shrink_to_fit=False,
... indent=0)

and I could use that info to wrap text with this line:
cell.alignment = Alignment(wrapText=True)
Now things are starting to make sense for me. :-) Thanks!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Need help to resolve this MK2020 1 260 Mar-28-2020, 05:04 AM
Last Post: SheeppOSU
  Python Script to Produce Difference Between Files and Resolve DNS Query for the Outpu sultan 2 524 May-22-2019, 07:20 AM
Last Post: buran
  How to resolve 404 returned from web method when not running on localhost littleGreenDude 3 696 Feb-05-2019, 09:01 PM
Last Post: littleGreenDude
  function wanted: resolve relative path Skaperen 4 776 Sep-06-2018, 01:52 AM
Last Post: Skaperen

Forum Jump:

Users browsing this thread: 1 Guest(s)