Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Copy QTableWidget cells to Excell

Copy QTableWidget cells to Excell

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 5.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dimis
    wrote on last edited by
    #1

    Hi all,

    Is there any way to copy a whole table (QTableWidget) and paste it in Excell?
    Should I use copy to clipboard with ctrl+c or something else?

    Thank you in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Expanding on @SGaist , if you loop over the items and construct a string with \t between
        the cols values for each row then you can paste it directly.

        alt text

        1 Reply Last reply
        4
        • D Offline
          D Offline
          Dimis
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved