title: Openpyxl: Manipulation of cell values
body: <p>I'm trying to pull cell values from an excel sheet, do math with them, and write the output to a new sheet. I keep getting an ErrorType. I've run the code successfully before, but just added this aspect of it, thus code has been distilled to below:</p>
  
  <pre><code>import openpyxl
  
  #set up ws from file, and ws_out write to new file
  
  def get_data():
      first = 0
      second = 0
      for x in range (1, 1000):
          if ws.cell(row=x, column=1).value == 'string':
              for y in range (1, 10):            #Only need next ten rows after 'string'
  
                  ws_out.cell(row=y, column=1).value = ws.cell(row=x+y, column=1).value
  
                  second = first                             #displaces first -&gt; second
                  first = ws.cell(row=x+y, column=1).value/100     #new value for first
                  difference = first - second
  
                  ws_out.cell(row=x+y+1, column=1).value = difference    #add to output
              break
  </code></pre>
  
  <p>Throws a TypeError message:</p>
  
  <blockquote>
    <p>first = ws.cell(row=x+y, column=1).value)/100<br>
    TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'</p>
  </blockquote>
  
  <p>I assume this is referring to the ws.cell value and 100, respectively, so I've also tried:</p>
  
  <pre><code>first = int(ws.cell(row=x, column=1))/100 #also tried with float
  </code></pre>
  
  <p>Which raises:</p>
  
  <blockquote>
    <p>TypeError: int() argument must be a string or a number</p>
  </blockquote>
  
  <p>I've confirmed that every cell in the column is made up of numbers only. Additionally, openpyxl's cell.data_type returns 'n' (presumably for number as far as I can tell by the documentation).</p>
  
  <p>I've also tested more simple math, and have the same error.</p>
  
  <p>All of my searching seems to point to openpyxl normally behaving like this. Am I doing something wrong, or is this simply a limitation of the module? If so, are there any programmatic workarounds?</p>
  
  <p>As a bonus, advice on writing code more succinctly would be much appreciated. I'm just beginning, and feel there must be a cleaner way to write an ideas like this.</p>
  
  <p>Python 3.3, openpyxl-1.6.2, Windows 7</p>
  
  <hr>
  
  <p><strong>Summary</strong></p>
  
  <p>cfi's answer helped me figure it out, although I used a slightly different workaround. On inspection of the originating file, there was one empty cell (which I had missed earlier). Since I will be re-using this code later on columns with more sporadic empty cells, I used:</p>
  
  <pre><code>if ws.cell(row=x+r, column=40).data_type == 'n':
      second = first                             #displaces first -&gt; second
      first = ws.cell(row=x+y, column=1).value/100     #new value for first
      difference = first - second
  
      ws_out.cell(row=x+y+1, column=1).value = difference    #add to output
  </code></pre>
  
  <p>Thus, if a specified cell was empty, it was ignored and skipped.</p>