一键设置button

This script is only for Chinese mainland users. The script function is to help Beijing Construction Research Company set up excel forms with one click

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/430372/959236/%E4%B8%80%E9%94%AE%E8%AE%BE%E7%BD%AEbutton.js

  1. // ==UserScript==
  2. // @name 一键设置button
  3. // @namespace coderWyh
  4. // @version 1.0.5
  5. // @description This script is only for Chinese mainland users. The script function is to help Beijing Construction Research Company set up excel forms with one click
  6. // @author coderWyh
  7. // @match http://www.gczl360.com:8084/Admin/ZLKGL/Template*
  8. // @run-at document-end
  9. // @require https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js
  10. // @require https://gf.qytechs.cn/scripts/430198-%E7%A6%81%E6%AD%A2%E8%B0%83%E8%AF%95/code/%E7%A6%81%E6%AD%A2%E8%B0%83%E8%AF%95.js?version=956324
  11. // ==/UserScript==
  12. //此脚本仅对中国大陆用户使用,脚本是给北京建科研公司提供一键设置excel表格
  13. // 本代码所有权归作者所有 作者QQ:2471630907 手机号:18990193572 微信同手机号
  14. // 本代码具有知识产权 未经作者授权严禁任何人进行使用、传播、二次开发等一系列损害作者知识产权的操作
  15. // 作者对未经授权的操作保留起诉但不仅限于起诉的维护个人知识产权利益的法律途径
  16.  
  17. (function() {
  18. 'use strict';
  19. let valueMap = []
  20. axios.post(BASEURL+'jky/value/getCodeValue/'+autoSetButtonCode)
  21. .then(response =>{
  22. if (response.data.success) {
  23. $("body").append("<button style='position:absolute;top:10%;right:15%;background-color:peachpuff;border:1px solid;text-transform: uppercase;font-size: 14px;padding: 10px 20px;font-weight: 300;' class='autoSet'>自动设置</button>")
  24. $(".autoSet").on('click',
  25. function() {
  26. let url = location.href
  27. valueMap = response.data.data.valueList
  28. var sheet = spread.getActiveSheet();
  29. var sheetIndex_c = spread.getActiveSheetIndex();
  30. var colCount = sheet.getColumnCount();
  31. const list = [];
  32. const length = valueMap.length;
  33. let spanValue;
  34. let jcjg;
  35. let zkxm;
  36. let ybxm;
  37. let jcjl;
  38. let scjz2020;
  39. let oneValue;
  40. let scjz2020EndIndex;
  41. let rowCount = sheet.getRowCount();
  42. spread.suspendPaint();
  43. for (let i = 0; i < rowCount; i++) {
  44. for (let j = 0; j < colCount; j++) {
  45. let span = sheet.getSpans(new GC.Spread.Sheets.Range(i, j, 1, 1));
  46. if (span.length > 0) {
  47. if (list.length === 0) {
  48. spanValue = sheet.getText(i, j).replace(/\ +/g, "").replace(/[\r\n]/g, "");
  49. //OK 判断内容
  50. if (spanValue !== "") {
  51. if (spanValue.indexOf('编号')>=0) {
  52. if(sheet.getText(shan[0].row,shan[0].col+span[0].colCount).replace(/\ +/g, "").replace(/[\r\n]/g, "")!='001'){
  53. //TODO 判断编号后面不是001的情况
  54. }else {
  55. sheet.setText(span[0].row,span[0].col+span[0].colCount,'')
  56. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, 'bh1', '')
  57. }
  58. break
  59. }
  60. valueMap.map(item =>{
  61. if (spanValue === item.name) {
  62. if (spanValue.indexOf(':') >= 0 && spanValue.indexOf('编号') < 0 && spanValue.indexOf('工程名称') < 0) {
  63. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, item.value, 'sign')
  64. } else {
  65. if (spanValue === '年月日') {
  66. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col, item.value, '')
  67. } else {
  68. sheet.setText(span[0].row,span[0].col+span[0].colCount,'')
  69. let style = sheet.getStyle(span[0].row,span[0].col+span[0].colCount)
  70. style.backColor = '#FFFFFF'
  71. sheet.setStyle(span[0].row,span[0].col+span[0].colCount,style)
  72. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, item.value, '')
  73. }
  74. }
  75. }
  76. });
  77. list.push(span[0])
  78. }
  79. } else {
  80. A: for (let c = 0; c < list.length; c++) {
  81. for (let d = 0; d < list.length; d++) {
  82. if (list[d] === span[0]) {
  83. break A;
  84. }
  85. }
  86. spanValue = sheet.getText(i, j).replace(/\ +/g, "").replace(/[\r\n]/g, "");
  87. //OK 判断内容
  88. if (spanValue !== "") {
  89. if ((spanValue === '检查结果' || spanValue === '评判结果') && typeof(jcjg)==='undefined') {
  90. jcjg = span[0]
  91. break;
  92. }
  93. if (spanValue === '主控项目') {
  94. zkxm = span[0]
  95. break;
  96. }
  97. if (spanValue === '一般项目') {
  98. ybxm = span[0]
  99. break;
  100. }
  101. if ((spanValue === '检查记录' || spanValue === '施工单位质量评定记录') && typeof(jcjl)==='undefined') {
  102. jcjl = span[0]
  103. break;
  104. }
  105. if (spanValue.indexOf('四川省建设工程质量安全与监理协会')>=0) {
  106. scjz2020EndIndex = span[0].row
  107. break;
  108. }
  109. if (spanValue === '监理工程师(建设单位项目技术负责人):'||spanValue === '监理工程师(建设单位项目技术负责人):') {
  110. scjz2020 = span[0]
  111. }
  112. valueMap.map(item =>{
  113. if (spanValue === item.name) {
  114. if (spanValue.indexOf(':') >= 0 && spanValue.indexOf('编号') < 0 && spanValue.indexOf('工程名称') < 0) {
  115. if (sheet.getText(span[0].row,span[0].col+span[0].colCount) != '') {
  116. addTemplateAttArray(sheetIndex_c, span[0].row+span[0].rowCount, span[0].col, item.value, 'sign')
  117. } else {
  118. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, item.value, 'sign')
  119. }
  120. } else {
  121. if (spanValue === '年月日') {
  122. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col, item.value, '')
  123. } else {
  124. if (spanValue === '检验批部位' || spanValue.indexOf('工程名称') >=0 || spanValue.indexOf('编号') >=0 ||spanValue === '验收部位/区段' ) {
  125. sheet.setText(span[0].row,span[0].col+span[0].colCount,"")
  126. let style = sheet.getStyle(span[0].row,span[0].col+span[0].colCount)
  127. style.backColor = '#FFFFFF'
  128. sheet.setStyle(span[0].row,span[0].col+span[0].colCount,style)
  129. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, item.value, '')
  130. }
  131. else if (sheet.getText(span[0].row,span[0].col+span[0].colCount) != '') {
  132. sheet.setText(span[0].row+span[0].rowCount,span[0].col,"")
  133. let style = sheet.getStyle(span[0].row+span[0].rowCount,span[0].col)
  134. style.backColor = '#FFFFFF'
  135. sheet.setStyle(span[0].row+span[0].rowCount,span[0].col,style)
  136. addTemplateAttArray(sheetIndex_c, span[0].row + span[0].rowCount, span[0].col, item.value, '')
  137. } else {
  138. sheet.setText(span[0].row,span[0].col+span[0].colCount,"")
  139. let style = sheet.getStyle(span[0].row,span[0].col+span[0].colCount)
  140. style.backColor = '#FFFFFF'
  141. sheet.setStyle(span[0].row,span[0].col+span[0].colCount,style)
  142. addTemplateAttArray(sheetIndex_c, span[0].row, span[0].col + span[0].colCount, item.value, '')
  143. }
  144. }
  145. }
  146. }
  147. });
  148. }
  149. list.push(span[0])
  150. }
  151. }
  152. } else {
  153. oneValue = sheet.getText(i, j).replace(/\ +/g, "").replace(/[\r\n]/g, "");
  154. //OK 判断内容
  155. if (oneValue !== "") {
  156. if ((oneValue === '检查结果' || oneValue === '评判结果') && typeof(jcjg)==='undefined') {
  157. jcjg = {row: i,col: j,rowCount: 1,colCount: 1}
  158. break;
  159. }
  160. valueMap.map(item =>{
  161. if (oneValue === item.name) {
  162. if (oneValue.indexOf(':') >= 0 && oneValue.indexOf('编号') < 0 && oneValue.indexOf('工程名称') < 0) {
  163. addTemplateAttArray(sheetIndex_c, i, j+1, item.value, 'sign')
  164. } else {
  165. if (oneValue === '年月日') {
  166. addTemplateAttArray(sheetIndex_c, i, j, item.value, '')
  167. } else {
  168. sheet.setText(i,j+1,"")
  169. addTemplateAttArray(sheetIndex_c, i, j+1, item.value, '')
  170. }
  171. }
  172. }
  173. });
  174. }
  175. }
  176. }
  177. }
  178. // 设置检查记录
  179. if (jcjl != null) {
  180. if (ybxm != null) {
  181. let length = ybxm.row+ybxm.rowCount-jcjl.row
  182. for (let i = 1; i < length; i++) {
  183. if (sheet.getText(jcjl.row + i, jcjl.col)===''||sheet.getText(jcjl.row + i, jcjl.col)===null){
  184. addTemplateAttArray(sheetIndex_c, jcjl.row + i, jcjl.col, 's201403', '')
  185. }
  186. }
  187. }
  188. else {
  189. let length = zkxm.row+zkxm.rowCount-jcjl.row
  190. for (let i = 1;i < length; i++) {
  191. if(sheet.getText(jcjl.row + i, jcjl.col)===''||sheet.getText(jcjl.row + i, jcjl.col)===null){
  192. addTemplateAttArray(sheetIndex_c, jcjl.row + i, jcjl.col, 's201403', '')
  193. }
  194. }
  195. }
  196. }
  197. // 设置检查结果
  198. if (jcjg != null) {
  199. if (ybxm != null) {
  200. if (zkxm != null) {
  201. let style = new GC.Spread.Sheets.Style();
  202. style.borderBottom = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  203. style.borderRight = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  204. style.borderLeft = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  205. style.borderTop = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  206. style.cellButtons = [{
  207. imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
  208. command: 'openList',
  209. useButtonStyle: false,
  210. visibility: GC.Spread.Sheets.ButtonVisibility.onSelected
  211. }];
  212. style.dropDowns = [{
  213. type: GC.Spread.Sheets.DropDownType.list,
  214. option: {
  215. items: [{
  216. text: ' ',
  217. value: ' '
  218. },
  219. {
  220. text: '√',
  221. value: '√'
  222. },
  223. {
  224. text: '×',
  225. value: '×'
  226. },
  227. {
  228. text: '/',
  229. value: '/'
  230. }],
  231. multiSelect: false,
  232. valueType: 0,
  233. }
  234. }];
  235. let zkxmLen = zkxm.rowCount
  236. for (let i = 1; i <= zkxmLen+1; i++) {
  237. if(sheet.getText(jcjg.row+i,jcjg.col)===''||sheet.getText(jcjg.row+i,jcjg.col)===null) {
  238. sheet.setStyle(jcjg.row + i, jcjg.col, style);
  239. }
  240. }
  241.  
  242. let style1 = new GC.Spread.Sheets.Style();
  243. style1.borderBottom = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  244. style1.borderRight = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  245. style1.borderLeft = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  246. style1.borderTop = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  247. style1.cellButtons = [{
  248. imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
  249. command: 'openList',
  250. useButtonStyle: false,
  251. visibility: GC.Spread.Sheets.ButtonVisibility.onSelected
  252. }];
  253. style1.dropDowns = [{
  254. type: GC.Spread.Sheets.DropDownType.list,
  255. option: {
  256. items: [{
  257. text: ' ',
  258. value: ' '
  259. },
  260. {
  261. text: '√',
  262. value: '√'
  263. },
  264. {
  265. text: '×',
  266. value: '×'
  267. },
  268. {
  269. text: '/',
  270. value: '/'
  271. },
  272. {
  273. text: '%',
  274. value: '%'
  275. }],
  276. multiSelect: false,
  277. valueType: 0,
  278. }
  279. }];
  280. let ybxmLen = ybxm.rowCount
  281. for (let i = 0; i < ybxmLen; i++) {
  282. if(sheet.getText(ybxm.row+i,jcjg.col)===''||sheet.getText(ybxm.row+i,jcjg.col)===null) {
  283. sheet.setStyle(ybxm.row + i, jcjg.col, style1);
  284. }
  285. }
  286. } else {
  287. let style1 = new GC.Spread.Sheets.Style();
  288. style1.borderBottom = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  289. style1.borderRight = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  290. style1.borderLeft = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  291. style1.borderTop = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  292. style1.cellButtons = [{
  293. imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
  294. command: 'openList',
  295. useButtonStyle: false,
  296. visibility: GC.Spread.Sheets.ButtonVisibility.onSelected
  297. }];
  298. style1.dropDowns = [{
  299. type: GC.Spread.Sheets.DropDownType.list,
  300. option: {
  301. items: [{
  302. text: ' ',
  303. value: ' '
  304. },
  305. {
  306. text: '√',
  307. value: '√'
  308. },
  309. {
  310. text: '×',
  311. value: '×'
  312. },
  313. {
  314. text: '/',
  315. value: '/'
  316. },
  317. {
  318. text: '%',
  319. value: '%'
  320. }],
  321. multiSelect: false,
  322. valueType: 0,
  323. }
  324. }];
  325. let ybxmLen = ybxm.rowCount
  326. for (let i = 1; i <= ybxmLen; i++) {
  327. if(sheet.getText(ybxm.row+i,jcjg.col)===''||sheet.getText(ybxm.row+i,jcjg.col)===null) {
  328. sheet.setStyle(ybxm.row + i, jcjg.col, style1);
  329. }
  330. }
  331. }
  332. } else {
  333. let style = new GC.Spread.Sheets.Style();
  334. style.borderBottom = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  335. style.borderRight = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  336. style.borderLeft = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  337. style.borderTop = new GC.Spread.Sheets.LineBorder("#000000", GC.Spread.Sheets.LineStyle.thin);
  338. style.cellButtons = [{
  339. imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
  340. command: 'openList',
  341. useButtonStyle: false,
  342. visibility: GC.Spread.Sheets.ButtonVisibility.onSelected
  343. }];
  344. style.dropDowns = [{
  345. type: GC.Spread.Sheets.DropDownType.list,
  346. option: {
  347. items: [{
  348. text: ' ',
  349. value: ' '
  350. },
  351. {
  352. text: '√',
  353. value: '√'
  354. },
  355. {
  356. text: '×',
  357. value: '×'
  358. },
  359. {
  360. text: '/',
  361. value: '/'
  362. }],
  363. multiSelect: false,
  364. valueType: 0,
  365. }
  366. }];
  367. let zkxmLen = zkxm.rowCount
  368. for (let i = 1; i <= zkxmLen; i++) {
  369. if(sheet.getText(jcjg.row+i,jcjg.col)===''||sheet.getText(jcjg.row+i,jcjg.col)===null) {
  370. sheet.setStyle(jcjg.row + i, jcjg.col, style)
  371. }
  372. }
  373. }
  374. }
  375. // 单独处理四川建筑2020签字栏需要两个签名
  376. if (scjz2020 != null) {
  377. let span1 = sheet.getSpans(new GC.Spread.Sheets.Range(scjz2020.row, scjz2020.col+scjz2020.colCount, 1, 1))
  378. if (span1.length >0) {
  379. let style = sheet.getStyle(span1[0].row, span1[0].col + span1[0].colCount)
  380. style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
  381. style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
  382. sheet.setStyle(span1[0].row, span1[0].col + span1[0].colCount, style)
  383. addTemplateAttArray(sheetIndex_c, span1[0].row, span1[0].col + span1[0].colCount, 'p0205', 'sign')
  384. }
  385. }
  386. if(url.indexOf('ade8e564-4917-4f38-810f-e9b7ae9a54e0')>0) {
  387. for(let i=0;i<rowCount;i++){
  388. for(let j = 0;j<colCount;j++){
  389. let value = sheet.getText(i,j).replace(/\ +/g, "").replace(/[\r\n]/g, "")
  390. if (ybxm!=null||zkxm!=null) {
  391. if ((value != ''|| i<3||j===0||j===colCount||i>=scjz2020EndIndex-1) && (value != '年月日')){
  392. let style = sheet.getStyle(i,j)
  393. style.backColor = '#E0E0E0'
  394. sheet.setStyle(i,j,style)
  395. }
  396. }else{
  397. if ((value != ''|| i<3||j===0||j===colCount||i>=scjz2020EndIndex) && (value != '年月日')){
  398. let style = sheet.getStyle(i,j)
  399. style.backColor = '#E0E0E0'
  400. sheet.setStyle(i,j,style)
  401. }
  402. }
  403. }
  404. }
  405. let picture = sheet.pictures.add("pic001", 'http://www.gczl360.com:8084/Attach/PicData/2021-07-29/202107290458194590.jpg');
  406. picture.startRow(2);
  407. picture.startColumn(25);
  408. picture.endRow(2);
  409. picture.endColumn(28);
  410. picture.dynamicMove(false);
  411. picture.dynamicSize(true);
  412. }else {
  413. for(let i=0;i<rowCount;i++){
  414. for(let j = 0;j<colCount;j++){
  415. let value = sheet.getText(i,j).replace(/\ +/g, "").replace(/[\r\n]/g, "")
  416. if (ybxm!=null||zkxm!=null) {
  417. if ((value != ''|| i<3 ||j===colCount) && (value != '年月日')){
  418. let style = sheet.getStyle(i,j)
  419. style.backColor = '#E0E0E0'
  420. sheet.setStyle(i,j,style)
  421. }
  422. }else{
  423. if ((value != ''|| i<3 ||j===colCount) && (value != '年月日')){
  424. let style = sheet.getStyle(i,j)
  425. style.backColor = '#E0E0E0'
  426. sheet.setStyle(i,j,style)
  427. }
  428. }
  429. }
  430. }
  431. }
  432. spread.resumePaint();
  433. layer.msg("自动设置成功", {
  434. time: 1000
  435. });
  436.  
  437.  
  438. function addTemplateAttArray(sheetIndex, row, col, value, type) {
  439. for (let i = 0; i < attrArray.length; i++) {
  440. let item = attrArray[i]
  441. if (item.sheetIndex === sheetIndex && item.row === row && item.col === col) {
  442. item.value = value
  443. item.type = type
  444. return
  445. }
  446. }
  447. attrArray.push({ sheetIndex: sheetIndex, row: row, col: col, value: value , type:type})
  448. }
  449. });
  450. } else {
  451. $(".record_box>.slimScrollDiv").append("<div style='position:absolute;top:20%;left:2%;background-color:red;border:1px;text-transform: uppercase;font-size: 14px;padding: 5px 10px;font-weight: 300;color:white' class='tips'>"+response.data.message+autoSetButtonCode+"</div>")
  452.  
  453. }
  454. })
  455. .catch(error =>{
  456. console.log(error);
  457. })
  458.  
  459. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址