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. How to ensure that an HTML-table in QTextEdit is copied as a table when pasting into for instance Excel?
QtWS25 Last Chance

How to ensure that an HTML-table in QTextEdit is copied as a table when pasting into for instance Excel?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditqt5.6htmlcopy
5 Posts 2 Posters 2.1k Views
  • 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.
  • J Offline
    J Offline
    Jakob
    wrote on 23 May 2016, 12:57 last edited by
    #1

    We use a QTextEdit instance to display some results of calculations in tabular form. We would like to be able to copy such tables and paste them into for instance Excel.

    In our current (naive) implementation each value from the HTML table, becomes a separate row in Excel. How can we do better?

    R 1 Reply Last reply 23 May 2016, 13:06
    0
    • J Jakob
      23 May 2016, 12:57

      We use a QTextEdit instance to display some results of calculations in tabular form. We would like to be able to copy such tables and paste them into for instance Excel.

      In our current (naive) implementation each value from the HTML table, becomes a separate row in Excel. How can we do better?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 May 2016, 13:06 last edited by
      #2

      @Jakob
      How do you create the drop data?
      When you simply create text/plain i guess it will become a single row/cell.
      Probably making sure, that you create text/html mimedata excel will paste them differently.
      But i am not sure.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      J 1 Reply Last reply 23 May 2016, 13:35
      0
      • R raven-worx
        23 May 2016, 13:06

        @Jakob
        How do you create the drop data?
        When you simply create text/plain i guess it will become a single row/cell.
        Probably making sure, that you create text/html mimedata excel will paste them differently.
        But i am not sure.

        J Offline
        J Offline
        Jakob
        wrote on 23 May 2016, 13:35 last edited by
        #3

        @raven-worx Thanx for reading and taking some time to help me out.

        Here with 'copying' I simply mean selecting the relevant text in the QTextEdit and hitting Ctrl+C.

        R 1 Reply Last reply 23 May 2016, 13:42
        0
        • J Jakob
          23 May 2016, 13:35

          @raven-worx Thanx for reading and taking some time to help me out.

          Here with 'copying' I simply mean selecting the relevant text in the QTextEdit and hitting Ctrl+C.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 23 May 2016, 13:42 last edited by
          #4

          @Jakob
          what happens if you do this?

          QMimeData* MyTextEdit::createMimeDataFromSelection()
          {
               QMimeData* origData = QTextEdit::createMimeDataFromSelection();
               QMimeData* data = new QMimeData;
                   data->setData( "text/html", origData->data("Text/html") )
               delete origData;
               retrun Data;
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply 24 May 2016, 08:04
          1
          • R raven-worx
            23 May 2016, 13:42

            @Jakob
            what happens if you do this?

            QMimeData* MyTextEdit::createMimeDataFromSelection()
            {
                 QMimeData* origData = QTextEdit::createMimeDataFromSelection();
                 QMimeData* data = new QMimeData;
                     data->setData( "text/html", origData->data("Text/html") )
                 delete origData;
                 retrun Data;
            }
            
            J Offline
            J Offline
            Jakob
            wrote on 24 May 2016, 08:04 last edited by
            #5

            @raven-worx Thanx for the suggestion. I think we can go a long way with this, except that we are on Windows and it seems we need some Windows-specific MIME-conversions. We'll try to tinker a bit with that.

            1 Reply Last reply
            0

            5/5

            24 May 2016, 08:04

            • Login

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