dbzhang800 / QtXlsxWriter

.xlsx file reader and writer for Qt5
http://qtxlsx.debao.me
Other
1.24k stars 632 forks source link

SheetModel. Get horizontal headers from first row #100

Closed Matumba closed 8 years ago

Matumba commented 8 years ago

Hi. I tried do my custom tablemodel like this https://github.com/dbzhang800/QtXlsxWriter/blob/master/examples/xlsx/xlsxwidget/xlsxsheetmodel.h I reimplemented function headerdata inline QVariant SheetModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole) { if (orientation == Qt::Horizontal) return sheet->read(1, section + 1); else return QString::number(section + 1); } return QVariant(); }

and in my reimplemented version of function data() I started read data from second row QXlsx::Cell *cell = sheet->cellAt(index.row() + 2, index.column() + 1); QVariant userFriendlyValue = sheet->read(index.row() + 2, index.column() + 1); This work on start. But if smb will click on editable item, then my data will be move up to one position How can I fix that?

Matumba commented 8 years ago

Sorry. All that I had to do it on my reinmplemented version of function setData change from if (sheet->write(index.row() + 1, index.column() + 1, value) == 0) to if (sheet->write(index.row() + 2, index.column() + 1, value) == 0)