首页 办公 正文

关于qt筛选excel的信息

QStringdsn=QString("DRIVER={MicrosoftExcelDriver(*.xls)};db.setDatabaseName(dsn);inti=0;for(introw=0;row++){QSqlRecordexcelRecord=excelTableModel-record(row);foreach(QS...

今天给各位分享qt筛选excel的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录:

关于qt与excel

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

if(!db.isValid())

{

qDebug() "export2Excel failed: QODBC not supported.";

return ;

}

QString xlsFile = "D:/test.xls";

QString dsn = QString("DRIVER={Microsoft Excel Driver (*.xls)};Readonly=0;DriverId=790;DBQ=%1").arg(xlsFile);

db.setDatabaseName(dsn);

if(!db.open())

{

//错误处理

return;

}

QString queryystr = "select * from [sheet1$]";

SqlTableModel*excelTableModel = new SqlTableModel(this, db);

QString tableName = "[sheet1$]";

excelTableModel-setTable(tableName);

QSqlQuery querry(queryystr, db);

excelTableModel-setQuery(querry);

excelTableModel-setEditStrategy(QSqlTableModel::OnManualSubmit);

excelTableModel-setSort(0, Qt::AscendingOrder);

bool ok = excelTableModel-select(); //选取整个表的所有行

ui.tableView_2-setModel(excelTableModel);

int i = 0;

foreach(QString heardName, heardList)

{

excelTableModel-setHeaderData(i, Qt::Horizontal, heardName);

i++;

}

int sqlTableCount = m_sqlTableModel-rowCount();

int excelTableCount = excelTableModel-rowCount();

QListQSqlRecord tmprecord;

for (int row = 0; row excelTableCount; row++ )

{

QSqlRecord excelRecord = excelTableModel-record(row);

tmprecord excelRecord;

}

db.close();

bool open = m_dba.open();

foreach(QSqlRecord record, tmprecord)

{

bool ok = m_sqlTableModel-insertRow(sqlTableCount); //添加一行

for (int k = 0; k5;k++)

{

if (k == 0)

{

bool suc= m_sqlTableModel-setData(m_sqlTableModel-index(sqlTableCount,k),record.value(k), Qt::CheckStateRole);

}

bool suc= m_sqlTableModel-setData(m_sqlTableModel-index(sqlTableCount,k),record.value(k), Qt::EditRole);

}

sqlTableCount++;

}

AlterButtonClicked();

initWindow(TEACHERMANAGECLICKED);

AlterButtonClicked()

{

m_sqlTableModel-database().transaction(); //开始事务操作

if (m_sqlTableModel-submitAll())

{

m_sqlTableModel-database().commit(); //提交

}

else

{

m_sqlTableModel-database().rollback(); //回滚

QMessageBox::warning(this, tr("Model"), tr("数据库错误: %1").arg(m_sqlTableModel-lastError().text()));

}

}

initWindow(int index)

{

int i = 0;

heardList.clear();

if (index == STUDENTMANAGECLICKED)

{

heardList "选择" "编号" "姓名" "性别" "班级" "备注";

m_sqlTableModel-setTable("\"StudentInfo\"");

m_sqlTableModel-setEditStrategy(QSqlTableModel::OnManualSubmit);

m_sqlTableModel-setSort(0, Qt::AscendingOrder);

m_sqlTableModel-select(); //选取整个表的所有行

ui.tableView_2-setModel(m_sqlTableModel);

foreach(QString heardName, heardList)

{

m_sqlTableModel-setHeaderData(i, Qt::Horizontal, heardName);

i++;

}

}

else if (index == TEACHERMANAGECLICKED)

{

heardList "选择" "用户名" "姓名" "性别" "角色" "备注";

m_sqlTableModel-setTable("\"TeacherInfo\"");

m_sqlTableModel-setEditStrategy(QSqlTableModel::OnManualSubmit);

m_sqlTableModel-setSort(0, Qt::AscendingOrder);

bool ok1 = m_sqlTableModel-select(); //选取整个表的所有行

ui.tableView_2-setModel(m_sqlTableModel);

foreach(QString heardName, heardList)

{

m_sqlTableModel-setHeaderData(i, Qt::Horizontal, heardName);

i++;

}

}

//m_sqlTableModel-insertColumn(0);

ui.tableView_2-resizeColumnsToContents();

}

Qt实现一个表格,具有excel功能?

使用QAxwidget,导入excel控件,然后窗口中的内容就是excel,你什么功能都不需要开发,直接用就是了。最后,把QAxwidget放入Qgraphicsscene中即可。

如何使用Qt来操作Excel

1、显示当前窗口: excel.setProperty("Visible", true); 2、更改 Excel 标题栏: excel.setProperty("Caption", "Invoke Microsoft Excel"); 3、添加新工作簿: QAxObject * workbooks = excel.querySubObject("WorkBooks"); workbooks-dynami...

QT获取excel 单元格位置

Qt可以通过QAxServer和QAxContainer库来获取excel单元格位置。

方法是:通过QAxServer获得Excel应用程序对象QAxObject,然后使用QAxObject打开相应的excel文档,找到指定的工作表,从里面读取指定位置上的单元格。

Qt操作Excel

如果设置后台启动报错的话,那提供一种无奈之选,就是,设置窗口可见,然后

excel-setProperty("WindowState", "xlMinimized");

将窗口最小化,将就一下

关于qt筛选excel和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

本文转载自互联网,如有侵权,联系删除