title: Iterating xlsx files and removing unicode python openpyxl
body: <p>I'm trying to convert all of the excel files on my computer to CSV files (sheet by sheet).  Some of the .xlsx files are massive (over 100MB).  I'm still having a couple issues:
  <br> 1. My function to remove non-unicode characters is very slow
  <br> 2. I'm not sure that I'm using openpyxl's iteration properly, as I'm still using a lot of memory and am afraid that if I really let this thing run, it'll hit a memory error 
  <br> Also, looking for any coding help in general, as I'm still very new to code in general.</p>
  
  <pre><code>import csv
  from formic import FileSet
  from openpyxl import load_workbook
  import re
  from os.path import basename
  import os
  import string
  
  
  def uclean(s): # Clean out non-unicode chars for csv.writer - SLOW
      try:
          return ''.join(char for char in s if char in string.printable).strip()
      except:
          return ''
  
  def fclean(s): # Clean out non-filename-safe chars
      return ''.join([c for c in s if re.match(r'\w', c)])
  
  xlsx_files = FileSet(directory='C:\\', include='**\\*.xlsx') # the whole computer's excel files
  for filename in xlsx_files:
      wb = load_workbook(filename, use_iterators=True, read_only=True)  # This is still using &gt; 600 MBs
      for sheet in wb.worksheets:
          i = wb.worksheets.index(sheet)
          bf = os.path.splitext(
              basename(filename))[0]
          sn = fclean(str(wb.get_sheet_names()[i]))
          f = bf + '_' + sn + '.csv'
          if not os.path.exists(f):
              with open(f, 'wb') as outf:
                  out_writer = csv.writer(outf)
                  for row in sheet.iter_rows():
                      out_writer.writerow([uclean(cell.value) for cell in row])
  </code></pre>