generateword.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. #include <QTextCodec>
  2. #include <QDir>
  3. #include <QDebug>
  4. #include <QDateTime>
  5. #include <QThread>
  6. #include "generateword.h"
  7. #include "qword.h"
  8. GenerateWord::GenerateWord(QObject *parent) : QObject(parent)
  9. {
  10. }
  11. void setTalbeCurve(QWord &word,QList<QPointF> &points,QString picture)
  12. {
  13. word.setFontSize(7);
  14. word.setFontBold(false);
  15. QAxObject *table;
  16. int length = points.length();
  17. int integer = length/10;
  18. int remainder = length%10;
  19. if(remainder > 0)
  20. integer += 1;
  21. table = word.createTableWithColor(integer, 10);
  22. for(int i=0;i<length; i++){
  23. QPointF point = points.at(i);
  24. QString text = QString::number(point.y());
  25. int lineNum = i/10+1;
  26. int row = i%10+1;
  27. word.setCellText(table, lineNum, row, text,false);
  28. }
  29. word.autoFitBehavior(table,wdAutoFitWindow);
  30. word.moveForEnd();
  31. word.insertMoveDown();
  32. if(table != nullptr)
  33. delete table;
  34. //添加曲线图
  35. word.AddPicture(QDir::currentPath()+"/"+picture);
  36. word.moveForEnd();
  37. word.insertMoveDown();
  38. word.insertEnter();
  39. }
  40. void setTalbeCurve1(QWord &word,QList<QVariant> &points,QString picture)
  41. {
  42. if(points.length() == 0){
  43. word.insertEnter();
  44. return;
  45. }
  46. word.setFontSize(7);
  47. word.setFontBold(false);
  48. QAxObject *table;
  49. int length = points.length();
  50. int integer = length/10;
  51. int remainder = length%10;
  52. if(remainder > 0)
  53. integer += 1;
  54. table = word.createTableWithColor(integer, 10);
  55. for(int i=0;i<length; i++){
  56. QVariant variant = points.at(i);
  57. QPointF point = variant.toPointF();
  58. QString text = QString::number(point.y());
  59. int lineNum = i/10+1;
  60. int row = i%10+1;
  61. word.setCellText(table, lineNum, row, text,false);
  62. }
  63. word.autoFitBehavior(table,wdAutoFitWindow);
  64. word.moveForEnd();
  65. word.insertMoveDown();
  66. if(table != nullptr)
  67. delete table;
  68. //添加曲线图
  69. word.AddPicture(QDir::currentPath()+"/"+picture);
  70. word.moveForEnd();
  71. word.insertMoveDown();
  72. word.insertEnter();
  73. }
  74. void GenerateWord::breatheValveRecordWrite(QWord &word,QString testType, QVariant &obj)
  75. {
  76. QString text;
  77. QString picture;
  78. QAxObject *table;
  79. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  80. QVariantMap map = obj.toMap();
  81. QList<QVariant> points0 = map["pointList0"].toList();
  82. QList<QVariant> points1 = map["pointList1"].toList();
  83. QList<QVariant> points2 = map["pointList2"].toList();
  84. QList<QVariant> points3 = map["pointList3"].toList();
  85. QList<QVariant> points4 = map["pointList4"].toList();
  86. QList<QVariant> points5 = map["pointList5"].toList();
  87. QString resultSetPressure1 = map["resultSetPressure1"].toString();
  88. QString resultSetPressure2 = map["resultSetPressure2"].toString();
  89. QString resultSetPressure3 = map["resultSetPressure3"].toString();
  90. QString resultSealPressure1 = map["resultSealPressure1"].toString();
  91. QString resultSealPressure2 = map["resultSealPressure2"].toString();
  92. QString resultSealPressure3 = map["resultSealPressure3"].toString();
  93. //第一次 开启压力试验
  94. word.setFontSize(9);
  95. word.setParagraphAlignment(ALIGNMENT_LEFT);
  96. word.setFontBold(true);
  97. if(testType == "negative"){
  98. text=codec->toUnicode("3.1、第一次负压开启压力试验记录表(kPa)");
  99. //text="3.1、第一次负压开启压力试验记录表(kPa)";
  100. }
  101. else if(testType == "positive"){
  102. text=codec->toUnicode("2.1、第一次正压开启压力试验记录表(kPa)");
  103. //text="2.1、第一次正压开启压力试验记录表(kPa)";
  104. }
  105. else if(testType == "capsize"){
  106. text=codec->toUnicode("4.1、90°颠覆性密封试验记录表(kPa)");
  107. //text="4.1、90°颠覆性密封试验记录表(kPa)";
  108. }
  109. word.insertText(text);
  110. word.insertMoveDown();
  111. if(testType == "positive"){
  112. picture= "2.1.jpg";
  113. }
  114. else if(testType == "negative"){
  115. picture= "3.1.jpg";
  116. }
  117. else if(testType == "capsize"){
  118. picture= "4.1.jpg";
  119. }
  120. setTalbeCurve1(word,points0,picture);
  121. //第二次 开启压力试验
  122. word.setFontSize(9);
  123. word.setParagraphAlignment(ALIGNMENT_LEFT);
  124. word.setFontBold(true);
  125. if(testType == "positive"){
  126. text=codec->toUnicode("2.2、第二次正压开启压力试验记录表(kPa)");
  127. }
  128. else if(testType == "negative"){
  129. text=codec->toUnicode("3.2、第二次负压开启压力试验记录表(kPa)");
  130. }
  131. else if(testType == "capsize"){
  132. text=codec->toUnicode("4.2、180°颠覆性密封试验记录表(kPa)");
  133. }
  134. word.insertText(text);
  135. word.insertMoveDown();
  136. if(testType == "positive"){
  137. picture= "2.2.jpg";
  138. }
  139. else if(testType == "negative"){
  140. picture= "3.2.jpg";
  141. }
  142. else if(testType == "capsize"){
  143. picture= "4.2.jpg";
  144. }
  145. setTalbeCurve1(word,points1,picture);
  146. //第三次 开启压力试验
  147. word.setFontSize(9);
  148. word.setParagraphAlignment(ALIGNMENT_LEFT);
  149. word.setFontBold(true);
  150. if(testType == "positive"){
  151. text=codec->toUnicode("2.3、第三次正压开启压力试验记录表(kPa)");
  152. }
  153. else if(testType == "negative"){
  154. text=codec->toUnicode("3.3、第三次负压开启压力试验记录表(kPa)");
  155. }
  156. else if(testType == "capsize"){
  157. text=codec->toUnicode("4.3、270°颠覆性密封试验记录表(kPa)");
  158. }
  159. word.insertText(text);
  160. word.insertMoveDown();
  161. if(testType == "positive"){
  162. picture= "2.3.jpg";
  163. }
  164. else if(testType == "negative"){
  165. picture= "3.3.jpg";
  166. }
  167. else if(testType == "capsize"){
  168. picture= "4.3.jpg";
  169. }
  170. setTalbeCurve1(word,points2,picture);
  171. if(testType == "capsize"){
  172. goto result;
  173. }
  174. //第一次 密封压力试验
  175. word.setFontSize(9);
  176. word.setParagraphAlignment(ALIGNMENT_LEFT);
  177. word.setFontBold(true);
  178. if(testType == "positive"){
  179. text=codec->toUnicode("2.4、第一次正压密封压力试验记录表(kPa)");
  180. }
  181. else if(testType == "negative"){
  182. text=codec->toUnicode("3.4、第一次负压密封压力试验记录表(kPa)");
  183. }
  184. word.insertText(text);
  185. word.insertMoveDown();
  186. if(testType == "positive"){
  187. picture= "2.4.jpg";
  188. }
  189. else if(testType == "negative"){
  190. picture= "3.4.jpg";
  191. }
  192. setTalbeCurve1(word,points3,picture);
  193. //第二次 密封压力试验
  194. word.setFontSize(9);
  195. word.setParagraphAlignment(ALIGNMENT_LEFT);
  196. word.setFontBold(true);
  197. if(testType == "positive"){
  198. text=codec->toUnicode("2.5、第二次正压密封压力试验记录表(kPa)");
  199. }
  200. else if(testType == "negative"){
  201. text=codec->toUnicode("3.5、第二次负压密封压力试验记录表(kPa)");
  202. }
  203. word.insertText(text);
  204. word.insertMoveDown();
  205. if(testType == "positive"){
  206. picture= "2.5.jpg";
  207. }
  208. else if(testType == "negative"){
  209. picture= "3.5.jpg";
  210. }
  211. setTalbeCurve1(word,points4,picture);
  212. //第三次 密封压力试验
  213. word.setFontSize(9);
  214. word.setParagraphAlignment(ALIGNMENT_LEFT);
  215. word.setFontBold(true);
  216. if(testType == "positive"){
  217. text=codec->toUnicode("2.6、第三次正压密封压力试验记录表(kPa)");
  218. }
  219. else if(testType == "negative"){
  220. text=codec->toUnicode("3.6、第三次负压密封压力试验记录表(kPa)");
  221. }
  222. word.insertText(text);
  223. word.insertMoveDown();
  224. if(testType == "positive"){
  225. picture= "2.6.jpg";
  226. }
  227. else if(testType == "negative"){
  228. picture= "3.6.jpg";
  229. }
  230. setTalbeCurve1(word,points5,picture);
  231. //试验结果
  232. result:
  233. if(testType == "positive"){
  234. text=codec->toUnicode("2.7、正压开启压力和密封试验结果");
  235. }
  236. else if(testType == "negative"){
  237. text=codec->toUnicode("3.7、负压开启压力和密封试验结果");
  238. }
  239. else if(testType == "capsize"){
  240. text=codec->toUnicode("4.4、颠覆性密封试验结果");
  241. }
  242. word.setFontBold(true);
  243. word.setFontSize(9);
  244. word.insertText(text);
  245. word.insertEnter();
  246. word.moveForEnd();
  247. if(testType == "capsize"){
  248. word.setFontSize(7);
  249. word.setFontBold(false);
  250. table = word.createTableWithColor(3, 2);
  251. text=codec->toUnicode("90°颠覆性密封试验结果");
  252. word.setCellText(table, 1, 1, text,true);
  253. word.setCellText(table, 1, 2, resultSealPressure1.toUtf8(),false);
  254. text=codec->toUnicode("180°颠覆性密封试验结果");
  255. word.setCellText(table, 2, 1, text,true);
  256. word.setCellText(table, 2, 2, resultSealPressure2.toUtf8(),false);
  257. text=codec->toUnicode("270°颠覆性密封试验结果");
  258. word.setCellText(table, 3, 1, text,true);
  259. word.setCellText(table, 3, 2, resultSealPressure3.toUtf8(),false);
  260. }
  261. else{
  262. word.setFontSize(7);
  263. word.setFontBold(false);
  264. table = word.createTableWithColor(3, 4);
  265. if(testType == "positive")
  266. text=codec->toUnicode("第一次正压开启压力(kPa)");
  267. else if(testType == "negative")
  268. text=codec->toUnicode("第一次负压开启压力(kPa)");
  269. word.setCellText(table, 1, 1, text,true);
  270. word.setCellText(table, 1, 2, resultSetPressure1.toUtf8(),false);
  271. if(testType == "positive")
  272. text=codec->toUnicode("第一次正压密封压力(kPa)");
  273. else if(testType == "negative")
  274. text=codec->toUnicode("第一次负压密封压力(kPa)");
  275. word.setCellText(table, 1, 3, text,true);
  276. word.setCellText(table, 1, 4, resultSealPressure1.toUtf8(),false);
  277. if(testType == "positive")
  278. text=codec->toUnicode("第二次正压开启压力(kPa)");
  279. else if(testType == "negative")
  280. text=codec->toUnicode("第二次负压开启压力(kPa)");
  281. word.setCellText(table, 2, 1, text,true);
  282. word.setCellText(table, 2, 2, resultSetPressure2.toUtf8(),false);
  283. if(testType == "positive")
  284. text=codec->toUnicode("第二次正压密封压力(kPa)");
  285. else if(testType == "negative")
  286. text=codec->toUnicode("第二次负压密封压力(kPa)");
  287. word.setCellText(table, 2, 3, text,true);
  288. word.setCellText(table, 2, 4, resultSealPressure2.toUtf8(),false);
  289. if(testType == "positive")
  290. text=codec->toUnicode("第三次正压开启压力(kPa)");
  291. else if(testType == "negative")
  292. text=codec->toUnicode("第三次负压开启压力(kPa)");
  293. word.setCellText(table, 3, 1, text,true);
  294. word.setCellText(table, 3, 2, resultSetPressure3.toUtf8(),false);
  295. if(testType == "positive")
  296. text=codec->toUnicode("第三次正压密封压力(kPa)");
  297. else if(testType == "negative")
  298. text=codec->toUnicode("第三次负压密封压力(kPa)");
  299. word.setCellText(table, 3, 3, text,true);
  300. word.setCellText(table, 3, 4, resultSealPressure3.toUtf8(),false);
  301. }
  302. word.autoFitBehavior(table,wdAutoFitWindow);
  303. word.moveForEnd();
  304. word.insertMoveDown();
  305. delete table;
  306. }
  307. void GenerateWord::receiveGenerateBreatheValveWord(QString savePath, QVariant para,QVariant obj1, QVariant obj2, QVariant obj3)
  308. {
  309. qDebug()<<"receiveGenerateBreatheValveWord";
  310. QVariantMap map = para.toMap();
  311. QString manufacture = map["manufacture"].toString();
  312. QString type = map["type"].toString();
  313. QString serialNumber = map["serialNumber"].toString();
  314. QString user = map["user"].toString();
  315. QString carplate = map["carplate"].toString();
  316. QString valve = map["valve"].toString();
  317. QString setPressure = map["setPressure"].toString();
  318. QString state = map["state"].toString();
  319. QString text;
  320. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  321. QString text1 = codec->toUnicode("正在生成报告,请耐心等待");
  322. QString text2 = codec->toUnicode("正在保存中...");
  323. QString text3 = codec->toUnicode("报告已完成");
  324. QString text4 = codec->toUnicode("打开word失败");
  325. QString title = manufacture+"_"+type+"_"+serialNumber;
  326. sendWordReportProgress(text1);
  327. QThread::sleep(1);
  328. QWord word;
  329. if( !word.createNewWord(savePath) )
  330. {
  331. QString error = tr("Failed to export report,") + word.getStrErrorInfo();
  332. qDebug()<<error;
  333. sendWordReportProgress(text4);
  334. QThread::msleep(500);
  335. sendWordReportProgress("close");
  336. return;
  337. }
  338. word.setPageOrientation(0); //页面方向
  339. word.setWordPageView(3); //页面视图
  340. //字体选择
  341. QString font;
  342. font=codec->toUnicode("宋体");
  343. word.setFontName(font);
  344. //标题
  345. word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
  346. word.setFontSize(10); //字体大小
  347. word.setFontBold(true); //字体加粗
  348. word.insertText(title);
  349. word.insertMoveDown();
  350. //1、基本信息 题目
  351. word.setFontSize(9);
  352. word.setParagraphAlignment(ALIGNMENT_LEFT);
  353. word.setFontBold(true);
  354. text=codec->toUnicode("1、基本信息");
  355. word.insertText(text);
  356. word.insertMoveDown();
  357. //基本信息表格
  358. word.setFontSize(7);
  359. word.setFontBold(false);
  360. QAxObject *table;
  361. table = word.createTableWithColor(4, 4);
  362. text = codec->toUnicode("制造单位");
  363. word.setCellText(table, 1, 1, text,true);
  364. word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
  365. text = codec->toUnicode("阀门型号");
  366. word.setCellText(table, 1, 3, text,true);
  367. word.setCellText(table, 1, 4, type.toUtf8(),false);
  368. text = codec->toUnicode("使用单位");
  369. word.setCellText(table, 2, 1, text,true);
  370. word.setCellText(table, 2, 2, user.toUtf8(),false);
  371. text = codec->toUnicode("出厂编号");
  372. word.setCellText(table, 2, 3, text,true);
  373. word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
  374. text = codec->toUnicode("车牌号");
  375. word.setCellText(table, 3, 1, text,true);
  376. word.setCellText(table, 3, 2, carplate.toUtf8(),false);
  377. text = codec->toUnicode("阀门类型");
  378. word.setCellText(table, 3, 3, text,true);
  379. word.setCellText(table, 3, 4, valve.toUtf8(),false);
  380. text = codec->toUnicode("阀门状态");
  381. word.setCellText(table, 4, 1, text,true);
  382. word.setCellText(table, 4, 2, state.toUtf8(),false);
  383. //自动对齐
  384. word.autoFitBehavior(table,wdAutoFitWindow);
  385. word.moveForEnd();
  386. word.insertMoveDown();
  387. delete table;
  388. breatheValveRecordWrite(word,"positive", obj1);
  389. breatheValveRecordWrite(word,"negative", obj2);
  390. breatheValveRecordWrite(word,"capsize", obj3);
  391. word.insertEnter();
  392. word.insertEnter();
  393. word.insertEnter();
  394. //报告人员: 报告日期:
  395. QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
  396. word.setFontSize(10);
  397. word.setFontBold(true);
  398. text = codec->toUnicode(" 检测人员: 报告日期: ");
  399. word.insertText(text+current_Time);
  400. word.saveAs();
  401. word.close();
  402. sendWordReportProgress(text3);
  403. QThread::msleep(500);
  404. sendWordReportProgress("close");
  405. }
  406. void GenerateWord::receiveGenerateWord(QString savePath, QVariant obj)
  407. {
  408. qDebug()<<"receiveMsg";
  409. QVariantMap map = obj.toMap();
  410. QList<QVariant> points0 = map["pointList0"].toList();
  411. QList<QVariant> points1 = map["pointList1"].toList();
  412. QList<QVariant> points2 = map["pointList2"].toList();
  413. QList<QVariant> points3 = map["pointList3"].toList();
  414. QList<QVariant> points4 = map["pointList4"].toList();
  415. QList<QVariant> points5 = map["pointList5"].toList();
  416. QString manufacture = map["manufacture"].toString();
  417. QString type = map["type"].toString();
  418. QString serialNumber = map["serialNumber"].toString();
  419. QString user = map["user"].toString();
  420. QString carplate = map["carplate"].toString();
  421. QString valve = map["valve"].toString();
  422. QString setPressure = map["setPressure"].toString();
  423. QString state = map["state"].toString();
  424. QString resultSetPressure1 = map["resultSetPressure1"].toString();
  425. QString resultSetPressure2 = map["resultSetPressure2"].toString();
  426. QString resultSetPressure3 = map["resultSetPressure3"].toString();
  427. QString resultSealPressure1 = map["resultSealPressure1"].toString();
  428. QString resultSealPressure2 = map["resultSealPressure2"].toString();
  429. QString resultSealPressure3 = map["resultSealPressure3"].toString();
  430. QString text;
  431. QTextCodec *codec = QTextCodec::codecForName("GBK");
  432. QString text1 = codec->toUnicode("正在生成报告,请耐心等待");
  433. QString text2 = codec->toUnicode("正在保存中...");
  434. QString text3 = codec->toUnicode("报告已完成");
  435. QString text4 = codec->toUnicode("打开word失败");
  436. QString title = manufacture+"_"+type+"_"+serialNumber;
  437. sendWordReportProgress(text1);
  438. QWord word;
  439. if( !word.createNewWord(savePath) )
  440. {
  441. QString error = tr("Failed to export report,") + word.getStrErrorInfo();
  442. qDebug()<<error;
  443. sendWordReportProgress(text4);
  444. QThread::msleep(500);
  445. sendWordReportProgress("close");
  446. return;
  447. }
  448. word.setPageOrientation(0); //页面方向
  449. word.setWordPageView(3); //页面视图
  450. QString font;
  451. font=codec->toUnicode("宋体");
  452. word.setFontName(font);
  453. //标题
  454. word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
  455. word.setFontSize(10); //字体大小
  456. word.setFontBold(true); //字体加粗
  457. word.insertText(title);
  458. word.insertMoveDown();
  459. //1、基本信息 题目
  460. word.setFontSize(9);
  461. word.setParagraphAlignment(ALIGNMENT_LEFT);
  462. word.setFontBold(true);
  463. text=codec->toUnicode("1、基本信息");
  464. word.insertText(text);
  465. word.insertMoveDown();
  466. //基本信息表格
  467. word.setFontSize(7);
  468. word.setFontBold(false);
  469. QAxObject *table;
  470. table = word.createTableWithColor(4, 4);
  471. text = codec->toUnicode("制造单位");
  472. word.setCellText(table, 1, 1, text,true);
  473. word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
  474. text = codec->toUnicode("阀门型号");
  475. word.setCellText(table, 1, 3, text,true);
  476. word.setCellText(table, 1, 4, type.toUtf8(),false);
  477. text = codec->toUnicode("使用单位");
  478. word.setCellText(table, 2, 1, text,true);
  479. word.setCellText(table, 2, 2, user.toUtf8(),false);
  480. text = codec->toUnicode("出厂编号");
  481. word.setCellText(table, 2, 3, text,true);
  482. word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
  483. text = codec->toUnicode("车牌号");
  484. word.setCellText(table, 3, 1, text,true);
  485. word.setCellText(table, 3, 2, carplate.toUtf8(),false);
  486. text = codec->toUnicode("阀门类型");
  487. word.setCellText(table, 3, 3, text,true);
  488. word.setCellText(table, 3, 4, valve.toUtf8(),false);
  489. text=codec->toUnicode("安全阀");
  490. if(valve.toUtf8() == text){
  491. text = codec->toUnicode("整定压力要求");
  492. word.setCellText(table, 4, 3, text,true);
  493. word.setCellText(table, 4, 4, setPressure.toUtf8(),false);
  494. }
  495. text=codec->toUnicode("真空阀");
  496. if(valve.toUtf8() == text){
  497. text = codec->toUnicode("设计外压");
  498. word.setCellText(table, 4, 3, text,true);
  499. word.setCellText(table, 4, 4, setPressure.toUtf8(),false);
  500. }
  501. text = codec->toUnicode("阀门状态");
  502. word.setCellText(table, 4, 1, text,true);
  503. word.setCellText(table, 4, 2, state.toUtf8(),false);
  504. word.autoFitBehavior(table,wdAutoFitWindow);
  505. word.moveForEnd();
  506. word.insertMoveDown();
  507. delete table;
  508. word.setFontSize(9);
  509. word.setParagraphAlignment(ALIGNMENT_LEFT);
  510. word.setFontBold(true);
  511. if(valve == codec->toUnicode("安全阀")){
  512. text=codec->toUnicode("2、第一次整定压力试验记录表(kPa)");
  513. }
  514. else if(valve == codec->toUnicode("真空阀")){
  515. text=codec->toUnicode("2、第一次开启压力试验记录表(kPa)");
  516. }
  517. else if(valve == codec->toUnicode("人孔盖")){
  518. text=codec->toUnicode("2、第一次泄放压力试验记录表(kPa)");
  519. }
  520. word.insertText(text);
  521. word.insertMoveDown();
  522. setTalbeCurve1(word,points0,"0.jpg");
  523. word.setFontSize(9);
  524. word.setParagraphAlignment(ALIGNMENT_LEFT);
  525. word.setFontBold(true);
  526. if(valve == codec->toUnicode("安全阀")){
  527. text=codec->toUnicode("3、第二次整定压力试验记录表(kPa)");
  528. }
  529. else if(valve == codec->toUnicode("真空阀")){
  530. text=codec->toUnicode("3、第二次开启压力试验记录表(kPa)");
  531. }
  532. else if(valve == codec->toUnicode("人孔盖")){
  533. text=codec->toUnicode("3、第二次泄放压力试验记录表(kPa)");
  534. }
  535. word.insertText(text);
  536. word.insertMoveDown();
  537. setTalbeCurve1(word,points1,"1.jpg");
  538. word.setFontSize(9);
  539. word.setParagraphAlignment(ALIGNMENT_LEFT);
  540. word.setFontBold(true);
  541. if(valve == codec->toUnicode("安全阀")){
  542. text=codec->toUnicode("4、第三次整定压力试验记录表(kPa)");
  543. }
  544. else if(valve == codec->toUnicode("真空阀")){
  545. text=codec->toUnicode("4、第三次开启压力试验记录表(kPa)");
  546. }
  547. else if(valve == codec->toUnicode("人孔盖")){
  548. text=codec->toUnicode("4、第三次泄放压力试验记录表(kPa)");
  549. }
  550. word.insertText(text);
  551. word.insertMoveDown();
  552. setTalbeCurve1(word,points2,"2.jpg");
  553. word.setFontSize(9);
  554. word.setParagraphAlignment(ALIGNMENT_LEFT);
  555. word.setFontBold(true);
  556. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  557. text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
  558. }
  559. else if(valve == codec->toUnicode("人孔盖")){
  560. text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
  561. }
  562. word.insertText(text);
  563. word.insertMoveDown();
  564. setTalbeCurve1(word,points3,"3.jpg");
  565. word.setFontSize(9);
  566. word.setParagraphAlignment(ALIGNMENT_LEFT);
  567. word.setFontBold(true);
  568. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  569. text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
  570. }
  571. else if(valve == codec->toUnicode("人孔盖")){
  572. text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
  573. }
  574. word.insertText(text);
  575. word.insertMoveDown();
  576. setTalbeCurve1(word,points4,"4.jpg");
  577. word.setFontSize(9);
  578. word.setParagraphAlignment(ALIGNMENT_LEFT);
  579. word.setFontBold(true);
  580. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  581. text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
  582. }
  583. else if(valve == codec->toUnicode("人孔盖")){
  584. text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
  585. }
  586. word.insertText(text);
  587. word.insertMoveDown();
  588. setTalbeCurve1(word,points5,"5.jpg");
  589. //3、处理建议
  590. text=codec->toUnicode("8、试验结果");
  591. word.setFontBold(true);
  592. word.setFontSize(9);
  593. word.insertText(text);
  594. word.insertEnter();
  595. word.moveForEnd();
  596. if(valve != codec->toUnicode("人孔盖"))
  597. {
  598. word.setFontSize(7);
  599. word.setFontBold(false);
  600. table = word.createTableWithColor(3, 4);
  601. if(valve == codec->toUnicode("安全阀") ){
  602. text = codec->toUnicode("第一次整定压力(kPa)");
  603. }
  604. else if(valve == codec->toUnicode("真空阀"))
  605. {
  606. text = codec->toUnicode("第一次开启压力(kPa)");
  607. }
  608. word.setCellText(table, 1, 1, text,true);
  609. word.setCellText(table, 1, 2, resultSetPressure1.toUtf8(),false);
  610. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  611. text = codec->toUnicode("第一次密封压力(kPa)");
  612. }
  613. word.setCellText(table, 1, 3, text,true);
  614. word.setCellText(table, 1, 4, resultSealPressure1.toUtf8(),false);
  615. if(valve == codec->toUnicode("安全阀") ){
  616. text = codec->toUnicode("第二次整定压力(kPa)");
  617. }
  618. else if(valve == codec->toUnicode("真空阀"))
  619. {
  620. text = codec->toUnicode("第二次开启压力(kPa)");
  621. }
  622. word.setCellText(table, 2, 1, text,true);
  623. word.setCellText(table, 2, 2, resultSetPressure2.toUtf8(),false);
  624. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  625. text = codec->toUnicode("第二次密封压力(kPa)");
  626. }
  627. word.setCellText(table, 2, 3, text,true);
  628. word.setCellText(table, 2, 4, resultSealPressure2.toUtf8(),false);
  629. if(valve == codec->toUnicode("安全阀") ){
  630. text = codec->toUnicode("第三次整定压力(kPa)");
  631. }
  632. else if(valve == codec->toUnicode("真空阀"))
  633. {
  634. text = codec->toUnicode("第三次开启压力(kPa)");
  635. }
  636. word.setCellText(table, 3, 1, text,true);
  637. word.setCellText(table, 3, 2, resultSetPressure3.toUtf8(),false);
  638. if(valve == codec->toUnicode("安全阀") || valve == codec->toUnicode("真空阀")){
  639. text = codec->toUnicode("第三次密封压力(kPa)");
  640. }
  641. word.setCellText(table, 3, 3, text,true);
  642. word.setCellText(table, 3, 4, resultSealPressure3.toUtf8(),false);
  643. word.autoFitBehavior(table,wdAutoFitWindow);
  644. word.moveForEnd();
  645. word.insertMoveDown();
  646. delete table;
  647. }
  648. word.insertEnter();
  649. word.insertEnter();
  650. word.insertEnter();
  651. //报告人员: 报告日期:
  652. QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
  653. word.setFontSize(10);
  654. word.setFontBold(true);
  655. text = codec->toUnicode(" 检测人员: 报告日期: ");
  656. word.insertText(text+current_Time);
  657. word.saveAs();
  658. word.close();
  659. sendWordReportProgress(text3);
  660. QThread::msleep(500);
  661. sendWordReportProgress("close");
  662. }
  663. //放弃接口
  664. 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)
  665. {
  666. qDebug()<<"receiveMsg";
  667. QString text;
  668. QTextCodec *codec = QTextCodec::codecForName("GBK");
  669. QString text1 = codec->toUnicode("正在生成报告");
  670. QString text2 = codec->toUnicode("正在保存中...");
  671. QString text3 = codec->toUnicode("报告已完成");
  672. QString text4 = codec->toUnicode("打开word失败");
  673. QString title = manufacture+"_"+type+"_"+serialNumber;
  674. QWord word;
  675. if( !word.createNewWord(savePath) )
  676. {
  677. QString error = tr("Failed to export report,") + word.getStrErrorInfo();
  678. qDebug()<<error;
  679. sendWordReportProgress(text4);
  680. return;
  681. }
  682. word.setPageOrientation(0); //页面方向
  683. word.setWordPageView(3); //页面视图
  684. QString font;
  685. font=codec->toUnicode("宋体");
  686. word.setFontName(font);
  687. //标题
  688. word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
  689. word.setFontSize(10); //字体大小
  690. word.setFontBold(true); //字体加粗
  691. word.insertText(title);
  692. word.insertMoveDown();
  693. //1、基本信息 题目
  694. word.setFontSize(9);
  695. word.setParagraphAlignment(ALIGNMENT_LEFT);
  696. word.setFontBold(true);
  697. text=codec->toUnicode("1、基本信息");
  698. word.insertText(text);
  699. word.insertMoveDown();
  700. //基本信息表格
  701. word.setFontSize(7);
  702. word.setFontBold(false);
  703. QAxObject *table;
  704. table = word.createTableWithColor(4, 4);
  705. text = codec->toUnicode("制造单位");
  706. word.setCellText(table, 1, 1, text,true);
  707. word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
  708. text = codec->toUnicode("阀门型号");
  709. word.setCellText(table, 1, 3, text,true);
  710. word.setCellText(table, 1, 4, type.toUtf8(),false);
  711. text = codec->toUnicode("使用单位");
  712. word.setCellText(table, 2, 1, text,true);
  713. word.setCellText(table, 2, 2, user.toUtf8(),false);
  714. text = codec->toUnicode("出厂编号");
  715. word.setCellText(table, 2, 3, text,true);
  716. word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
  717. text = codec->toUnicode("车牌号");
  718. word.setCellText(table, 3, 1, text,true);
  719. word.setCellText(table, 3, 2, carplate.toUtf8(),false);
  720. text = codec->toUnicode("阀门类型");
  721. word.setCellText(table, 3, 3, text,true);
  722. word.setCellText(table, 3, 4, valve.toUtf8(),false);
  723. if(valve.toUtf8() == "安全阀"){
  724. text = codec->toUnicode("整定压力要求");
  725. word.setCellText(table, 4, 1, text,true);
  726. word.setCellText(table, 4, 2, setPressure.toUtf8(),false);
  727. }
  728. text = codec->toUnicode("阀门状态");
  729. word.setCellText(table, 4, 3, text,true);
  730. word.setCellText(table, 4, 4, state.toUtf8(),false);
  731. word.autoFitBehavior(table,wdAutoFitWindow);
  732. word.moveForEnd();
  733. word.insertMoveDown();
  734. delete table;
  735. word.setFontSize(9);
  736. word.setParagraphAlignment(ALIGNMENT_LEFT);
  737. word.setFontBold(true);
  738. text = codec->toUnicode("安全阀");
  739. if(valve == text){
  740. text=codec->toUnicode("2、第一次整定压力试验记录表(kPa)");
  741. }
  742. word.insertText(text);
  743. word.insertMoveDown();
  744. setTalbeCurve(word,points0,"0.jpg");
  745. word.setFontSize(9);
  746. word.setParagraphAlignment(ALIGNMENT_LEFT);
  747. word.setFontBold(true);
  748. text = codec->toUnicode("安全阀");
  749. if(valve == text){
  750. text=codec->toUnicode("3、第二次整定压力试验记录表(kPa)");
  751. }
  752. word.insertText(text);
  753. word.insertMoveDown();
  754. setTalbeCurve(word,points1,"1.jpg");
  755. word.setFontSize(9);
  756. word.setParagraphAlignment(ALIGNMENT_LEFT);
  757. word.setFontBold(true);
  758. text = codec->toUnicode("安全阀");
  759. if(valve == text){
  760. text=codec->toUnicode("4、第三次整定压力试验记录表(kPa)");
  761. }
  762. word.insertText(text);
  763. word.insertMoveDown();
  764. setTalbeCurve(word,points2,"2.jpg");
  765. word.setFontSize(9);
  766. word.setParagraphAlignment(ALIGNMENT_LEFT);
  767. word.setFontBold(true);
  768. text = codec->toUnicode("安全阀");
  769. if(valve == text){
  770. text=codec->toUnicode("5、第一次密封压力试验记录表(kPa)");
  771. }
  772. word.insertText(text);
  773. word.insertMoveDown();
  774. setTalbeCurve(word,points3,"3.jpg");
  775. word.setFontSize(9);
  776. word.setParagraphAlignment(ALIGNMENT_LEFT);
  777. word.setFontBold(true);
  778. text = codec->toUnicode("安全阀");
  779. if(valve == text){
  780. text=codec->toUnicode("6、第二次密封压力试验记录表(kPa)");
  781. }
  782. word.insertText(text);
  783. word.insertMoveDown();
  784. setTalbeCurve(word,points4,"4.jpg");
  785. word.setFontSize(9);
  786. word.setParagraphAlignment(ALIGNMENT_LEFT);
  787. word.setFontBold(true);
  788. text = codec->toUnicode("安全阀");
  789. if(valve == text){
  790. text=codec->toUnicode("7、第三次密封压力试验记录表(kPa)");
  791. }
  792. word.insertText(text);
  793. word.insertMoveDown();
  794. setTalbeCurve(word,points5,"5.jpg");
  795. //3、处理建议
  796. text=codec->toUnicode("3、试验结果");
  797. word.setFontBold(true);
  798. word.setFontSize(9);
  799. word.insertText(text);
  800. word.insertEnter();
  801. word.moveForEnd();
  802. table = word.createTable(1, 1);
  803. word.setCellText(table, 1, 1, "\r\r",false);
  804. word.autoFitBehavior(table,wdAutoFitWindow);
  805. word.moveForEnd();
  806. word.insertMoveDown();
  807. delete table;
  808. word.insertEnter();
  809. word.insertEnter();
  810. word.insertEnter();
  811. //报告人员: 报告日期:
  812. QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
  813. word.setFontSize(10);
  814. word.setFontBold(true);
  815. text = codec->toUnicode(" 报告人员: 报告日期: ");
  816. word.insertText(text+current_Time);
  817. word.saveAs();
  818. word.close();
  819. }
  820. //void GenerateWord::receiveMsg(QString savePath,QString valve,QString manufacture, QString type, QString serialNumber, QString user, QString carplate, QList<QPointF> points)
  821. //{
  822. // //qDebug()<<"receiveMsg";
  823. // QString text;
  824. // QTextCodec *codec = QTextCodec::codecForName("GBK");
  825. // QString text1 = codec->toUnicode("正在生成报告");
  826. // QString text2 = codec->toUnicode("正在保存中...");
  827. // QString text3 = codec->toUnicode("报告已完成");
  828. // QString text4 = codec->toUnicode("打开word失败");
  829. // QString title = manufacture+"-"+type+"-"+serialNumber;
  830. // QWord word;
  831. // if( !word.createNewWord(savePath) )
  832. // {
  833. // QString error = tr("Failed to export report,") + word.getStrErrorInfo();
  834. // qDebug()<<error;
  835. // sendWordReportProgress(text4);
  836. // return;
  837. // }
  838. // word.setPageOrientation(0); //页面方向
  839. // word.setWordPageView(3); //页面视图
  840. // QString font;
  841. // font=codec->toUnicode("宋体");
  842. // word.setFontName(font);
  843. // //标题
  844. // word.setParagraphAlignment(ALIGNMENT_MIDDLE); //下面文字位置
  845. // word.setFontSize(10); //字体大小
  846. // word.setFontBold(true); //字体加粗
  847. // word.insertText(title);
  848. // word.insertMoveDown();
  849. // //1、基本信息 题目
  850. // word.setFontSize(9);
  851. // word.setParagraphAlignment(ALIGNMENT_LEFT);
  852. // word.setFontBold(true);
  853. // text=codec->toUnicode("1、基本信息");
  854. // word.insertText(text);
  855. // word.insertMoveDown();
  856. // //基本信息表格
  857. // word.setFontSize(7);
  858. // word.setFontBold(false);
  859. // QAxObject *table;
  860. // table = word.createTableWithColor(3, 4);
  861. // text = codec->toUnicode("制造单位");
  862. // word.setCellText(table, 1, 1, text,true);
  863. // word.setCellText(table, 1, 2, manufacture.toUtf8(),false);
  864. // text = codec->toUnicode("阀门型号");
  865. // word.setCellText(table, 1, 3, text,true);
  866. // word.setCellText(table, 1, 4, type.toUtf8(),false);
  867. // text = codec->toUnicode("使用单位");
  868. // word.setCellText(table, 2, 1, text,true);
  869. // word.setCellText(table, 2, 2, user.toUtf8(),false);
  870. // text = codec->toUnicode("阀门编号");
  871. // word.setCellText(table, 2, 3, text,true);
  872. // word.setCellText(table, 2, 4, serialNumber.toUtf8(),false);
  873. // text = codec->toUnicode("车牌号");
  874. // word.setCellText(table, 3, 1, text,true);
  875. // word.setCellText(table, 3, 2, carplate.toUtf8(),false);
  876. // text = codec->toUnicode("阀门类型");
  877. // word.setCellText(table, 3, 3, text,true);
  878. // word.setCellText(table, 3, 4, valve.toUtf8(),false);
  879. // word.autoFitBehavior(table,wdAutoFitWindow);
  880. // word.moveForEnd();
  881. // word.insertMoveDown();
  882. // delete table;
  883. // //2、压力表格 题目
  884. // word.setFontSize(9);
  885. // word.setParagraphAlignment(ALIGNMENT_LEFT);
  886. // word.setFontBold(true);
  887. // text=codec->toUnicode("2、压力记录表");
  888. // word.insertText(text);
  889. // word.insertMoveDown();
  890. // //记录表格
  891. // word.setFontSize(7);
  892. // word.setFontBold(false);
  893. // int length = points.length();
  894. // int integer = length/10;
  895. // int remainder = length%10;
  896. // if(remainder > 0)
  897. // integer += 1;
  898. // table = word.createTableWithColor(integer, 10);
  899. // for(int i=0;i<length; i++){
  900. // QPointF point = points.at(i);
  901. // QString text = QString::number(point.y());
  902. // int lineNum = i/10+1;
  903. // int row = i%10+1;
  904. // word.setCellText(table, lineNum, row, text,false);
  905. // }
  906. // word.autoFitBehavior(table,wdAutoFitWindow);
  907. // word.moveForEnd();
  908. // word.insertMoveDown();
  909. // delete table;
  910. // //添加曲线图
  911. // word.AddPicture(QDir::currentPath()+"/1.jpg");
  912. // word.moveForEnd();
  913. // word.insertMoveDown();
  914. // word.insertEnter();
  915. // //3、处理建议
  916. // text=codec->toUnicode("3、试验结果");
  917. // word.setFontBold(true);
  918. // word.setFontSize(9);
  919. // word.insertText(text);
  920. // word.insertEnter();
  921. // word.moveForEnd();
  922. // table = word.createTable(1, 1);
  923. // word.setCellText(table, 1, 1, "\r\r",false);
  924. // word.autoFitBehavior(table,wdAutoFitWindow);
  925. // word.moveForEnd();
  926. // word.insertMoveDown();
  927. // delete table;
  928. // word.insertEnter();
  929. // word.insertEnter();
  930. // word.insertEnter();
  931. // //报告人员: 报告日期:
  932. // QString current_Time = QDateTime::currentDateTime().toString("yyyy-MM-dd");
  933. // word.setFontSize(10);
  934. // word.setFontBold(true);
  935. // text = codec->toUnicode(" 报告人员: 报告日期: ");
  936. // word.insertText(text+current_Time);
  937. // word.saveAs();
  938. // word.close();
  939. //}