Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. Best way to populate a QTableView or QTableWidget with Excel data (urgent)
QtWS25 Last Chance

Best way to populate a QTableView or QTableWidget with Excel data (urgent)

Scheduled Pinned Locked Moved India
8 Posts 5 Posters 14.8k 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.
  • M Offline
    M Offline
    maxoreli
    wrote on last edited by
    #1

    Hi, I'm working on an application where I need to import Excel data and put it into either a QTableView or QTableWidget. I'm wondering what would be the best method to accomplish this. Please i want just a sample code for this.

    1. Help me to import Excel files in Qt
      2.Populates a QTableView or QTableWidget with Excel data

    [[Merged two posts, Tobias]]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxoreli
      wrote on last edited by
      #2

      Hi, I'm working on an application where I need to import Excel data and put it into either a QTableView or QTableWidget. I'm wondering what would be the best method to accomplish this:
      Please i want just a sample code for this:

      1. Help me to import Excel files in Qt
        2.Populates a QTableView or QTableWidget with Excel data
      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        You need

        a C++ library to perform the parsing of the Excel files (libxl?)

        to write a custom model (like, a QAbstractTableModel subclass) that uses that library in order to provide the data to Qt views (in your case, a QTableView).

        If you have an existing excel installation you could also use the ActiveX extension for Qt (search in the forums, I saw topics about this).

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          On flagging your question as urgent, please read "this":http://www.catb.org/~esr/faqs/smart-questions.html#urgent.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jim_kaiser
            wrote on last edited by
            #5

            It's quite simple, you just have to do it.

            Okay, first, we need to export it to a CSV. (Comma separated values)

            Now, use QFile::open(QIODevice::ReadOnly) to read the csv file, read the lines.

            For each line use the QString::split(",") function to get list of values.

            Now use a QStandardItemModel to add the first line as header (QStandardItemModel::setHorizontalHeaderLabels (QStringList)), values for each row (QStandardItemModel::appendRow(QList<QStandardItem*>)).

            Set the model on a QTableView.

            Done. I don't want to write the code because it is trivial. But the pseudo-code should guide you, I hope.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Unfortunately, parsing real CSV is not trivial. Just split at "," does lead to false parts if one of the fields contains a comma itself. Usually the CSV is wrapped in qutoation marks (") in this case, which need be removed for retrieving back the actual value. I leave the implications of a field value containing a comma and a quotation mark to you. So no, this is actually not a good recommendation unless one uses a mature CSV parsing library.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jim_kaiser
                wrote on last edited by
                #7

                @Volker: Hmm.. you're right. It needs more handling than I have suggested. Maybe, best to stick to an external library for parsing.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maxoreli
                  wrote on last edited by
                  #8

                  Thanks for answer.
                  i already download libXl librairy but i have always problems.
                  Please give me an a sample code and steps for reading/writing Excelfiles

                  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