资源简介
ts翻译文件导出为excel。qt5.5编译。包含代码及可执行程序。
代码片段和文件信息
#include “exportexcelobject.h“
#include
#include
#include
int ExportExcelobject::export2Excel()
{
if(fieldList.size() <= 0)
{
qDebug() << “ExportExcelobject::export2Excel failed: No fields defined.“;
return -1;
}
QSqlDatabase db = QSqlDatabase::addDatabase(“QODBC“ “excelexport“);
if(!db.isValid())
{
qDebug() << “ExportExcelobject::export2Excel failed: QODBC not supported.“;
return -2;
}
// set the dsn string
QString dsn = QString(“DRIVER={Microsoft Excel Driver (*.xls)};DSN=‘‘;FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\“%1\“;DBQ=%2“).
arg(excelFilePath).arg(excelFilePath);
db.setDatabaseName(dsn);
if(!db.open())
{
qDebug() << “ExportExcelobject::export2Excel failed: Create Excel file failed by DRIVER={Microsoft Excel Driver (*.xls)}.“;
//QSqlDatabase::removeDatabase(“excelexport“);
return -3;
}
QSqlQuery query(db);
//drop the table if it‘s already exists
QString s sSql = QString(“DROP TABLE [%1] (“).arg(sheetName);
query.exec(sSql);
//create the table (sheet in Excel file)
sSql = QString(“CREATE TABLE [%1] (“).arg(sheetName);
for (int i = 0; i < fieldList.size(); i++)
{
s = QString(“[%1] %2“).arg(fieldList.at(i)->sFieldName).arg(fieldList.at(i)->sFieldType);
sSql += s;
if(i < fieldList.size() - 1)
sSql += “ “;
}
sSql += “)“;
query.prepare(sSql);
if(!query.exec())
{
qDebug() << “ExportExcelobject::export2Excel failed: Create Excel sheet failed.“;
//db.close();
//QSqlDatabase::removeDatabase(“excelexport“);
return -4;
}
//add all rows
sSql = QString(“INSERT INTO [%1] (“).arg(sheetName);
for (int i = 0; i < fieldList.size(); i++)
{
sSql += fieldList.at(i)->sFieldName;
if(i < fieldList.size() - 1)
sSql += “ “;
}
sSql += “) VALUES (“;
for (int i = 0; i < fieldList.size(); i++)
{
sSql += QString(“:data%1“).arg(i);
if(i < fieldList.size() - 1)
sSql += “ “;
}
sSql += “)“;
qDebug() << sSql;
int r iRet = 0;
for(r = 0 ; r < tableView->model()->rowCount() ; r++)
{
query.prepare(sSql);
for (int c = 0; c < fieldList.size(); c++)
{
query.bindValue(QString(“:data%1“).arg(c) tableView->model()->data(tableView->model()->index(r fieldList.at(c)->iCol)));
}
if(query.exec())
iRet++;
if(r % 10 == 0)
emit exportedRowCount(r);
}
emit exportedRowCount(r);
return iRet;
}
- 上一篇:C-V2X技术(10份报告打包)
- 下一篇:iWall For Mac 破解版
相关资源
- QT高级编程 中文完整高清版
- 精通Qt4编程pdf高清电子版
- 十个bootstrap框架写的后台管理模块
- Qt5开发及第2版(含CD光盘1张)
- 黑苹果安装工具以及DSDTssdt修改工具
- Qt及Qt Quick开发实战精解.pdf
- samylee的yolo训练weights
- QtitanRibbon含源码 试用版
- EtherCATSlaveStackCodeTool5.12.rar
- Qt实现中文输入法面板集成谷歌输入法
-
基于qt的qmediapla
yer类实现的一个播放 - cstsuit2012.pdf
- Operating+System+Concepts+10th+Edition英文版
- 回归分析与实验设计 design and analysi
- SD-UHS-II简化规范中文完整翻译.pdf
- 微电子电路第五版习题答案 Microelec
- 1119447_General_NetSDK_Chn_Win64_IS_V3.052.000
- 美赛论文翻译14篇中科院博士翻译.r
- 基于QT的串口工具——实时显示波形
- 信息科学与电子工程专业英语 王朔中
- Qt5 GUI programming书 和源码
- Discrete Mathematics and Its Applications 8th
- echarts数据大屏模版.zip
- SM2算法QT实现
- QT5 编程入门的 源代码
- TSMaster-M3U8及TS解析解密合并工具
- 基于SpringMVC+Spring+Mybatis+BootStrap的教务
- 大地测量计算工具集4.5
- 实现IFileDialog
- 骑士周游算法的QT演示版
评论
共有 条评论