1, Foreword
The original intention of this component is to create a wheel to make data import and export extremely simple. It can be done in a few lines of code, which is applicable to most application scenarios. This is also the biggest difference between this component and qtxls. Qtxls aims to be large and comprehensive and provide various xls interfaces. Programmers need to deal with how to organize exported data, This can not avoid calling a lot of function code, which is often not so convenient for novice programmers. For example, many people actually want to export the data in the current QTableWidget or QTableView, and do not want to study how to organize the data. The hope is to pass in the QTableWidget control name, field name, field width and data content, Don't worry, because the controls are given to you and the data is there. Just implement the function to fix it. Just use it comfortably.
2, Functional features
- Component integrates exporting data to csv, xls, pdf and printing data at the same time.
- All operations provide static methods without new, and structural data is adopted for parameter settings such as data and attributes, which is very convenient.
- It also supports QTableView, QTableWidget, QStandardItemModel, QSqlTableModel and other data sources.
- Provide static methods to directly pass in QTableView and QTableWidget controls to automatically identify column name, column width and data content.
- Each group of functions provides a separate complete example with detailed comments, which is very suitable for Qter programmers at all stages.
- The original data export mechanism does not rely on any third-party libraries such as office components or operating systems, and supports embedded linux.
- The speed is super fast. It takes only 2 seconds to complete 100000 rows of data in 9 fields.
- It only takes four steps to quickly export massive data, such as 100W records to Excel.
- At the same time, it provides direct write data interface and multi-threaded write data interface without card main interface.
- You can set the title, subtitle and table name.
- You can set the field name, column name and column width of exported data.
- You can set the automatic stretching and filling of the end column, and the default stretching is more beautiful.
- You can set whether to enable verification filtering data. After enabling, the data that meets the rules will be displayed in special colors.
- Check columns, check rules, check values, and check value data types can be specified.
- The verification rule supports accurate equal to = =, greater than >, greater than or equal to > =, less than <, less than or equal to < =, not equal to! = contains.
- The data type of the check value supports integer int, floating point float and double, and the default text string type.
- You can set the random background color and the column set that needs the random background color.
- It supports grouping and outputting data, such as grouping and outputting data according to equipment, which is convenient for viewing.
- You can set csv separator, line content separator and sub content separator.
- You can set the border width and auto fill data type. The auto data type is on by default.
- You can set whether to turn on the data cell style. It is not turned on by default, which can save about 30% of the file volume.
- You can set horizontal layout, paper margin, etc., such as exporting to pdf and printing data.
- Support mixed arrangement of pictures and texts, export data to pdf and print data, and automatic paging.
- Super flexible, you can freely change the source code, set the alignment, text color, background color, etc.
- Support any Excel software, including but not limited to excel 2003-2021, wps, openoffice, etc.
- Written in pure Qt, it supports any Qt version + any compiler + any system.
3, Experience address
- Experience address: https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A Extraction code: o05q file name: bin_dataout.zip
- Domestic sites: https://gitee.com/feiyangqingyun
- International sites: https://github.com/feiyangqingyun
- Personal homepage: https://blog.csdn.net/feiyangqingyun
- Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/
4, Renderings
5, Related code
void frmSimple::on_btnLoad1_clicked() { //Set the data model first, otherwise setColumnWidth will not work ui->tableView->setModel(model); //Set the number of columns, column title and column width model->setColumnCount(column); //An easy way to set the column header collection model->setHorizontalHeaderLabels(columnNames); for (int i = 0; i < column; ++i) { ui->tableView->setColumnWidth(i, columnWidths.at(i)); } //Loop add row data QDateTime now = QDateTime::currentDateTime(); model->setRowCount(row); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { QStandardItem *item = new QStandardItem; //The last column shows the time difference if (j == column - 1) { item->setText(now.addSecs(i).toString("yyyy-MM-dd HH:mm:ss")); } else { item->setText(QString("%1_%2").arg(i + 1).arg(j + 1)); } model->setItem(i, j, item); } } } void frmSimple::on_btnCsv1_clicked() { QString file = QUIHelper::appPath() + "/db/dataout_tableview.csv"; DataHelper::DataOut(ui->tableView, model, 0, file, "Test title", "Test information"); //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnXls1_clicked() { //Generic functions are passed directly into the control #if 1 QString file = QUIHelper::appPath() + "/db/dataout_tableview.xls"; DataHelper::DataOut(ui->tableView, model, 1, file, "Test title", "Test information"); #else //If the file name is not passed in, a dialog box will pop up and select save file name QString file = DataHelper::DataOut(ui->tableView, model, 1); #endif //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnPdf1_clicked() { //Generic functions are passed directly into the control QString file = QUIHelper::appPath() + "/db/dataout_tableview.pdf"; DataHelper::DataOut(ui->tableView, model, 2, file, "Test title", "Test information"); //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnPrint1_clicked() { //Generic functions are passed directly into the control DataHelper::DataOut(ui->tableView, model, 3, "", "Test title"); } void frmSimple::on_btnLoad2_clicked() { //Set column title, number and width ui->tableWidget->setColumnCount(column); //An easy way to set the column header set ui->tableWidget->setHorizontalHeaderLabels(columnNames); for (int i = 0; i < column; ++i) { ui->tableWidget->setColumnWidth(i, columnWidths.at(i)); } //Add data QDateTime now = QDateTime::currentDateTime(); ui->tableWidget->setRowCount(row); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { QTableWidgetItem *item = new QTableWidgetItem; //The last column shows the time difference if (j == column - 1) { item->setText(now.addSecs(i).toString("yyyy-MM-dd HH:mm:ss")); } else { item->setText(QString("%1_%2").arg(i + 1).arg(j + 1)); } ui->tableWidget->setItem(i, j, item); } } } void frmSimple::on_btnCsv2_clicked() { QString file = QUIHelper::appPath() + "/db/dataout_tablewidget.csv"; DataHelper::DataOut(ui->tableWidget, 0, file, "Test title", "Test information"); //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnXls2_clicked() { QString file = QUIHelper::appPath() + "/db/dataout_tablewidget.xls"; DataHelper::DataOut(ui->tableWidget, 1, file, "Test title", "Test information"); //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnPdf2_clicked() { //Generic functions are passed directly into the control QString file = QUIHelper::appPath() + "/db/dataout_tablewidget.pdf"; DataHelper::DataOut(ui->tableWidget, 2, file, "Test title", "Test information"); //Open the file you just exported QUIHelper::openFile(file, "Export test information"); } void frmSimple::on_btnPrint2_clicked() { //Generic functions are passed directly into the control DataHelper::DataOut(ui->tableWidget, 3, "", "Test title"); }