Important: Please read the Qt Code of Conduct -

How to make or embed xls in pyqt based gui and

  • How to make or embed xls in pyqt based gui and user should cross link to other views in the GUis
    for example user should be able to take values from cells of Excels and create a heirarchy in QtreeView of pyqt based GUI

  • Banned

    First to directly answer your question -- you do not embed an XLS into your PyQt GUI

    What you do is access the XLS file as a Data Source (Model) using straight Python and then pass that to your Router (Controller) that then send it to the GUI (View) in a format it can consume. AKA classic MVC Methodology

    Thus you end up using the Excel spreadsheet like a mini-database (which actually that is what it is -- it is Microsoft's smallest database engine with a spreadsheet GUI layered on top) that pull the data from and store the data into. Of course if you do not need to use an XLS to store the data then sqlite3 is much better and then you can export the data from there as a CSV so you can view it in your XLS or write a simply Python program that pulls the data out and imports into your XLS as needed. Using an XLS file as your data source while doable is not nearly as clean nor as efficient. So consider that as well.

    Now the worst thing you can do is mix your Apples (Data Source) with your Oranges (GUI) as the two are not really compatible directly and further if you some day change your Oranges and start using Grapefruits you have to recode just about everything. The MVC methodology makes it such that the Data Source (Model) does not know nor cares how its data is being used and the GUI (View) does not know or care where its data is coming from and the Router (Controller) handles all the translations and communicates to these 2 end points using your standardized API calls that you set up within the GUI and Data Source

  • In that case can we have

    1. QTableWIdget in th Pyqt GUI
    2. It should have the same functionality of Excel sheet
    3. For that if some one can help in code that will be helpful

  • @Qt-Enthusiast
    We chose openpyxl,, as the best/easiest interface to Excel/LibreOffice Calc cross-platform. This lets you read/write XLS/XLSX files.

    However, you have to write your own UI code to e.g. display data in a table, and it won't evaluate formulae for you, it's a file reader/writer. So you won't just get "the same functionality of Excel sheet" out of the box, you have to write that part (quite a bit of work, depending on how much functionality you expect).

    To really get Excel you'd have to try something like QAxObject, e.g. or Of course that is not "a QTableWIdget", it's full Excel running, and naturally you have to have Excel/Windows only....

  • Banned

    First my current project actually takes data from an Excel Spreadsheet, moves this data into an SQLite3 database, then implements everything using that data. So all I needed was a pure Python importer from XLS and a pure Python exporter to XLS -- but in this project the XLS is actually a necessity as it is used when designing the Serial Device layout and such.

    Next I would strongly suggest that you do not use JonB's suggestion because that adds a major level of complexity to your code that does not really gain you all that much if anything and probably introduces a lot more headaches.

    So to address your points:

    1. A QTreeView works as good as a QTableWidget for displaying and manipulating data in a spreadsheet like manner with QTreeView being less complex

    2. What do you mean by same functionality of an Excel Sheet?

    3. Yes I can help teach you how to do this in a step by step process just shoot me a PM

Log in to reply