title: Use OpenPyXL to iterate through sheets and cells, and update cells with contantenated string
body: <p>I would like to use OpenPyXL to search through a workbook, but I'm running into some issues that I'm hoping someone can help with. </p>
  
  <p>Here are a few of the obstacles/to-dos: </p>
  
  <ul>
  <li>I have an unknown number of sheets &amp; cells</li>
  <li>I want to search through the workbook and place the sheet names in an array</li>
  <li>I want to cycle through each array item and search for cells containing a specific string</li>
  <li>I have cells with UNC paths that reference an old server. I need to extract all the text after the server name within the UNC path, update the server name, and contatenate the remaining text back on the server name <br>
  <strong>e.g. \file-server\blah\blah\blah.xlsx; extract \file-server\; replace with \file-server1\; put remaining blah\blah\blah.xlsx after new name.</strong></li>
  <li>Save xlsx document</li>
  </ul>
  
  <p>I'm new to Python, so would someone be able to point me in the right direction? Sample code is appreciated, because all I know how to do at this point is search through a known workbook, with known sheet names, and then print the data. I don't know how to include wildcards when iterating through worksheets &amp; cells. </p>
  
  <p>What I've done to show the contents of the cells: </p>
  
  <pre><code>from openpyxl import load_workbook, worksheet
  
  def main():
      #read workbook to get data
      wb = load_workbook(filename = 'Book1_test.xlsx', use_iterators = True)
      ws = wb.get_sheet_by_name(name = 'Sheet1')
      #ws = wb.worksheets
  
      #Iterate through worksheet and print cell contents
      for row in ws.iter_rows():
          for cell in row:
              print cell.value
  
      #Iterate through workbook &amp; print worksheets     
      #for sheet in wb.worksheets:
      #    print sheet
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>-----------------------Update-------------------------</p>
  
  <p>I'm able to search through the cells and extract the server name from the cell, but I I'm not able to save the spreadsheet because I'm in read only mode. When I try to switch to optimized_write=True I get the error: </p>
  
  <p>AttributeError: 'ReadOnlyCell' object has no attribute 'upper'</p>
  
  <p>Here's my code: </p>
  
  <pre><code>from openpyxl import load_workbook, worksheet, Workbook
  
  def main():
      #read workbook to get data
      wb = load_workbook(filename = 'Book1_test.xlsx', use_iterators = True)
      ws = wb.get_sheet_by_name(name = 'Sheet1')
      #ws = wb.worksheets
  
      #Iterate through worksheet and print cell contents
      for row in ws.iter_rows():
          for cell in row:
              cellContent = str(cell.value)
              #Scans the first 14 characters of the string for the server name
              if cellContent[:14] == '\\\\file-server\\':
                  #open workbook in write mode?
                  wb = Workbook(optimized_write=True)
                  ws = wb.create_sheet()
  
                  #update cell content
                  ws[cell] = '\\\\file-server1\\' + cellContent[14:]
                  print cellContent[:14]
  
                  #save workbooks
                  wb.save('Book1_test.xlsx')
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p><strong>Does anyone know how to update cell contents?</strong></p>