title: Insert an image into Excel with openpyxl
body: <p>My PC crashed and so I had to reinstall all of my libraries; after finishing the install, I realized that some libraries updated to a new version and my code no longer works (due to a new version of openpyxl).</p>
  
  <p>I am trying to insert an image into an Excel file, but I do not understand the error messages that are occurring. Other questions seem to be for older versions of openpyxl (for which my original code worked), but do not work for the current version of openpyxl. Your assistance in helping me understand how to fix my code is appreciated. :)</p>
  
  <p>Original code (which works):</p>
  
  <pre><code>import openpyxl
  wb = openpyxl.load_workbook(filename)
  ws = wb.get_sheet_by_name(sheet_name)
  img = openpyxl.drawing.image.Image(img_name)
  img.anchor(ws['D2'])
  ws.add_image(img)
  wb.save(filename)
  </code></pre>
  
  <p>Current code (which doesn't work):</p>
  
  <pre><code>import openpyxl
  wb = openpyxl.load_workbook(filename)
  ws = wb[sheet_name]
  img = openpyxl.drawing.image.Image(img_name)
  img.anchor(ws.cell(row=2,column=4))
  ws.add_image(img)
  wb.save(filename)
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-5-9efc1289cc73&gt; in &lt;module&gt;()
  ----&gt; 1 img.anchor(ws.cell(row=2,column=4))
  
  TypeError: 'str' object is not callable
  </code></pre>
  
  <p>Any hints?</p>
  
  <p>Thanks</p>
  
  <p>EDIT: Apparently, img.anchor is now the string; I have no idea what it used to be but apparently was not a string (since there wasn't an error message. Changing to the following now sets the anchor, but I get a different error message.</p>
  
  <p>Sets anchor:</p>
  
  <pre><code>img.anchor = ws.cell(row=2,column=4)
  ws.add_image(img)
  </code></pre>
  
  <p>But it now crashes when trying to save:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-13-2cfd938ccf60&gt; in &lt;module&gt;()
        1 img.anchor = ws.cell(row=2,column=4)
        2 ws.add_image(img)
  ----&gt; 3 wb.save(filename)
  
  AttributeError: 'Cell' object has no attribute 'upper'
  </code></pre>