generateword.cpp 38 KB

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