123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- #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)");
- //text="3.1、第一次负压开启压力试验记录表(kPa)";
- }
- else if(testType == "positive"){
- text=codec->toUnicode("2.1、第一次正压开启压力试验记录表(kPa)");
- //text="2.1、第一次正压开启压力试验记录表(kPa)";
- }
- else if(testType == "capsize"){
- text=codec->toUnicode("4.1、90°颠覆性密封试验记录表(kPa)");
- //text="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 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;
- 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;
- }
- 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();
- //}
|