1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123 |
- #include <QTextCodec>
- #include <QDir>
- #include <QDebug>
- #include <QDateTime>
- #include <QThread>
- #include "generateword.h"
- #include "qword.h"
- GenerateWord::GenerateWord(QObject *parent) : QObject(parent)
- {
- }
- void setTalbeCurve(QWord &word,QList<QPointF> &points,QString picture)
- {
- word.setFontSize(7);
- word.setFontBold(false);
- QAxObject *table;
- int length = points.length();
- int integer = length/10;
- int remainder = length%10;
- if(remainder > 0)
- integer += 1;
- table = word.createTableWithColor(integer, 10);
- for(int i=0;i<length; i++){
- QPointF point = points.at(i);
- QString text = QString::number(point.y());
- int lineNum = i/10+1;
- int row = i%10+1;
- word.setCellText(table, lineNum, row, text,false);
- }
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- if(table != nullptr)
- delete table;
- //添加曲线图
- word.AddPicture(QDir::currentPath()+"/"+picture);
- word.moveForEnd();
- word.insertMoveDown();
- word.insertEnter();
- }
- void setTalbeCurve1(QWord &word,QList<QVariant> &points,QString picture)
- {
- if(points.length() == 0){
- word.insertEnter();
- return;
- }
- word.setFontSize(7);
- word.setFontBold(false);
- QAxObject *table;
- int length = points.length();
- int integer = length/10;
- int remainder = length%10;
- if(remainder > 0)
- integer += 1;
- table = word.createTableWithColor(integer, 10);
- for(int i=0;i<length; i++){
- QVariant variant = points.at(i);
- QPointF point = variant.toPointF();
- QString text = QString::number(point.y());
- int lineNum = i/10+1;
- int row = i%10+1;
- word.setCellText(table, lineNum, row, text,false);
- }
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- if(table != nullptr)
- delete table;
- //添加曲线图
- word.AddPicture(QDir::currentPath()+"/"+picture);
- word.moveForEnd();
- word.insertMoveDown();
- word.insertEnter();
- }
- void GenerateWord::breatheValveRecordWrite(QWord &word,QString testType, QVariant &obj)
- {
- QString text;
- QString picture;
- QAxObject *table;
- QTextCodec *codec = QTextCodec::codecForName("UTF-8");
- QVariantMap map = obj.toMap();
- QList<QVariant> points0 = map["pointList0"].toList();
- QList<QVariant> points1 = map["pointList1"].toList();
- QList<QVariant> points2 = map["pointList2"].toList();
- QList<QVariant> points3 = map["pointList3"].toList();
- QList<QVariant> points4 = map["pointList4"].toList();
- QList<QVariant> points5 = map["pointList5"].toList();
- QString resultSetPressure1 = map["resultSetPressure1"].toString();
- QString resultSetPressure2 = map["resultSetPressure2"].toString();
- QString resultSetPressure3 = map["resultSetPressure3"].toString();
- QString resultSealPressure1 = map["resultSealPressure1"].toString();
- QString resultSealPressure2 = map["resultSealPressure2"].toString();
- QString resultSealPressure3 = map["resultSealPressure3"].toString();
- //第一次 开启压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "negative"){
- text=codec->toUnicode("3.1、第一次负压开启压力试验记录表(kPa)");
- }
- else if(testType == "positive"){
- text=codec->toUnicode("2.1、第一次正压开启压力试验记录表(kPa)");
- }
- else if(testType == "capsize"){
- text=codec->toUnicode("4.1、90°颠覆性密封试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.1.jpg";
- }
- else if(testType == "negative"){
- picture= "3.1.jpg";
- }
- else if(testType == "capsize"){
- picture= "4.1.jpg";
- }
- setTalbeCurve1(word,points0,picture);
- //第二次 开启压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "positive"){
- text=codec->toUnicode("2.2、第二次正压开启压力试验记录表(kPa)");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.2、第二次负压开启压力试验记录表(kPa)");
- }
- else if(testType == "capsize"){
- text=codec->toUnicode("4.2、180°颠覆性密封试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.2.jpg";
- }
- else if(testType == "negative"){
- picture= "3.2.jpg";
- }
- else if(testType == "capsize"){
- picture= "4.2.jpg";
- }
- setTalbeCurve1(word,points1,picture);
- //第三次 开启压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "positive"){
- text=codec->toUnicode("2.3、第三次正压开启压力试验记录表(kPa)");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.3、第三次负压开启压力试验记录表(kPa)");
- }
- else if(testType == "capsize"){
- text=codec->toUnicode("4.3、270°颠覆性密封试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.3.jpg";
- }
- else if(testType == "negative"){
- picture= "3.3.jpg";
- }
- else if(testType == "capsize"){
- picture= "4.3.jpg";
- }
- setTalbeCurve1(word,points2,picture);
- if(testType == "capsize"){
- goto result;
- }
- //第一次 密封压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "positive"){
- text=codec->toUnicode("2.4、第一次正压密封压力试验记录表(kPa)");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.4、第一次负压密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.4.jpg";
- }
- else if(testType == "negative"){
- picture= "3.4.jpg";
- }
- setTalbeCurve1(word,points3,picture);
- //第二次 密封压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "positive"){
- text=codec->toUnicode("2.5、第二次正压密封压力试验记录表(kPa)");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.5、第二次负压密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.5.jpg";
- }
- else if(testType == "negative"){
- picture= "3.5.jpg";
- }
- setTalbeCurve1(word,points4,picture);
- //第三次 密封压力试验
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(testType == "positive"){
- text=codec->toUnicode("2.6、第三次正压密封压力试验记录表(kPa)");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.6、第三次负压密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- if(testType == "positive"){
- picture= "2.6.jpg";
- }
- else if(testType == "negative"){
- picture= "3.6.jpg";
- }
- setTalbeCurve1(word,points5,picture);
- //试验结果
- result:
- if(testType == "positive"){
- text=codec->toUnicode("2.7、正压开启压力和密封试验结果");
- }
- else if(testType == "negative"){
- text=codec->toUnicode("3.7、负压开启压力和密封试验结果");
- }
- else if(testType == "capsize"){
- text=codec->toUnicode("4.4、颠覆性密封试验结果");
- }
- word.setFontBold(true);
- word.setFontSize(9);
- word.insertText(text);
- word.insertEnter();
- word.moveForEnd();
- if(testType == "capsize"){
- word.setFontSize(7);
- word.setFontBold(false);
- table = word.createTableWithColor(3, 2);
- text=codec->toUnicode("90°颠覆性密封试验结果");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, resultSealPressure1.toUtf8(),false);
- text=codec->toUnicode("180°颠覆性密封试验结果");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, resultSealPressure2.toUtf8(),false);
- text=codec->toUnicode("270°颠覆性密封试验结果");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, resultSealPressure3.toUtf8(),false);
- }
- else{
- word.setFontSize(7);
- word.setFontBold(false);
- table = word.createTableWithColor(3, 4);
- if(testType == "positive")
- text=codec->toUnicode("第一次正压开启压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第一次负压开启压力(kPa)");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, resultSetPressure1.toUtf8(),false);
- if(testType == "positive")
- text=codec->toUnicode("第一次正压密封压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第一次负压密封压力(kPa)");
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, resultSealPressure1.toUtf8(),false);
- if(testType == "positive")
- text=codec->toUnicode("第二次正压开启压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第二次负压开启压力(kPa)");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, resultSetPressure2.toUtf8(),false);
- if(testType == "positive")
- text=codec->toUnicode("第二次正压密封压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第二次负压密封压力(kPa)");
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, resultSealPressure2.toUtf8(),false);
- if(testType == "positive")
- text=codec->toUnicode("第三次正压开启压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第三次负压开启压力(kPa)");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, resultSetPressure3.toUtf8(),false);
- if(testType == "positive")
- text=codec->toUnicode("第三次正压密封压力(kPa)");
- else if(testType == "negative")
- text=codec->toUnicode("第三次负压密封压力(kPa)");
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, resultSealPressure3.toUtf8(),false);
- }
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- }
- void GenerateWord::receiveGenerateBreatheValveWord(QString savePath, QVariant para,QVariant obj1, QVariant obj2, QVariant obj3)
- {
- qDebug()<<"receiveGenerateBreatheValveWord";
- QVariantMap map = para.toMap();
- QString manufacture = map["manufacture"].toString();
- QString type = map["type"].toString();
- QString serialNumber = map["serialNumber"].toString();
- QString user = map["user"].toString();
- QString carplate = map["carplate"].toString();
- QString valve = map["valve"].toString();
- QString setPressure = map["setPressure"].toString();
- QString state = map["state"].toString();
- QString text;
- QTextCodec *codec = QTextCodec::codecForName("UTF-8");
- QString text1 = codec->toUnicode("正在生成报告,请耐心等待");
- QString text2 = codec->toUnicode("正在保存中...");
- QString text3 = codec->toUnicode("报告已完成");
- QString text4 = codec->toUnicode("打开word失败");
- QString title = manufacture+"_"+type+"_"+serialNumber;
- sendWordReportProgress(text1);
- QThread::sleep(1);
- QWord word;
- if( !word.createNewWord(savePath) )
- {
- QString error = tr("Failed to export report,") + word.getStrErrorInfo();
- qDebug()<<error;
- sendWordReportProgress(text4);
- QThread::msleep(500);
- sendWordReportProgress("close");
- return;
- }
- word.setPageOrientation(0); //页面方向
- word.setWordPageView(3); //页面视图
- //字体选择
- QString font;
- font=codec->toUnicode("宋体");
- word.setFontName(font);
- //标题
- word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
- word.setFontSize(10); //字体大小
- word.setFontBold(true); //字体加粗
- word.insertText(title);
- word.insertMoveDown();
- //1、基本信息 题目
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text=codec->toUnicode("1、基本信息");
- word.insertText(text);
- word.insertMoveDown();
- //基本信息表格
- word.setFontSize(7);
- word.setFontBold(false);
- QAxObject *table;
- table = word.createTableWithColor(4, 4);
- text = codec->toUnicode("制造单位");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
- text = codec->toUnicode("阀门型号");
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, type.toUtf8(),false);
- text = codec->toUnicode("使用单位");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, user.toUtf8(),false);
- text = codec->toUnicode("出厂编号");
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
- text = codec->toUnicode("车牌号");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, carplate.toUtf8(),false);
- text = codec->toUnicode("阀门类型");
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, valve.toUtf8(),false);
- text = codec->toUnicode("阀门状态");
- word.setCellText(table, 4, 1, text,true);
- word.setCellText(table, 4, 2, state.toUtf8(),false);
- //自动对齐
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- breatheValveRecordWrite(word,"positive", obj1);
- breatheValveRecordWrite(word,"negative", obj2);
- breatheValveRecordWrite(word,"capsize", obj3);
- word.insertEnter();
- word.insertEnter();
- word.insertEnter();
- //报告人员: 报告日期:
- QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
- word.setFontSize(10);
- word.setFontBold(true);
- text = codec->toUnicode(" 检测人员: 报告日期: ");
- word.insertText(text+current_Time);
- word.saveAs();
- word.close();
- sendWordReportProgress(text3);
- QThread::msleep(500);
- sendWordReportProgress("close");
- }
- void GenerateWord::receiveGenerateWord(QString savePath, QVariant obj)
- {
- qDebug()<<"receiveMsg";
- QVariantMap map = obj.toMap();
- QList<QVariant> points0 = map["pointList0"].toList();
- QList<QVariant> points1 = map["pointList1"].toList();
- QList<QVariant> points2 = map["pointList2"].toList();
- QList<QVariant> points3 = map["pointList3"].toList();
- QList<QVariant> points4 = map["pointList4"].toList();
- QList<QVariant> points5 = map["pointList5"].toList();
- QString manufacture = map["manufacture"].toString();
- QString type = map["type"].toString();
- QString serialNumber = map["serialNumber"].toString();
- QString user = map["user"].toString();
- QString carplate = map["carplate"].toString();
- QString valve = map["valve"].toString();
- QString setPressure = map["setPressure"].toString();
- QString state = map["state"].toString();
- QString resultSetPressure1 = map["resultSetPressure1"].toString();
- QString resultSetPressure2 = map["resultSetPressure2"].toString();
- QString resultSetPressure3 = map["resultSetPressure3"].toString();
- QString resultSealPressure1 = map["resultSealPressure1"].toString();
- QString resultSealPressure2 = map["resultSealPressure2"].toString();
- QString resultSealPressure3 = map["resultSealPressure3"].toString();
- QString resultSealPressure1_add = "";
- QString resultSealPressure2_add = "";
- QString resultSealPressure3_add = "";
- QString text;
- //QTextCodec *codec = QTextCodec::codecForName("GBK");
- QTextCodec *codec = QTextCodec::codecForName("UTF-8");
- if(valve == codec->toUnicode("人孔盖")){
- resultSealPressure1_add = map["resultSealPressure1_add"].toString();
- resultSealPressure2_add = map["resultSealPressure2_add"].toString();
- resultSealPressure3_add = map["resultSealPressure3_add"].toString();
- }
- QString text1 = codec->toUnicode("正在生成报告,请耐心等待");
- QString text2 = codec->toUnicode("正在保存中...");
- QString text3 = codec->toUnicode("报告已完成");
- QString text4 = codec->toUnicode("打开word失败");
- QString title = manufacture+"_"+type+"_"+serialNumber;
- sendWordReportProgress(text1);
- QWord word;
- if( !word.createNewWord(savePath) )
- {
- QString error = tr("Failed to export report,") + word.getStrErrorInfo();
- qDebug()<<error;
- sendWordReportProgress(text4);
- QThread::msleep(500);
- sendWordReportProgress("close");
- return;
- }
- word.setPageOrientation(0); //页面方向
- word.setWordPageView(3); //页面视图
- QString font;
- font=codec->toUnicode("宋体");
- word.setFontName(font);
- //标题
- word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
- word.setFontSize(10); //字体大小
- word.setFontBold(true); //字体加粗
- word.insertText(title);
- word.insertMoveDown();
- //1、基本信息 题目
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text=codec->toUnicode("1、基本信息");
- word.insertText(text);
- word.insertMoveDown();
- //基本信息表格
- word.setFontSize(7);
- word.setFontBold(false);
- QAxObject *table;
- table = word.createTableWithColor(4, 4);
- text = codec->toUnicode("制造单位");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
- text = codec->toUnicode("阀门型号");
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, type.toUtf8(),false);
- text = codec->toUnicode("使用单位");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, user.toUtf8(),false);
- text = codec->toUnicode("出厂编号");
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
- text = codec->toUnicode("车牌号");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, carplate.toUtf8(),false);
- text = codec->toUnicode("阀门类型");
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, valve.toUtf8(),false);
- text=codec->toUnicode("安全阀");
- if(valve.toUtf8() == text){
- text = codec->toUnicode("整定压力要求");
- word.setCellText(table, 4, 3, text,true);
- word.setCellText(table, 4, 4, setPressure.toUtf8(),false);
- }
- text=codec->toUnicode("真空阀");
- if(valve.toUtf8() == text){
- text = codec->toUnicode("设计外压");
- word.setCellText(table, 4, 3, text,true);
- word.setCellText(table, 4, 4, setPressure.toUtf8(),false);
- }
- text = codec->toUnicode("阀门状态");
- word.setCellText(table, 4, 1, text,true);
- word.setCellText(table, 4, 2, state.toUtf8(),false);
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀")){
- text=codec->toUnicode("2、第一次整定压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("2、第一次开启压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("2、第一次泄放压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points0,"0.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀")){
- text=codec->toUnicode("3、第二次整定压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("3、第二次开启压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("3、第二次泄放压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points1,"1.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀")){
- text=codec->toUnicode("4、第三次整定压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("4、第三次开启压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("4、第三次泄放压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points2,"2.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points3,"3.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points4,"4.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
- }
- else if(valve == codec->toUnicode("人孔盖")){
- text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve1(word,points5,"5.jpg");
- //3、处理建议
- text=codec->toUnicode("8、试验结果");
- word.setFontBold(true);
- word.setFontSize(9);
- word.insertText(text);
- word.insertEnter();
- word.moveForEnd();
- if(valve != codec->toUnicode("人孔盖"))
- {
- word.setFontSize(7);
- word.setFontBold(false);
- table = word.createTableWithColor(3, 4);
- if(valve == codec->toUnicode("安全阀") ){
- text = codec->toUnicode("第一次整定压力(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀"))
- {
- text = codec->toUnicode("第一次开启压力(kPa)");
- }
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, resultSetPressure1.toUtf8(),false);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text = codec->toUnicode("第一次密封压力(kPa)");
- }
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, resultSealPressure1.toUtf8(),false);
- if(valve == codec->toUnicode("安全阀") ){
- text = codec->toUnicode("第二次整定压力(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀"))
- {
- text = codec->toUnicode("第二次开启压力(kPa)");
- }
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, resultSetPressure2.toUtf8(),false);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text = codec->toUnicode("第二次密封压力(kPa)");
- }
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, resultSealPressure2.toUtf8(),false);
- if(valve == codec->toUnicode("安全阀") ){
- text = codec->toUnicode("第三次整定压力(kPa)");
- }
- else if(valve == codec->toUnicode("真空阀"))
- {
- text = codec->toUnicode("第三次开启压力(kPa)");
- }
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, resultSetPressure3.toUtf8(),false);
- if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
- text = codec->toUnicode("第三次密封压力(kPa)");
- }
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, resultSealPressure3.toUtf8(),false);
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- }else{
- word.setFontSize(7);
- word.setFontBold(false);
- table = word.createTableWithColor(3, 5);
- text = codec->toUnicode("第一次泄放压力(kPa)");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, resultSetPressure1.toUtf8(),false);
- text = codec->toUnicode("第一次密封压力(kPa)");
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, resultSealPressure1.toUtf8(),false);
- word.setCellText(table, 1, 5, resultSealPressure1_add.toUtf8(),false);
- text = codec->toUnicode("第二次泄放压力(kPa)");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, resultSetPressure2.toUtf8(),false);
- text = codec->toUnicode("第二次密封压力(kPa)");
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, resultSealPressure2.toUtf8(),false);
- word.setCellText(table, 2, 5, resultSealPressure2_add.toUtf8(),false);
- text = codec->toUnicode("第三次泄放压力(kPa)");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, resultSetPressure3.toUtf8(),false);
- text = codec->toUnicode("第三次密封压力(kPa)");
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, resultSealPressure3.toUtf8(),false);
- word.setCellText(table, 3, 5, resultSealPressure3_add.toUtf8(),false);
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- }
- word.insertEnter();
- word.insertEnter();
- word.insertEnter();
- //报告人员: 报告日期:
- QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
- word.setFontSize(10);
- word.setFontBold(true);
- text = codec->toUnicode(" 检测人员: 报告日期: ");
- word.insertText(text+current_Time);
- word.saveAs();
- word.close();
- sendWordReportProgress(text3);
- QThread::msleep(500);
- sendWordReportProgress("close");
- }
- //放弃接口
- void GenerateWord::receiveMsg(QString savePath, QString valve, QString manufacture, QString type, QString serialNumber, QString user, QString carplate, QString state, QString setPressure, QList<QPointF> points0, QList<QPointF> points1, QList<QPointF> points2, QList<QPointF> points3, QList<QPointF> points4, QList<QPointF> points5)
- {
- qDebug()<<"receiveMsg";
- QString text;
- QTextCodec *codec = QTextCodec::codecForName("GBK");
- QString text1 = codec->toUnicode("正在生成报告");
- QString text2 = codec->toUnicode("正在保存中...");
- QString text3 = codec->toUnicode("报告已完成");
- QString text4 = codec->toUnicode("打开word失败");
- QString title = manufacture+"_"+type+"_"+serialNumber;
- QWord word;
- if( !word.createNewWord(savePath) )
- {
- QString error = tr("Failed to export report,") + word.getStrErrorInfo();
- qDebug()<<error;
- sendWordReportProgress(text4);
- return;
- }
- word.setPageOrientation(0); //页面方向
- word.setWordPageView(3); //页面视图
- QString font;
- font=codec->toUnicode("宋体");
- word.setFontName(font);
- //标题
- word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
- word.setFontSize(10); //字体大小
- word.setFontBold(true); //字体加粗
- word.insertText(title);
- word.insertMoveDown();
- //1、基本信息 题目
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text=codec->toUnicode("1、基本信息");
- word.insertText(text);
- word.insertMoveDown();
- //基本信息表格
- word.setFontSize(7);
- word.setFontBold(false);
- QAxObject *table;
- table = word.createTableWithColor(4, 4);
- text = codec->toUnicode("制造单位");
- word.setCellText(table, 1, 1, text,true);
- word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
- text = codec->toUnicode("阀门型号");
- word.setCellText(table, 1, 3, text,true);
- word.setCellText(table, 1, 4, type.toUtf8(),false);
- text = codec->toUnicode("使用单位");
- word.setCellText(table, 2, 1, text,true);
- word.setCellText(table, 2, 2, user.toUtf8(),false);
- text = codec->toUnicode("出厂编号");
- word.setCellText(table, 2, 3, text,true);
- word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
- text = codec->toUnicode("车牌号");
- word.setCellText(table, 3, 1, text,true);
- word.setCellText(table, 3, 2, carplate.toUtf8(),false);
- text = codec->toUnicode("阀门类型");
- word.setCellText(table, 3, 3, text,true);
- word.setCellText(table, 3, 4, valve.toUtf8(),false);
- if(valve.toUtf8() == "安全阀"){
- text = codec->toUnicode("整定压力要求");
- word.setCellText(table, 4, 1, text,true);
- word.setCellText(table, 4, 2, setPressure.toUtf8(),false);
- }
- text = codec->toUnicode("阀门状态");
- word.setCellText(table, 4, 3, text,true);
- word.setCellText(table, 4, 4, state.toUtf8(),false);
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("2、第一次整定压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points0,"0.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("3、第二次整定压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points1,"1.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("4、第三次整定压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points2,"2.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points3,"3.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points4,"4.jpg");
- word.setFontSize(9);
- word.setParagraphAlignment(ALIGNMENT_LEFT);
- word.setFontBold(true);
- text = codec->toUnicode("安全阀");
- if(valve == text){
- text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
- }
- word.insertText(text);
- word.insertMoveDown();
- setTalbeCurve(word,points5,"5.jpg");
- //3、处理建议
- text=codec->toUnicode("3、试验结果");
- word.setFontBold(true);
- word.setFontSize(9);
- word.insertText(text);
- word.insertEnter();
- word.moveForEnd();
- table = word.createTable(1, 1);
- word.setCellText(table, 1, 1, "\r\r",false);
- word.autoFitBehavior(table,wdAutoFitWindow);
- word.moveForEnd();
- word.insertMoveDown();
- delete table;
- word.insertEnter();
- word.insertEnter();
- word.insertEnter();
- //报告人员: 报告日期:
- QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
- word.setFontSize(10);
- word.setFontBold(true);
- text = codec->toUnicode(" 报告人员: 报告日期: ");
- word.insertText(text+current_Time);
- word.saveAs();
- word.close();
- }
- //void GenerateWord::receiveMsg(QString savePath,QString valve,QString manufacture, QString type, QString serialNumber, QString user, QString carplate, QList<QPointF> points)
- //{
- // //qDebug()<<"receiveMsg";
- // QString text;
- // QTextCodec *codec = QTextCodec::codecForName("GBK");
- // QString text1 = codec->toUnicode("正在生成报告");
- // QString text2 = codec->toUnicode("正在保存中...");
- // QString text3 = codec->toUnicode("报告已完成");
- // QString text4 = codec->toUnicode("打开word失败");
- // QString title = manufacture+"-"+type+"-"+serialNumber;
- // QWord word;
- // if( !word.createNewWord(savePath) )
- // {
- // QString error = tr("Failed to export report,") + word.getStrErrorInfo();
- // qDebug()<<error;
- // sendWordReportProgress(text4);
- // return;
- // }
- // word.setPageOrientation(0); //页面方向
- // word.setWordPageView(3); //页面视图
- // QString font;
- // font=codec->toUnicode("宋体");
- // word.setFontName(font);
- // //标题
- // word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
- // word.setFontSize(10); //字体大小
- // word.setFontBold(true); //字体加粗
- // word.insertText(title);
- // word.insertMoveDown();
- // //1、基本信息 题目
- // word.setFontSize(9);
- // word.setParagraphAlignment(ALIGNMENT_LEFT);
- // word.setFontBold(true);
- // text=codec->toUnicode("1、基本信息");
- // word.insertText(text);
- // word.insertMoveDown();
- // //基本信息表格
- // word.setFontSize(7);
- // word.setFontBold(false);
- // QAxObject *table;
- // table = word.createTableWithColor(3, 4);
- // text = codec->toUnicode("制造单位");
- // word.setCellText(table, 1, 1, text,true);
- // word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
- // text = codec->toUnicode("阀门型号");
- // word.setCellText(table, 1, 3, text,true);
- // word.setCellText(table, 1, 4, type.toUtf8(),false);
- // text = codec->toUnicode("使用单位");
- // word.setCellText(table, 2, 1, text,true);
- // word.setCellText(table, 2, 2, user.toUtf8(),false);
- // text = codec->toUnicode("阀门编号");
- // word.setCellText(table, 2, 3, text,true);
- // word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
- // text = codec->toUnicode("车牌号");
- // word.setCellText(table, 3, 1, text,true);
- // word.setCellText(table, 3, 2, carplate.toUtf8(),false);
- // text = codec->toUnicode("阀门类型");
- // word.setCellText(table, 3, 3, text,true);
- // word.setCellText(table, 3, 4, valve.toUtf8(),false);
- // word.autoFitBehavior(table,wdAutoFitWindow);
- // word.moveForEnd();
- // word.insertMoveDown();
- // delete table;
- // //2、压力表格 题目
- // word.setFontSize(9);
- // word.setParagraphAlignment(ALIGNMENT_LEFT);
- // word.setFontBold(true);
- // text=codec->toUnicode("2、压力记录表");
- // word.insertText(text);
- // word.insertMoveDown();
- // //记录表格
- // word.setFontSize(7);
- // word.setFontBold(false);
- // int length = points.length();
- // int integer = length/10;
- // int remainder = length%10;
- // if(remainder > 0)
- // integer += 1;
- // table = word.createTableWithColor(integer, 10);
- // for(int i=0;i<length; i++){
- // QPointF point = points.at(i);
- // QString text = QString::number(point.y());
- // int lineNum = i/10+1;
- // int row = i%10+1;
- // word.setCellText(table, lineNum, row, text,false);
- // }
- // word.autoFitBehavior(table,wdAutoFitWindow);
- // word.moveForEnd();
- // word.insertMoveDown();
- // delete table;
- // //添加曲线图
- // word.AddPicture(QDir::currentPath()+"/1.jpg");
- // word.moveForEnd();
- // word.insertMoveDown();
- // word.insertEnter();
- // //3、处理建议
- // text=codec->toUnicode("3、试验结果");
- // word.setFontBold(true);
- // word.setFontSize(9);
- // word.insertText(text);
- // word.insertEnter();
- // word.moveForEnd();
- // table = word.createTable(1, 1);
- // word.setCellText(table, 1, 1, "\r\r",false);
- // word.autoFitBehavior(table,wdAutoFitWindow);
- // word.moveForEnd();
- // word.insertMoveDown();
- // delete table;
- // word.insertEnter();
- // word.insertEnter();
- // word.insertEnter();
- // //报告人员: 报告日期:
- // QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
- // word.setFontSize(10);
- // word.setFontBold(true);
- // text = codec->toUnicode(" 报告人员: 报告日期: ");
- // word.insertText(text+current_Time);
- // word.saveAs();
- // word.close();
- //}
|