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?

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 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?

    raven-worxR 1 Reply Last reply
    0
    • J Jakob

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      0
      • raven-worxR raven-worx

        @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 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.

        raven-worxR 1 Reply Last reply
        0
        • J Jakob

          @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.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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
          1
          • raven-worxR raven-worx

            @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 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

            • Login

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