title: PyQt: QTableWidget to .xls file
body: <p>So, I have a QTableWidget that I want to save it to an .xls file using the xlwt module...</p>
  
  <p>Here's the code:</p>
  
  <pre><code>def savefile(self):
          filename = unicode(QtGui.QFileDialog.getSaveFileName(self, 'Save File', '', ".xls(*.xls)"))    
          wbk = xlwt.Workbook()
          self.sheet = wbk.add_sheet("sheet")
          self.row = 0
          self.col = 0
          self.add2(self.row, self.col)
          wbk.save(filename)    
  
  
  def add2(self, row, col):
      for i in range(self.tableWidget.columnCount()):
          for x in range(self.tableWidget.rowCount()):
              try:
                  teext = str(self.tableWidget.item(row, col).text())
                  self.sheet.write(row, col, teext)
                  row += 1
              except AttributeError:
                  pass                   
          col += 1
  </code></pre>
  
  <p>But that writes out only the text from cell 0,0 and nothing else...</p>
  
  <p>I think that I have made some serious mistake...</p>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>def savefile(self):
          filename = unicode(QtGui.QFileDialog.getSaveFileName(self, 'Save File', '', ".xls(*.xls)"))    
          wbk = xlwt.Workbook()
          self.sheet = wbk.add_sheet("sheet", cell_overwrite_ok=True)
          self.add2()
          wbk.save(filename)    
  
  
  def add2(self):
      row = 0
      col = 0         
      for i in range(self.tableWidget.columnCount()):
          for x in range(self.tableWidget.rowCount()):
              try:             
                  teext = str(self.tableWidget.item(row, col).text())
                  self.sheet.write(row, col, teext)
                  row += 1
              except AttributeError:
                  row += 1
          row = 0
          col += 1             
  </code></pre>
  
  <p>Solved the problem...</p>