Re: copy tableview to Excel
What have you tried so far?
Re: copy tableview to Excel
So far I tried this.
I want to use ctrl-c and ctrl-v when I have selected a column or two.
Thanks for your help,
Arend
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QStandardItemModel"
#include "QAbstractItemModel"
#include "QItemSelectionModel"
#include "QKeyEvent"
#include "QKeySequence"
#include "QClipboard"
{
ui->setupUi(this);
model->setItem(0,0,firstRow);
model->setItem(1,0,secondRow);
ui->tableView->setModel(model);
QModelIndexList list = model->selectionIndexes();
qSort(list);
for(int i = 0; i < list.size(); i++)
{
QString text
= abmodel
->data
(index
).
toString();
copy_table.append(text);
if(index.row() != previous.row())
{
copy_table.append('\n');
}
else
{
copy_table.append('\t');
}
previous = index;
}
clipboard->setText(copy_table);
}
MainWindow::~MainWindow()
{
delete ui;
}
Re: copy tableview to Excel
You need to use text/csv as the mime-type instead of text/plain which is used when you call QClipboard::setText(). Use QClipboard::setMimeData() instead.