qt - Paste entire column into QTableView from Excel -


i having issue pasting qtableview excel when user has copied selecting entire column in excel, putting every single row in selected column, entire excel sheet, on clipboard. following paste code qtableview (please note, in python using pyqt principle same c++).

def paste(self):         model=self.model()         pastestring=qtgui.qapplication.clipboard().text()          rows=pastestring.split('\n')         numrows=len(rows)         numcols=rows[0].count('\t')+1          selectionranges=self.selectionmodel().selection()          #make sure have 1 selection range , not non-contiguous selections         if len(selectionranges)==1:             topleftindex=selectionranges[0].topleft()             selcolumn=topleftindex.column()             selrow=topleftindex.row()             if selcolumn+numcols>model.columncount():                 #the number of columns have paste, starting @ selected cell, go beyond how many columns exist.                 #insert amount of columns need accomodate paste                 model.insertcolumns(model.columncount(), numcols-(model.columncount()-selcolumn))              if selrow+numrows>model.rowcount():                 #the number of rows have paste, starting @ selected cell, go beyond how many rows exist.                 #insert amount of rows need accomodate paste                 model.insertrows(model.rowcount(), numrows-(model.rowcount()-selrow))              #block signals "datachanged" signal setdata doesn't update view every cell set             model.blocksignals(true)                row in xrange(numrows):                 columns=rows[row].split('\t')                  [model.setdata(model.createindex(selrow+row, selcolumn+col), qvariant(columns[col])) col in xrange(len(columns))]              #unblock signal , emit datachangesd ourselves update view @ once             model.blocksignals(false)             model.datachanged.emit(topleftindex, model.createindex(selrow+numrows, selcolumn+numcols)) 

this works fine when user has selected bunch of cells in excel , copied those. breaks down when select entire column because pastestring becomes upwards of 1048576 characters long (this found printing pastestring.size() when highlighting empty excel column selecting header , copying).

is there anyway copied column clipboard more efficiently tab delimited text or something? or should throw error when size of string on clipboard arbitrarily large length?

not familiar qtableview had similar experience in vba excel; hit bottom of sheet. there 65,536 rows in excel 97 - 2003 , 1048576 rows in 2007+, not arbitrary.

check number of rows, of 2 values indicate went through entire column without hitting cell containing value, hence column empty.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -