LibEngsas
espreadsheethandler.cpp

This example demonstrates the usage of ESpreadsheetHandler to load and display spreadsheets.The example has one main window and allows to load and save spreadsheet files (like Excel, CSV, ...) with help of ESpreadsheetHandler and ESpreadsheetProvider implementations.

example-espreadsheethandler-screenshot.png

The main window is a class with name MainWindow, defined in file mainwindow.h as follows:

The implementation is done within mainwindow.cpp. Within the constructor, the UI is created and the ESpreadsheetHandler is loaded. At this point, it is also checked, that at least one ESpreadsheetProvider is available, to make sure that some spreadsheet formats could be handled.

Since the Open action in the menu bar is connected to the slot QMainWindow::close(), only the MainWindow::open() and MainWindow::save() slots are implemented within this class.

If the Open action in the menubar is clicked, the slot MainWindow::open() is executed. After checking for an available handler, it asks the user for a file to open. The open dialog allows to choose all files, which can be handled by the available providers. To achieve this, the ESpreadsheetHandler::filters() are forwarded to the dialog.

The file is opened with ESpreadsheetHandler::load(QString) after checking for empty files. If the file was loaded successfully, the number of contained sheets is determined with ESpreadsheetHandler::spreadsheets() and checked.

At least the QStandardItemModel of the view is updated with new data of the first sheet.

To save changed data, it calls ESpreadsheetHandler::writeData().

espreadsheethandler.cpp contains the main() function to execute QApplication and load the MainWindow.