Copy QTableWidget cells to Excell
-
Hi,
What did you try ?
One thing that comes to mind: you can copy to the clipboard your table content as a CSV string. Warning not tested, it just a suggestion.
-
Thank you bot h for your responses. I ended up with a qstring, a qtextstream and a for loop, as below (for a table with 8 columns):
QClipboard *clipboard = QApplication::clipboard();
int tbl_lines = ui->tbl->rowCount();
QString str;
for (int i=0; i<tbl_lines; i++)
{QString mydata0 = ui->tbl->item(i, 0)->text();
QString mydata1 = ui->tbl->item(i, 1)->text();
QString mydata2 = ui->tbl->item(i, 2)->text();
QString mydata3 = ui->tbl->item(i, 3)->text();
QString mydata4 = ui->tbl->item(i, 4)->text();
QString mydata5 = ui->tbl->item(i, 5)->text();
QString mydata6 = ui->tbl->item(i, 6)->text();
QString mydata7 = ui->tbl->item(i, 7)->text();QTextStream(&str) << mydata0 << "\t" << mydata1 << "\t"<< mydata2 << "\t" << mydata3 <<"\t"<< mydata4 << "\t" << mydata5 << "\t"<< mydata6 << "\t" << mydata7 << endl;
}
clipboard->setText(str);it might be kind of silly my approach, but it works! Thanks again!