sheet_common.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. var sheetCommonObj = {
  5. // CSL.2017.06.05
  6. // createSpread、initSheet 在一个Spread多个Sheet分别调用时的情况下使用。
  7. createSpread: function(container, SheetCount){
  8. var me = this;
  9. var spreadBook = new GC.Spread.Sheets.Workbook(container, { sheetCount: SheetCount });
  10. spreadBook.options.tabStripVisible = false;
  11. spreadBook.options.showHorizontalScrollbar = true;
  12. spreadBook.options.showVerticalScrollbar = true;
  13. spreadBook.options.allowCopyPasteExcelStyle = false;
  14. spreadBook.options.allowUserDragDrop = true;
  15. spreadBook.options.allowContextMenu = false;
  16. spreadBook.options.allowUserEditFormula = false;
  17. spreadBook.options.showDragFillSmartTag = false;
  18. return spreadBook;
  19. },
  20. initSheet: function(sheet, setting, rowCount) {
  21. var me = this;
  22. var spreadNS = GC.Spread.Sheets;
  23. if(setting.headRows == 2){
  24. return me.buildSpanHeader(sheet, setting, rowCount);//初始化合并表格列头
  25. }
  26. sheet.suspendPaint();
  27. sheet.suspendEvent();
  28. if(setting.frozenCols) sheet.frozenColumnCount(setting.frozenCols);//冻结列s
  29. sheet.setRowCount(setting.headRows ? setting.headRows : 1, spreadNS.SheetArea.colHeader);
  30. sheet.setColumnCount(setting.header.length, spreadNS.SheetArea.viewport);
  31. if (setting && setting.view && setting.view.colHeaderHeight) {
  32. sheet.setRowHeight(0, setting.view.colHeaderHeight, spreadNS.SheetArea.colHeader);
  33. };
  34. if (setting && setting.view && setting.view.rowHeaderWidth) {
  35. sheet.setColumnWidth(0, setting.view.rowHeaderWidth, spreadNS.SheetArea.rowHeader);
  36. };
  37. if (setting.emptyRowHeader) {
  38. sheet.setColumnWidth(0, 1, GC.Spread.Sheets.SheetArea.rowHeader);
  39. }
  40. sheet.options.colHeaderAutoTextIndex = 1;
  41. sheet.options.colHeaderAutoText = spreadNS.HeaderAutoText.numbers;
  42. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  43. sheet.options.protectionOptions = {
  44. allowResizeColumns: true
  45. };
  46. sheet.showRowOutline(false);
  47. sheet.options.allowCellOverflow = false;
  48. me.buildHeader(sheet, setting);
  49. sheet.resumeEvent();
  50. sheet.resumePaint();
  51. },
  52. // buildSheet 在一个Spread、一个Sheet的情况下使用。
  53. buildSheet: function(container, setting, rowCount) {
  54. var me = this;
  55. var spreadBook = me.createSpread(container, { sheetCount: 1 });
  56. var sheet = spreadBook.getSheet(0);
  57. me.initSheet(sheet, setting, rowCount);
  58. return spreadBook;
  59. },
  60. buildSpanHeader:function (sheet, setting, rowCount) {
  61. let temSetting = {
  62. "emptyRows":0,
  63. "headRows":2,
  64. "headRowHeight":[21],
  65. "defaultRowHeight": 21,
  66. "treeCol": 0,
  67. "cols":[]
  68. };
  69. let spanSetting = sheetCommonObj.transferToTreeSetting(setting,temSetting);
  70. TREE_SHEET_HELPER.loadSheetHeader(spanSetting,sheet,rowCount);
  71. },
  72. buildHeader: function(sheet, setting){
  73. var me = this, ch = GC.Spread.Sheets.SheetArea.colHeader;
  74. for (var i = 0; i < setting.header.length; i++) {
  75. sheet.setValue(0, i, setting.header[i].headerName, ch);
  76. sheet.getCell(0, i, ch).wordWrap(true);
  77. sheet.setColumnWidth(i, setting.header[i].headerWidth?setting.header[i].headerWidth:100);
  78. sheet.setColumnVisible(i,setting.header[i].visible === false ? false:true);
  79. }
  80. },
  81. getHeadersFromTreeSetting: function (treeSetting) {
  82. const vAlignMap = ['top', 'center', 'bottom'];
  83. const hAlignMap = ['left', 'center', 'right'];
  84. return treeSetting.cols.map(item => {
  85. const vAlign = vAlignMap[item.data.vAlign];
  86. const hAlign = hAlignMap[item.data.hAlign];
  87. return {
  88. name: item.head.titleNames[0],
  89. dataCode: item.data.field,
  90. width: item.width,
  91. vAlign,
  92. hAlign,
  93. };
  94. });
  95. },
  96. setHeader: function(sheet, headers) {
  97. sheet.suspendPaint();
  98. sheet.suspendEvent();
  99. sheet.setColumnCount(headers.length);
  100. sheet.setRowHeight(0, 30, GC.Spread.Sheets.SheetArea.colHeader);
  101. headers.forEach((header, index) => {
  102. sheet.setValue(0, index, header.name, GC.Spread.Sheets.SheetArea.colHeader);
  103. sheet.setColumnWidth(index, header.width, GC.Spread.Sheets.SheetArea.colHeader);
  104. if (header.formatter) {
  105. sheet.setFormatter(-1, index, header.formatter);
  106. }
  107. sheet.getRange(-1, index, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[header.hAlign]);
  108. sheet.getRange(-1, index, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[header.vAlign]);
  109. });
  110. sheet.resumeEvent();
  111. sheet.resumePaint();
  112. },
  113. cleanSheet: function(sheet, setting, rowCount) {
  114. sheet.suspendPaint();
  115. sheet.suspendEvent();
  116. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  117. if (rowCount > 0) sheet.setRowCount(rowCount);
  118. sheet.clearSelection();
  119. sheet.resumeEvent();
  120. sheet.resumePaint();
  121. },
  122. cleanData: function (sheet, setting, rowCount) {
  123. sheet.suspendPaint();
  124. sheet.suspendEvent();
  125. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  126. if (rowCount > 0) sheet.setRowCount(rowCount);
  127. sheet.resumeEvent();
  128. sheet.resumePaint();
  129. },
  130. setAreaAlign: function(area, hAlign, vAlign){
  131. if (!(hAlign) || hAlign === "left") {
  132. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  133. } else if (hAlign === "right") {
  134. area.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  135. } else if (hAlign === "center") {
  136. area.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  137. } else {
  138. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  139. }
  140. if (!(vAlign) || vAlign === "center") {
  141. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  142. } else if (vAlign === "top") {
  143. area.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  144. } else if (vAlign === "bottom") {
  145. area.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  146. } else {
  147. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  148. }
  149. },
  150. showTreeData:function (sheet,setting,data) {
  151. let ch = GC.Spread.Sheets.SheetArea.viewport;
  152. let parentMap=_.groupBy(data, 'ParentID');
  153. let visibleMap = {};
  154. let styleRow=[];
  155. sheet.suspendPaint();
  156. sheet.suspendEvent();
  157. for (let col = 0; col < setting.header.length; col++) {
  158. let hAlign = "left", vAlign = "center";
  159. if (setting.header[col].hAlign) {
  160. hAlign = setting.header[col].hAlign;
  161. } else if (setting.header[col].dataType !== "String"){
  162. hAlign = "right";
  163. }
  164. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  165. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  166. if (setting.header[col].formatter) {
  167. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  168. }
  169. if(setting.header[col].cellType === "comboBox"){
  170. this.setComboBox(-1,col,sheet,setting.header[col].options,setting.header[col].editorValueType,setting.header[col].editable,setting.header[col].maxDropDownItems);
  171. }
  172. for (let row = 0; row < data.length; row++) {
  173. if(data[row].cellType === 'comboBox'){
  174. let options = data[row].options ? data[row].options.split("@") : [];
  175. this.setComboBox(row,col,sheet,options);
  176. }else if(data[row].cellType === 'String'){//默认设置字符输入,避免出现输入10:01变成日期的情况
  177. sheet.setFormatter(row, col,"@", GC.Spread.Sheets.SheetArea.viewport);
  178. }
  179. let val = data[row][setting.header[col].dataCode];
  180. if(val&&setting.header[col].dataType === "Number"){
  181. if(setting.header[col].hasOwnProperty('decimalField')){
  182. let decimal = getDecimal(setting.header[col].decimalField);
  183. val =scMathUtil.roundToString(val,decimal);
  184. sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
  185. }else {
  186. val =scMathUtil.roundToString(val,2);
  187. }
  188. }
  189. if(val!=null && setting.header[col].cellType == "checkBox"){
  190. this.setCheckBoxCell(row,col,sheet,val);
  191. }
  192. sheet.setValue(row, col, val, ch);
  193. if(col==0){
  194. let treeType = sheetCommonObj.getTreeNodeCellType(data,row,parentMap);
  195. sheet.getCell(row, 0).cellType(treeType);
  196. visibleMap[data[row].ID] = treeType.collapsed;
  197. this.setRowVisible(data,row,visibleMap,sheet);
  198. }
  199. if(data[row].bgColour) styleRow.push(row)
  200. }
  201. }
  202. for(let r of styleRow){
  203. this.setRowStyle(r,sheet,data[r].bgColour);
  204. }
  205. this.lockCells(sheet,setting);
  206. sheet.resumeEvent();
  207. sheet.resumePaint();
  208. },
  209. setRowVisible:function (data,row,visibleMap,sheet) {
  210. sheet.getRange(row , -1, 1, -1).visible(getVisible(data[row].ParentID));//显示或隐藏
  211. function getVisible(ParentID) {
  212. if(visibleMap[ParentID]) return false //如果父节点是缩起的,那就隐藏本身。
  213. if(visibleMap[ParentID] == false){//如果父节点不是缩起的,要再往父节点找看
  214. let pnode = _.find(data,{'ID':ParentID});
  215. if(pnode) return getVisible(pnode.ParentID);//如果有父节点,递归调用
  216. return true;//没有,返回显示
  217. }
  218. }
  219. },
  220. setSheetBySetting: function (sheet, setting) {
  221. function setCellType(range, cellType) {
  222. let type;
  223. if (cellType === 'checkBox') {
  224. type = new GC.Spread.Sheets.CellTypes.CheckBox();
  225. }
  226. range.cellType(type);
  227. }
  228. setting.header.forEach((item, index) => {
  229. const range = sheet.getRange(-1, index, -1, 1);
  230. this.setAreaAlign(range, item.hAlign, item.vAlign);
  231. if (item.cellType) {
  232. console.log(item);
  233. setCellType(range, item.cellType);
  234. }
  235. if (item.formatter) {
  236. range.formatter(item.formatter)
  237. }
  238. });
  239. },
  240. appendData: function (sheet, index, rowIndex, setting, data) {
  241. /*const viewport = GC.Spread.Sheets.SheetArea.viewport;
  242. const rowHeader = GC.Spread.Sheets.SheetArea.rowHeader;*/
  243. if (!index) {
  244. sheet.setRowCount(0);
  245. }
  246. sheet.suspendPaint();
  247. sheet.suspendEvent();
  248. // 追加空行
  249. sheet.addRows(index, data.length);
  250. // 显示数据
  251. data.forEach((item, rIdx) => {
  252. const row = index + rIdx;
  253. setting.header.forEach((hItem, cIdx) => {
  254. const dataCode = hItem.dataCode;
  255. const val = gljUtil.isDef(item[dataCode]) ? item[dataCode] : '';
  256. sheet.setValue(row, cIdx, val);
  257. });
  258. });
  259. sheet.resumeEvent();
  260. sheet.resumePaint();
  261. },
  262. showData: function(sheet, setting, data,distTypeTree,callback) {
  263. var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  264. sheet.suspendPaint();
  265. sheet.suspendEvent();
  266. //sheet.addRows(row, 1);
  267. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  268. if(sheet.getRowCount()<data.length){
  269. data.length<30? sheet.setRowCount(30):sheet.setRowCount(data.length);
  270. }else if(sheet.getRowCount()==0){
  271. sheet.setRowCount(30);
  272. }
  273. for (var col = 0; col < setting.header.length; col++) {
  274. var hAlign = "left", vAlign = "center";
  275. if (setting.header[col].hAlign) {
  276. hAlign = setting.header[col].hAlign;
  277. } else if (setting.header[col].dataType !== "String"){
  278. hAlign = "right";
  279. }
  280. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  281. me.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  282. if (setting.header[col].formatter) {
  283. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  284. }
  285. if(setting.headRows != 2 && setting.header[col].cellType === "checkBox"||setting.header[col].cellType === "button"){//clear and reset 2019 - 11- 11 加入了多行列头的判断情况,排除多行列头时清空操作,先试运行看是否有问题
  286. var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
  287. sheet.deleteColumns(col,1);
  288. sheet.addColumns(col, 1);
  289. sheet.setValue(0, col, setting.header[col].headerName, header);
  290. sheet.setColumnWidth(col, setting.header[col].headerWidth?setting.header[col].headerWidth:100);
  291. }
  292. if(setting.header[col].visible!==null&&setting.header[col].visible!==undefined){
  293. sheet.setColumnVisible(col,setting.header[col].visible);
  294. }
  295. sheet.getCell(0, col, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  296. }
  297. for (var row = 0; row < data.length; row++) {
  298. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  299. this.showRowData(sheet,setting,row,data,distTypeTree);
  300. if(setting.getStyle && setting.getStyle(data[row])){
  301. sheet.setStyle(row, -1, setting.getStyle(data[row]));
  302. }
  303. }
  304. if(setting.emptyRowHeader){
  305. let rowCount = sheet.getRowCount();
  306. for (let row = 0; row < rowCount; row++) {
  307. sheet.setValue(row, 0, '', GC.Spread.Sheets.SheetArea.rowHeader);
  308. }
  309. }
  310. this.lockCells(sheet,setting);
  311. if(callback) callback();
  312. sheet.resumeEvent();
  313. sheet.resumePaint();
  314. //me.shieldAllCells(sheet);
  315. },
  316. showRowData:function (sheet,setting,row,data,distTypeTree=null) {
  317. let ch = GC.Spread.Sheets.SheetArea.viewport;
  318. if(data[row].cellType == "date"){//日期格式比较特殊,要判断数据里的属性,为data类型,同时读取列
  319. this.setDatePickerCellType(row,data[row].dateCol,sheet)
  320. }
  321. if(data[row].cellType === 'comboBox'){//对于选项在数据里下拉框类型,同时读取列
  322. let options = data[row].options ? data[row].options.split("@") : [];
  323. this.setComboBox(row,data[row].dateCol,sheet,options);
  324. }
  325. for (var col = 0; col < setting.header.length; col++) {
  326. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  327. var val = data[row][setting.header[col].dataCode];
  328. let style = null;
  329. if(data[row].foreColor && data[row].styleCol == col){
  330. style = {foreColor: data[row].foreColor};
  331. sheet.setStyle(row, col, {foreColor: data[row].foreColor});
  332. }
  333. if(val&&setting.header[col].dataType === "Number"){
  334. if(setting.header[col].hasOwnProperty('tofix')){
  335. val =scMathUtil.roundToString(val,setting.header[col].tofix);
  336. }
  337. else if(setting.header[col].hasOwnProperty('decimalField')){
  338. var decimal = getDecimal(setting.header[col].decimalField);
  339. val =scMathUtil.roundToString(val,decimal);
  340. sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
  341. }else {
  342. val =val+'';
  343. }
  344. }
  345. if(val!=null&&setting.header[col].cellType === "checkBox"){
  346. this.setCheckBoxCell(row,col,sheet,val)
  347. }
  348. if(setting.header[col].cellType === "comboBox"){
  349. this.setComboBox(row,col,sheet,setting.header[col].options,setting.header[col].editorValueType,setting.header[col].editable,setting.header[col].maxDropDownItems);
  350. }
  351. if(setting.header[col].cellType === "selectButton"){
  352. this.setSelectButton(row,col,sheet,setting.header[col]);
  353. }
  354. if(setting.header[col].cellType === "replaceButton"){
  355. this.setReplaceButton(row,col,sheet,setting.header[col]);
  356. }
  357. if(setting.header[col].cellType === "cusButton"){
  358. this.setCusButton(row,col,sheet,setting,style);
  359. }
  360. if(setting.header[col].cellType === "tipsCell"){
  361. this.setTipsCell(row,col,sheet,setting.header[col]);
  362. }
  363. if(setting.owner==='gljTree'){
  364. if(setting.header[col].cellType === "checkBox"){
  365. val==1?val:0;
  366. this.setCheckBoxCell(row,col,sheet,val);
  367. }
  368. if(setting.header[col].dataCode === 'gljType' && data[row].gljType){
  369. let distTypeVal = distTypeTree.distTypes[distTypeTree.prefix + data[row].gljType].data.fullName;
  370. val=distTypeVal;
  371. }
  372. }
  373. if(setting.header[col].getText){
  374. val = setting.getText[setting.header[col].getText](data[row],val)
  375. }
  376. sheet.setValue(row, col, val, ch);
  377. }
  378. this.setRowStyle(row,sheet,data[row].bgColour);
  379. if(setting.autoFit==true){//设置自动行高
  380. if(setting.fitRow && setting.fitRow.length > 0){//如果有设置特定的某些列才需要自动行高就按设置的来,没有设置就默认所有列
  381. for(let dataCode of setting.fitRow){
  382. let col = _.findIndex(setting.header,{dataCode:dataCode})
  383. sheet.getCell(row,col).wordWrap(true);
  384. }
  385. }else {
  386. sheet.getRange(row, -1, 1, -1, GC.Spread.Sheets.SheetArea.viewport).wordWrap(true);
  387. }
  388. sheet.autoFitRow(row);
  389. }
  390. },
  391. checkData : function(col,setting, value) {
  392. let result = true;
  393. let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
  394. if (validator === null) {
  395. return result;
  396. }
  397. switch (validator) {
  398. case 'number':
  399. let regular = /^\d+(\.\d+)?$/;
  400. result = regular.test(value);
  401. break;
  402. case 'boolean':
  403. let booleanValue = [true, false];
  404. result = booleanValue.indexOf(value) >= 0;
  405. break;
  406. }
  407. return result;
  408. },
  409. //todo
  410. analyzePasteData: function(setting, pastedInfo) {
  411. var rst = [], propId = pastedInfo.cellRange.col, preStrIdx = 0, itemObj = {};//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  412. for (var i = 0; i < pastedInfo.pasteData.text.length; i++) {
  413. if (pastedInfo.pasteData.text[i] === "\n") {
  414. propId = pastedInfo.cellRange.col;//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  415. preStrIdx = i + 1;
  416. rst.push(itemObj);
  417. if (i < pastedInfo.pasteData.text.length - 1) {
  418. itemObj = {};
  419. }
  420. } else if (pastedInfo.pasteData.text[i] === "\t" || pastedInfo.pasteData.text[i] === "\r") {
  421. if (setting.header[propId]) {
  422. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx, i);
  423. }
  424. propId++;
  425. preStrIdx = i + 1;
  426. //if the last copied-cell were empty, should check whether the end of text
  427. if (i == pastedInfo.pasteData.text.length - 1 && setting.header[propId]) {
  428. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  429. rst.push(itemObj);
  430. }
  431. } else if (i == pastedInfo.pasteData.text.length - 1 && setting.header[propId]) {
  432. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  433. rst.push(itemObj);
  434. }
  435. }
  436. return rst;
  437. },
  438. combineRowData: function(sheet, setting, row) {
  439. var rst = {};
  440. for (var col = 0; col < setting.header.length; col++) {
  441. rst[setting.header[col].dataCode] = sheet.getValue(row, col);
  442. }
  443. return rst;
  444. },
  445. shieldAllCells: function(sheet) {
  446. sheet.options.isProtected = true;
  447. },
  448. unShieldAllCells: function(sheet) {
  449. sheet.options.isProtected = false;
  450. },
  451. lockCells: function(sheet, setting){
  452. if (setting && setting.view.lockColumns && setting.view.lockColumns.length > 0) {
  453. sheet.options.isProtected = true;
  454. sheet.getRange(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  455. for (var i = 0; i < setting.view.lockColumns.length; i++) {
  456. let col = setting.view.lockColumns[i];
  457. if(_.isString(col)){//如果是dataCode 进行转换
  458. col = _.findIndex(setting.header,{dataCode:col})
  459. }
  460. sheet.getRange(-1,col, -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  461. }
  462. }
  463. if (setting && Array.isArray(setting.view.lockRows) && setting.view.lockRows.length) {
  464. if (!setting.view.lockColumns || !setting.view.lockColumns.length) {
  465. sheet.options.isProtected = true;
  466. sheet.getRange(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  467. }
  468. setting.view.lockRows.forEach(row => {
  469. sheet.getRange(row, -1, 1, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  470. });
  471. }
  472. },
  473. setCheckBoxCell(row,col,sheet,val){
  474. var c = this.getCheckBox();
  475. sheet.setCellType(row, col,c,GC.Spread.Sheets.SheetArea.viewport);
  476. sheet.getCell(row, col).value(val);
  477. sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  478. },
  479. getCheckBox(threeState = false){
  480. var c = new GC.Spread.Sheets.CellTypes.CheckBox();
  481. c.isThreeState(threeState);
  482. return c
  483. },
  484. // 无法勾选的复选框
  485. getReadOnlyCheckBox () {
  486. function ReadOnlyCheckBox() {}
  487. ReadOnlyCheckBox.prototype = new GC.Spread.Sheets.CellTypes.CheckBox();
  488. ReadOnlyCheckBox.prototype.processMouseUp = function () {
  489. return;
  490. };
  491. return new ReadOnlyCheckBox();
  492. },
  493. setComboBox(row,col,sheet,options,editorValueType,editable,maxDropDownItems){
  494. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  495. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  496. if(options){
  497. dynamicCombo.items(options);
  498. if(maxDropDownItems) dynamicCombo.maxDropDownItems(maxDropDownItems);
  499. if(editable == true) dynamicCombo.editable(true);//可编辑
  500. if(editorValueType==true){
  501. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  502. }
  503. }
  504. sheet.setCellType(row, col,dynamicCombo,GC.Spread.Sheets.SheetArea.viewport);
  505. },
  506. setRowStyle(row,sheet,bgColour) {
  507. if(bgColour){
  508. let style = new GC.Spread.Sheets.Style();
  509. style.backColor = bgColour;
  510. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  511. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  512. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  513. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  514. sheet.setStyle(row, -1, style);
  515. }
  516. },
  517. getCustomerCoeCellType: function (htmlGenerator,setEditorValue,updateCallback) {
  518. let me = this;
  519. function CustomerCoeCellType() {
  520. this.isEscKey=false;
  521. this.displayText='';
  522. }
  523. CustomerCoeCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  524. CustomerCoeCellType.prototype.createEditorElement = function (context) {
  525. console.log("create editor")
  526. let element = document.createElement("div");//这里创建的,会自动销毁
  527. return element
  528. };
  529. CustomerCoeCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  530. if (editorContext) {
  531. $editor = $(editorContext);
  532. $editor.css("position", "fixed");
  533. $editor.css("background", "white");
  534. //$editor.css("width", cellRect.width); 2018-11-15 改成固定列宽
  535. $editor.css("width", 160);
  536. $editor.attr("gcUIElement", "gcEditingInput");
  537. if(htmlGenerator) htmlGenerator(context,cellRect,$editor);
  538. }
  539. }
  540. CustomerCoeCellType.prototype.deactivateEditor = function (editorContext, context) {
  541. };
  542. CustomerCoeCellType.prototype.setEditorValue = function (editor, value, context) {
  543. console.log("set editor value");
  544. this.displayText = value;
  545. };
  546. CustomerCoeCellType.prototype.getEditorValue = function (editor, context) {
  547. console.log("get value");
  548. if(this.isEscKey !=true&& updateCallback){
  549. updateCallback();
  550. }
  551. this.isEscKey = false;
  552. return this.displayText;
  553. };
  554. CustomerCoeCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  555. console.log(" update editor");
  556. if( setEditorValue){//不是esc时才更新
  557. setEditorValue(context);
  558. }
  559. };
  560. CustomerCoeCellType.prototype.isReservedKey = function (e, context) {
  561. //cell type handle tab key by itself
  562. this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
  563. return false;
  564. };
  565. return new CustomerCoeCellType();
  566. },
  567. scrollSheetForOption:function (sheet,cxt,cellRect,row,options){
  568. let topRow = sheet.getViewportTopRow(1);
  569. if(row == topRow) return;//已经是最顶行了
  570. let length = options&&options.length>0?options.length:1;
  571. let height = cxt.canvas.height;
  572. let startY = cellRect.y+cellRect.height;//下拉框的起始显示位置
  573. let endY = startY + length * cellRect.height;//下拉框的结束显示位置
  574. if(endY <= height) return; //如果没有超出显示位置,直接返回
  575. let overRow = Math.ceil((endY - height)/cellRect.height);//超出的行数
  576. let showRow = topRow + overRow > row?row:topRow + overRow;
  577. sheet.showRow(showRow, GC.Spread.Sheets.VerticalPosition.top);
  578. },
  579. setSelectButton(row,col,sheet,header){
  580. /* let getSelectButton = function (cellWidth=100) {
  581. function moreButton() {
  582. }
  583. moreButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  584. moreButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  585. GC.Spread.Sheets.CellTypes.Button.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
  586. let buttonW = cellWidth/5;
  587. let endX = x+w-2;
  588. if(value){
  589. let textWidth = ctx.measureText(value).width;
  590. let spaceWidth = cellWidth - buttonW;
  591. let textEndX = x+2+textWidth;
  592. if(spaceWidth<textWidth){
  593. for(let i = value.length-1;i>1;i--){
  594. let newValue = value.substr(0,i);
  595. let newTestWidth = ctx.measureText(newValue).width;
  596. if(spaceWidth>newTestWidth){
  597. value = newValue;
  598. textEndX = x+2+newTestWidth;
  599. break;
  600. }
  601. }
  602. }
  603. ctx.fillText(value,textEndX,y+h-5);
  604. }
  605. //画三个点
  606. ctx.save();
  607. ctx.beginPath();
  608. ctx.arc(endX-buttonW/2,y+h/2,1,0,360,false);
  609. ctx.arc(endX-buttonW/2-4,y+h/2,1,0,360,false);
  610. ctx.arc(endX-buttonW/2+4,y+h/2,1,0,360,false);
  611. ctx.fillStyle="black";//填充颜色,默认是黑色
  612. ctx.fill();//画实心圆
  613. ctx.closePath();
  614. ctx.restore();
  615. };
  616. moreButton.prototype.processMouseLeave= function (hitinfo) {
  617. let newCell = new selectButton();
  618. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, newCell, GC.Spread.Sheets.SheetArea.viewport);
  619. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(false);
  620. };
  621. function selectButton() {
  622. }
  623. selectButton.prototype = new GC.Spread.Sheets.CellTypes.Text();
  624. selectButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  625. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this,arguments);
  626. };
  627. selectButton.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  628. return {
  629. x: x,
  630. y: y,
  631. row: context.row,
  632. col: context.col,
  633. cellStyle: cellStyle,
  634. cellRect: cellRect,
  635. sheetArea: context.sheetArea
  636. };
  637. };
  638. selectButton.prototype.processMouseDown = function (hitinfo){
  639. if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).locked()!=true){
  640. let b1 = new moreButton();
  641. b1.marginLeft(cellWidth*4/5);
  642. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, b1, GC.Spread.Sheets.SheetArea.viewport);
  643. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(true);
  644. }
  645. };
  646. return new selectButton();
  647. };*/
  648. sheet.setCellType(row, col,this.getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
  649. },
  650. setCusButton:function (row,col,sheet,setting,style) {
  651. let functionName = setting.header[col].callback;
  652. let readOnly = setting.disable?setting.disable[setting.header[col].disable]:false;
  653. if(typeof(readOnly) == 'function' ){
  654. readOnly = readOnly(row,col);
  655. }
  656. if(functionName){
  657. sheet.setCellType(row, col,this.getCusButtonCellType(setting.callback[functionName],readOnly,style));
  658. }
  659. //sheet.setCellType(row, col,this.getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
  660. },
  661. getCusButtonCellType:function (callback,readOnly=false,ostyle) {
  662. var ns = GC.Spread.Sheets;
  663. function CusButtonCellType() {
  664. }
  665. CusButtonCellType.prototype = new ns.CellTypes.Text();
  666. CusButtonCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  667. if(!readOnly){
  668. if(options.sheet.getActiveRowIndex()==options.row&&options.sheet.getActiveColumnIndex()==options.col){
  669. var image = document.getElementById('f_btn'),imageMagin = 3;
  670. var imageHeight = 15;
  671. var imageWidth = 25;
  672. var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2;
  673. ctx.save();
  674. if(style.backColor){
  675. ctx.fillStyle = style.backColor;
  676. ctx.fillRect(x,y,w,h);
  677. }
  678. ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight);
  679. ctx.beginPath();
  680. ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false);
  681. ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false);
  682. ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false);
  683. ctx.fillStyle="black";//填充颜色,默认是黑色
  684. ctx.fill();//画实心圆
  685. ctx.closePath();
  686. ctx.restore();
  687. w = w - imageWidth - imageMagin;
  688. //这里的左对齐的,当显示的字长度超过空白地方时,要改成右对齐
  689. if(style.hAlign == 0){
  690. if(value){
  691. let textWidth = ctx.measureText(value).width;
  692. let spaceWidth = w;
  693. if(spaceWidth<textWidth){
  694. style.hAlign = 2;
  695. }
  696. }
  697. }
  698. }
  699. }
  700. if(ostyle) gljUtil.setProperty(style,ostyle);
  701. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  702. };
  703. CusButtonCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  704. return {
  705. x: x,
  706. y: y,
  707. row: context.row,
  708. col: context.col,
  709. cellStyle: cellStyle,
  710. cellRect: cellRect,
  711. sheetArea: context.sheetArea
  712. };
  713. };
  714. CusButtonCellType.prototype.processMouseDown = function (hitinfo) {
  715. if(hitinfo.sheet.getActiveRowIndex()==hitinfo.row&&hitinfo.sheet.getActiveColumnIndex()==hitinfo.col){
  716. var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6;
  717. var imageWidth = 25;
  718. if(hitinfo.x<offset&&hitinfo.x>offset-imageWidth){
  719. if(!readOnly){
  720. if(callback) callback(hitinfo)
  721. }
  722. }
  723. }
  724. };
  725. return new CusButtonCellType();
  726. },
  727. getSelectButton(cellWidth=100){
  728. function moreButton() {
  729. }
  730. moreButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  731. moreButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  732. GC.Spread.Sheets.CellTypes.Button.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
  733. ctx.font = '14px Calibri';
  734. let buttonW = cellWidth/5;
  735. let endX = x+w-2;
  736. if(value){
  737. let textWidth = ctx.measureText(value).width;
  738. let spaceWidth = cellWidth - buttonW;
  739. let textEndX = x+textWidth+2;
  740. if(spaceWidth<textWidth){
  741. for(let i = value.length-1;i>1;i--){
  742. let newValue = value.substr(0,i);
  743. let newTestWidth = ctx.measureText(newValue).width;
  744. if(spaceWidth>newTestWidth){
  745. value = newValue;
  746. textEndX = x+newTestWidth+2;
  747. break;
  748. }
  749. }
  750. }
  751. ctx.fillText(value,textEndX,y+h-6);
  752. }
  753. //画三个点
  754. ctx.save();
  755. ctx.beginPath();
  756. ctx.arc(endX-buttonW/2,y+h/2,1,0,360,false);
  757. ctx.arc(endX-buttonW/2-4,y+h/2,1,0,360,false);
  758. ctx.arc(endX-buttonW/2+4,y+h/2,1,0,360,false);
  759. ctx.fillStyle="black";//填充颜色,默认是黑色
  760. ctx.fill();//画实心圆
  761. ctx.closePath();
  762. ctx.restore();
  763. };
  764. moreButton.prototype.processMouseLeave= function (hitinfo) {
  765. let newCell = new selectButton();
  766. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, newCell, GC.Spread.Sheets.SheetArea.viewport);
  767. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(false);
  768. };
  769. function selectButton() {
  770. }
  771. selectButton.prototype = new GC.Spread.Sheets.CellTypes.Text();
  772. selectButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  773. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this,arguments);
  774. };
  775. selectButton.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  776. return {
  777. x: x,
  778. y: y,
  779. row: context.row,
  780. col: context.col,
  781. cellStyle: cellStyle,
  782. cellRect: cellRect,
  783. sheetArea: context.sheetArea
  784. };
  785. };
  786. selectButton.prototype.processMouseDown = function (hitinfo){
  787. if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).locked()!=true){
  788. let b1 = new moreButton();
  789. b1.marginLeft(cellWidth*4/5);
  790. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, b1, GC.Spread.Sheets.SheetArea.viewport);
  791. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(true);
  792. }
  793. };
  794. return new selectButton();
  795. },
  796. setReplaceButton(row,col,sheet){
  797. let replaceButton = function(){
  798. };
  799. replaceButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  800. replaceButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  801. GC.Spread.Sheets.CellTypes.Button.prototype.paint.apply(this,arguments);
  802. if(value){
  803. ctx.save();
  804. ctx.fillStyle = "white";
  805. let fh = options.fontInfo&&options.fontInfo.fontSize?options.fontInfo.fontSize:h-6;
  806. ctx.fillText(value,x+(w+ctx.measureText(value).width)/2,y+(h+fh)/2-2);
  807. ctx.restore();
  808. }
  809. };
  810. let cellType = new replaceButton();
  811. cellType.buttonBackColor("#07A0FF");
  812. sheet.setCellType(row, col,cellType,GC.Spread.Sheets.SheetArea.viewport);
  813. },
  814. setDatePickerCellType(row,col,sheet){
  815. let ns = GC.Spread.Sheets;
  816. function DatePickerCellType() {
  817. }
  818. DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  819. DatePickerCellType.prototype.createEditorElement = function (context) {
  820. //Create input presenter.
  821. return document.createElement("input");
  822. };
  823. DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  824. //Initialize input editor.
  825. if (editorContext) {
  826. $editor = $(editorContext);
  827. //DatePickerCellType.prototype.activateEditor.apply(this, arguments);
  828. $editor.datepicker({dateFormat: 'yy-mm-dd'});
  829. $editor.css("position", "absolute");
  830. $editor.attr("gcUIElement", "gcEditingInput");
  831. $(".ui-datepicker").attr("gcUIElement", "gcEditingInput");
  832. }
  833. }
  834. DatePickerCellType.prototype.deactivateEditor = function (editorContext, context) {
  835. //Remove input editor when end editor status.
  836. if (editorContext) {
  837. var element = editorContext;
  838. $(element).datepicker("hide");
  839. $(element).datepicker("destroy");
  840. }
  841. // DatePickerCellType.prototype.deactivateEditor.apply(this, arguments)
  842. };
  843. DatePickerCellType.prototype.setEditorValue = function (editor, value, context) {
  844. //Sync value from Cell value to editor value.
  845. $(editor).datepicker("setDate", value);
  846. };
  847. DatePickerCellType.prototype.getEditorValue = function (editor, context) {
  848. //Sync value from editor value to cell value.
  849. return $(editor).datepicker("getDate");
  850. };
  851. DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  852. if (editorContext) {
  853. $editor = $(editorContext);
  854. $editor.css("width", cellRect.width - 1);
  855. $editor.css("height", cellRect.height - 3);
  856. }
  857. };
  858. let picker = new DatePickerCellType();
  859. sheet.getCell(row, col).cellType(picker).width(100).formatter('yyyy-mm-dd');
  860. },
  861. setTipsCell(row,col,sheet,header){
  862. let TipCellType = function () {};
  863. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  864. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  865. return {
  866. x: x,
  867. y: y,
  868. row: context.row,
  869. col: context.col,
  870. cellStyle: cellStyle,
  871. cellRect: cellRect,
  872. sheet: context.sheet,
  873. sheetArea: context.sheetArea
  874. };
  875. };
  876. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  877. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  878. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  879. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  880. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  881. zoom = hitinfo.sheet.zoom();
  882. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  883. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  884. let setting = {};
  885. if(textLength <= cellWidth){
  886. return;
  887. }
  888. if(sheet && sheet.getParent().qo){
  889. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  890. }
  891. TREE_SHEET_HELPER.showTipsDiv(text,setting,hitinfo);
  892. };
  893. TipCellType.prototype.processMouseLeave = function (hitinfo) {
  894. TREE_SHEET_HELPER.tipDiv = 'hide';
  895. if (TREE_SHEET_HELPER._toolTipElement) {
  896. $(TREE_SHEET_HELPER._toolTipElement).hide();
  897. TREE_SHEET_HELPER._toolTipElement = null;
  898. };
  899. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  900. };
  901. sheet.setCellType(row, col,new TipCellType(),GC.Spread.Sheets.SheetArea.viewport);
  902. },
  903. chkIfEmpty: function(rObj, setting) {
  904. var rst = true;
  905. if (rObj) {
  906. for (var i = 0; i < setting.header.length; i++) {
  907. if (rObj[setting.header[i].dataCode]) {
  908. rst = false;
  909. break;
  910. }
  911. }
  912. }
  913. return rst;
  914. },
  915. //add by zhong 2017-10-10
  916. //动态下拉框,配合EnterCell, args.sheet.repaint();
  917. getDynamicCombo: function (forLocked) {
  918. let ComboCellForActiveCell = function () { };
  919. ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
  920. ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
  921. let sheet = options.sheet;
  922. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  923. GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
  924. } else {
  925. GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
  926. }
  927. };
  928. ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
  929. let sheet = options.sheet;
  930. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  931. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  932. } else {
  933. return {
  934. x: x,
  935. y: y,
  936. row: options.row,
  937. col: options.col,
  938. cellStyle: cellStyle,
  939. cellRect: cellRect,
  940. sheetArea: options.sheetArea
  941. };//GC.Spread.Sheets.CellTypes.Text.prototype.getHitInfo.apply(this, arguments);
  942. }
  943. };
  944. return new ComboCellForActiveCell();
  945. },
  946. getTipsCombo:function (forLocked,tips,setting,node) {
  947. let getTipsCombo = function () {
  948. this.clickCom=false;
  949. };
  950. getTipsCombo.prototype = sheetCommonObj.getDynamicCombo(forLocked);
  951. if(tips && tips !=""){
  952. getTipsCombo.prototype.processMouseEnter = function(hitinfo){
  953. if(this.clickCom == true){ //点击了下拉框的三角形,则不用再显示悬浮框了
  954. this.clickCom = false;
  955. return;
  956. }
  957. let text = typeof tips == 'function'?tips(node):tips;
  958. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting,text);
  959. };
  960. getTipsCombo.prototype.processMouseLeave = function (hitinfo) {
  961. TREE_SHEET_HELPER.hideTipsDiv();
  962. };
  963. getTipsCombo.prototype.processMouseDown = function (hitinfo){
  964. if(hitinfo.isReservedLocation == true){//这里是点击了下拉框的三角形才会有这个属性
  965. TREE_SHEET_HELPER.hideTipsDiv();
  966. this.clickCom = true;
  967. }
  968. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  969. };
  970. getTipsCombo.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context){
  971. TREE_SHEET_HELPER.hideTipsDiv();
  972. GC.Spread.Sheets.CellTypes.ComboBox.prototype.updateEditor.apply(this, arguments);
  973. };
  974. }
  975. return new getTipsCombo();
  976. },
  977. getTreeNodeCellType:function (datas,row,parentMap) {// 2018-09-26 不用spreadjs默认的树结构,自定义控件
  978. var ns = GC.Spread.Sheets;
  979. let rectW = 10;
  980. let rectH = 10;
  981. let margin = 3;
  982. function TreeNodeCellType() {
  983. this.collapsed = gljUtil.isDef(datas[row].collapsed)?datas[row].collapsed: true; //默认是折叠的
  984. this.treeNodeType = true;
  985. this.rectInfo = {};
  986. }
  987. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  988. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  989. let offset = 0;
  990. let step = 7;
  991. let level = getTreeLevel(datas[row],datas);//从0开始,取当前节点是第几级的
  992. let tem = offset+margin+ rectW/2+step;//两条线之间的间隔
  993. let t_offset = offset;
  994. let temParentID = datas[row].ParentID;
  995. if(this.treeNodeType == true){
  996. for(let i = level;i>0;i--){//这里是画子节点前面的竖线,从第二级开始
  997. let temParent = getParent(temParentID,datas);
  998. if(temParent){//父节点有下一个兄弟节点才需要画
  999. if(hasNextBrother(parentMap,temParent)) sheetCommonObj.drawLine(ctx,x+t_offset+tem*i,y,x+t_offset+tem*i,y+h);
  1000. temParentID = temParent.ParentID;
  1001. }
  1002. offset +=tem;
  1003. }
  1004. }
  1005. offset+=step; //这个没法移动,所以要两个判断
  1006. if(this.treeNodeType == true){
  1007. if(hasChildern(datas[row].ID,datas)){//如果是有子节点
  1008. //第一条 或者没有父节点(如费率子表综合里程项)不用画方框头上那条竖线其它都要
  1009. if(row !=0 && gljUtil.isDef(datas[row].ParentID)) sheetCommonObj.drawLine(ctx,x+offset+ rectW/2+margin,y,x+offset+ rectW/2+margin,y + Math.round(h / 2) - rectH / 2);
  1010. //画方框下面的那条竖线,如果没有下一个兄弟节点,则不用画
  1011. if(hasNextBrother(parentMap,datas[row])) sheetCommonObj.drawLine(ctx,x+offset+ rectW/2+margin,y + Math.round(h / 2) + rectH / 2,x+offset+ rectW/2+margin,y + h);
  1012. sheetCommonObj.drowRect(ctx, x+offset, y, w, h,rectW,rectH,margin);
  1013. sheetCommonObj.drowSymbol(ctx, x+offset, y, w, h,rectW,rectH,margin, this.collapsed);
  1014. this.rectInfo = {x:x+offset+margin,rectW:rectW}//计录一下可点击位置
  1015. }else {
  1016. let hasNext = datas[row+1]?datas[row+1].ParentID == datas[row].ParentID:false;
  1017. sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset,hasNext,margin+ rectW/2);
  1018. }
  1019. }
  1020. offset += step;
  1021. offset += rectW;
  1022. x = x + offset;//设置偏移
  1023. w = w - offset;
  1024. if(datas[row].foreColor) style.foreColor = datas[row].foreColor;
  1025. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1026. };
  1027. // override getHitInfo to allow cell type get mouse messages
  1028. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1029. return {
  1030. x: x,
  1031. y: y,
  1032. row: context.row,
  1033. col: context.col,
  1034. cellStyle: cellStyle,
  1035. cellRect: cellRect,
  1036. sheetArea: context.sheetArea
  1037. };
  1038. }
  1039. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1040. ////方框外1像素内都有效
  1041. if (!_.isEmpty(this.rectInfo)&&Math.floor(hitinfo.x) <= this.rectInfo.x+this.rectInfo.rectW+2 && Math.floor(hitinfo.x) >= this.rectInfo.x-2) {
  1042. this.collapsed = !this.collapsed;
  1043. datas[row].collapsed = this.collapsed;
  1044. this.refreshChildrenVisible(hitinfo.sheet);
  1045. hitinfo.sheet.invalidateLayout();
  1046. hitinfo.sheet.repaint();
  1047. }
  1048. };
  1049. TreeNodeCellType.prototype.refreshChildrenVisible = function (sheet) {
  1050. sheet.suspendPaint();
  1051. sheet.suspendEvent();
  1052. refreshVisible(datas[row]);
  1053. sheet.resumeEvent();
  1054. sheet.resumePaint();
  1055. function refreshVisible(item){
  1056. if(parentMap[item.ID]){
  1057. for(let sub of parentMap[item.ID]){
  1058. refreshVisible(sub)
  1059. }
  1060. }
  1061. let visible = getVisible(item);
  1062. let trow = datas.indexOf(item);
  1063. sheet.getRange(trow , -1, 1, -1).visible(visible);
  1064. }
  1065. function getVisible(item) {
  1066. if(item.ParentID){
  1067. let parent = getParent(item.ParentID,datas);
  1068. if(!parent) return true;
  1069. let p_row= datas.indexOf(parent);
  1070. let visible = !sheet.getCellType(p_row,0).collapsed;
  1071. if(visible == true){ //如果是显示的,则要再往父节点的父节点检查,只要有一个节点是隐藏的,则都是隐藏
  1072. return getVisible(parent);
  1073. }else {
  1074. return visible
  1075. }
  1076. }else {//如果parentID 为空则是最根节点
  1077. return true;
  1078. }
  1079. }
  1080. };
  1081. return new TreeNodeCellType()
  1082. function getTreeLevel(item,data) {
  1083. if(item.ParentID && item.ParentID!=-1){
  1084. let pitem = _.find(data,{'ID':item.ParentID});
  1085. return getTreeLevel(pitem,data) + 1;
  1086. }else {
  1087. return 0
  1088. }
  1089. }
  1090. function hasChildern(ID,data) {//返回是否有子项
  1091. let p = _.find(data,{'ParentID':ID});
  1092. if(p) return true;
  1093. return false
  1094. }
  1095. function getParent(ParentID,data) {
  1096. let p = _.find(data,{'ID':ParentID});
  1097. return p;
  1098. }
  1099. function hasNextBrother(parentMap,item){
  1100. let children =parentMap[item.ParentID];
  1101. if(!gljUtil.isDef(children)|| children.indexOf(item) == children.length -1) return false;
  1102. return true
  1103. }
  1104. },
  1105. setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  1106. let me = this;
  1107. sheet.suspendPaint();
  1108. let combo = me.getDynamicCombo();
  1109. for(let i = 0, len = rowCount; i < len; i++){
  1110. if(itemsHeight) {
  1111. combo.itemHeight(itemsHeight);
  1112. combo._maxDropDownItems = itemsHeight + 5;
  1113. }
  1114. if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1115. else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  1116. else combo.items(items);
  1117. sheet.getCell(beginRow + i, col).cellType(combo);
  1118. }
  1119. sheet.resumePaint();
  1120. },
  1121. setStaticCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  1122. sheet.suspendPaint();
  1123. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  1124. for(let i = 0, len = rowCount; i < len; i++){
  1125. if(itemsHeight) combo.itemHeight(itemsHeight);
  1126. if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1127. else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  1128. else combo.items(items);
  1129. sheet.getCell(beginRow + i, col).cellType(combo);
  1130. }
  1131. sheet.resumePaint();
  1132. },
  1133. //设置系统粘贴板数据,需要用户触发事件,直接调用会失败
  1134. copyTextToClipboard: function(text) {
  1135. let textArea = document.createElement("textarea");
  1136. textArea.style.position = 'fixed';
  1137. textArea.style.top = 0;
  1138. textArea.style.left = 0;
  1139. textArea.style.width = '2em';
  1140. textArea.style.height = '2em';
  1141. textArea.style.padding = 0;
  1142. textArea.style.border = 'none';
  1143. textArea.style.outline = 'none';
  1144. textArea.style.boxShadow = 'none';
  1145. textArea.style.background = 'transparent';
  1146. textArea.value = text;
  1147. document.body.appendChild(textArea);
  1148. textArea.select();
  1149. try {
  1150. let successful = document.execCommand('copy');
  1151. let msg = successful ? 'successful' : 'unsuccessful';
  1152. console.log('Copying text command was ' + msg);
  1153. } catch (err) {
  1154. console.log('Oops, unable to copy');
  1155. }
  1156. document.body.removeChild(textArea);
  1157. },
  1158. //获取选中区域的表格类型数据(可粘贴到excel)
  1159. getTableData: function (sheet, colSettings = null) {
  1160. let rst = '';
  1161. let sel = sheet.getSelections()[0];
  1162. let pasteText = [];
  1163. for(let row = sel.row; row < sel.row + sel.rowCount; row++){
  1164. if(!sheet.getCell(row, -1).visible())
  1165. continue;
  1166. let rowText = [];
  1167. for(let j = 0; j < sel.colCount; j++){
  1168. let col = sel.col + j;
  1169. if(!sheet.getCell(-1, col).visible())
  1170. continue;
  1171. if(colSettings && (colSettings[col]['data']['field'] === 'itemCharacterText' || colSettings[col]['data']['field'] === 'jobContentText'))
  1172. rowText.push(sheet.getText(row, col) ? `"${sheet.getText(row, col)}"` : '');
  1173. else
  1174. rowText.push(sheet.getText(row, col) ? sheet.getText(row, col): '');
  1175. }
  1176. pasteText.push(rowText.join('\t'));
  1177. }
  1178. return pasteText.join('\n');
  1179. },
  1180. transferToTreeSetting:function(setting,treeSetting,treeCol){
  1181. for(let h of setting.header){
  1182. treeSetting.cols.push(getSettingCol(h))
  1183. }
  1184. for(let l of setting.view.lockColumns){
  1185. if(_.isString(l)){//如果是dataCode 进行转换
  1186. l = _.findIndex(setting.header,{dataCode:l})
  1187. }
  1188. if(treeSetting.cols[l]) treeSetting.cols[l].readOnly = true;
  1189. }
  1190. return treeSetting;
  1191. function getSettingCol(header) {
  1192. let aMap ={left:0,center:1,right:2};
  1193. let hAlign = header.hAlign?aMap[header.hAlign]:0;
  1194. let col = {
  1195. "width":header.headerWidth?header.headerWidth:100,
  1196. "head":{
  1197. "titleNames":Array.isArray(header.headerName)?header.headerName:[header.headerName],
  1198. "spanCols":header.spanCols?header.spanCols:[1],
  1199. "spanRows":header.spanRows?header.spanRows:[1],
  1200. "vAlign":[1],
  1201. "hAlign":[1],
  1202. "font":["Arial"]
  1203. },
  1204. "data": {
  1205. "field": header.dataCode,
  1206. "vAlign": 1,
  1207. "hAlign": hAlign,
  1208. "font": "Arial"
  1209. }
  1210. };
  1211. if(header.showHint == true){
  1212. col.showHint = true;
  1213. }
  1214. if(header.cellType){
  1215. col.data.cellType = getCellType(header);
  1216. }
  1217. if(header.decimalField){//设置formatter
  1218. let decimal = getDecimal(header.decimalField);
  1219. col.formatter = getFormatter(decimal);
  1220. }
  1221. if(header.getText && treeCol){
  1222. col.data.getText = treeCol.getEvent(header.getText);
  1223. }
  1224. /*col.readOnly = function (node) {
  1225. if(node.data.ParentID == -1 || node.data.id == 'GJ'){//三材类别项不能编辑)
  1226. return true;
  1227. }
  1228. return false;
  1229. };*/
  1230. return col;
  1231. }
  1232. function getCellType(header) {
  1233. return function () {
  1234. if(header.cellType === "checkBox"){
  1235. return new GC.Spread.Sheets.CellTypes.CheckBox();
  1236. }
  1237. if(header.cellType === "comboBox"){
  1238. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  1239. if(header.options){
  1240. dynamicCombo.itemHeight(header.options.length).items(header.options);
  1241. if(header.editorValueType==true){
  1242. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1243. }
  1244. }
  1245. return dynamicCombo
  1246. }
  1247. }
  1248. }
  1249. },
  1250. //注册自定义回车键事件
  1251. bindEnterKey: function (workBook, operation) {
  1252. workBook.commandManager().register('myEnter', operation);
  1253. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  1254. workBook.commandManager().setShortcutKey('myEnter', GC.Spread.Commands.Key.enter, false, false, false, false);
  1255. },
  1256. //解决esc后触发了编辑结束的保存事件,显示与实际数据不同问题
  1257. bindEscKey: function (workBook, sheets) {
  1258. function isDef(v){
  1259. return typeof v !== 'undefined' && v !== null;
  1260. }
  1261. workBook.commandManager().register('myEsc', function () {
  1262. let activeSheet = workBook.getActiveSheet();
  1263. let hasTheSheet = false;
  1264. for(let sheetObj of sheets){
  1265. let sheet = sheetObj.sheet;
  1266. if(sheet === activeSheet){
  1267. hasTheSheet = true;
  1268. let editStarting = sheetObj.editStarting;
  1269. let editEnded = sheetObj.editEnded;
  1270. if(editStarting){
  1271. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  1272. }
  1273. if(editEnded){
  1274. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  1275. }
  1276. let row = sheet.getActiveRowIndex();
  1277. let col = sheet.getActiveColumnIndex();
  1278. let orgV = sheet.getValue(row, col);
  1279. let orgText = sheet.getText(row, col);
  1280. if(!isDef(orgV)){
  1281. orgV = '';
  1282. }
  1283. if(sheet.isEditing()){
  1284. sheet.endEdit();
  1285. sheet.setValue(row, col, orgV);
  1286. }
  1287. if(editStarting){
  1288. sheet.bind(GC.Spread.Sheets.Events.EditStarting, editStarting);
  1289. }
  1290. if(editEnded){
  1291. sheet.bind(GC.Spread.Sheets.Events.EditEnded, editEnded);
  1292. }
  1293. }
  1294. }
  1295. //容错处理,以防没把所有工作簿的表格信息传入参数
  1296. if(!hasTheSheet){
  1297. if(activeSheet.isEditing()){
  1298. activeSheet.endEdit();
  1299. }
  1300. }
  1301. });
  1302. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.esc, false, false, false, false);
  1303. workBook.commandManager().setShortcutKey('myEsc', GC.Spread.Commands.Key.esc, false, false, false, false);
  1304. },
  1305. //生成列字段与列号映射
  1306. initColMapping: function (obj, headers) {
  1307. //colToField 列下标与列字段映射
  1308. //fieldToCol 列字段与列下标映射
  1309. let colMapping = {colToField: {}, fieldToCol: {}};
  1310. for(let header of headers){
  1311. colMapping['colToField'][headers.indexOf(header)] = header.dataCode;
  1312. colMapping['fieldToCol'][header.dataCode] = headers.indexOf(header);
  1313. }
  1314. console.log(colMapping);
  1315. obj.colMapping = colMapping
  1316. },
  1317. //设置默认样式
  1318. spreadDefaultStyle: function (workBook) {
  1319. let defaultStyle = new GC.Spread.Sheets.Style();
  1320. defaultStyle.font = '14px Calibri';let sheetCount = workBook.getSheetCount();
  1321. for(let i = 0; i < sheetCount; i++){
  1322. let sheet = workBook.getSheet(i);
  1323. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
  1324. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.colHeader);
  1325. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.rowHeader);
  1326. }
  1327. },
  1328. //动态根据工作簿宽度和各列宽度比例设置宽度
  1329. setColumnWidthByRate: function (workBookWidth, workBook, headers){
  1330. if(workBook){
  1331. const sheet = workBook.getActiveSheet();
  1332. sheet.suspendEvent();
  1333. sheet.suspendPaint();
  1334. for(let col = 0; col < headers.length; col++){
  1335. if(headers[col]['rateWidth'] !== undefined && headers[col]['rateWidth'] !== null && headers[col]['rateWidth'] !== ''){
  1336. sheet.setColumnWidth(col, workBookWidth * headers[col]['rateWidth'], GC.Spread.Sheets.SheetArea.colHeader)
  1337. }
  1338. else {
  1339. if(headers[col]['headerWidth'] !== undefined && headers[col]['headerWidth'] !== null && headers[col]['headerWidth'] !== ''){
  1340. sheet.setColumnWidth(col, headers[col]['headerWidth'], GC.Spread.Sheets.SheetArea.colHeader)
  1341. }
  1342. }
  1343. }
  1344. sheet.resumeEvent();
  1345. sheet.resumePaint();
  1346. }
  1347. },
  1348. drowRect:function (ctx, x, y, w, h,rectW,rectH,margin) {
  1349. ctx.save();
  1350. ctx.strokeStyle = "gray";
  1351. ctx.translate(0.5, 0.5);
  1352. ctx.beginPath();
  1353. let rectX = x + margin;
  1354. let rectY = y + Math.round(h / 2) - rectH / 2;
  1355. ctx.moveTo(rectX, rectY);
  1356. ctx.lineTo(rectX, rectY + rectH);
  1357. ctx.lineTo(rectX + rectW, rectY + rectH);
  1358. ctx.lineTo(rectX + rectW, rectY);
  1359. ctx.lineTo(rectX, rectY);
  1360. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1361. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1362. ctx.stroke();
  1363. ctx.restore();
  1364. },
  1365. drawLine : function (ctx, x1, y1, x2, y2, color) {
  1366. let l_color = color?color:"gray";
  1367. ctx.save();
  1368. ctx.translate(0.5, 0.5);
  1369. ctx.beginPath();
  1370. ctx.moveTo(x1, y1);
  1371. ctx.lineTo(x2, y2);
  1372. ctx.strokeStyle = l_color;
  1373. ctx.stroke();
  1374. ctx.restore();
  1375. },
  1376. drowSymbol :function (ctx, x, y, w, h,rectW,rectH,margin,collapsed) {
  1377. ctx.save();
  1378. ctx.strokeStyle = "#000000";
  1379. ctx.translate(0.5, 0.5);
  1380. ctx.beginPath();
  1381. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1382. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1383. let rectY = y + Math.round(h / 2) - rectH / 2;
  1384. if (collapsed) {
  1385. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1386. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1387. }
  1388. ctx.stroke();
  1389. ctx.restore();
  1390. },
  1391. drowTriangle:function(ctx,x,y){//画向下三角形
  1392. ctx.save();
  1393. ctx.fillStyle = "black";
  1394. ctx.beginPath();
  1395. ctx.moveTo(x, y);
  1396. ctx.lineTo(x-3, y -6);
  1397. ctx.lineTo(x+3, y -6);
  1398. ctx.fill();
  1399. ctx.restore();
  1400. },
  1401. drowSubItem: function (ctx, x, y, w, h, offset, hasNext,step) {
  1402. let t_step = step?step:6;
  1403. offset += t_step;
  1404. ctx.save();
  1405. ctx.strokeStyle = "gray";
  1406. ctx.translate(0.5, 0.5);
  1407. ctx.beginPath();
  1408. ctx.moveTo(x + offset, y);
  1409. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1410. offset += 9;
  1411. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1412. if (hasNext) {
  1413. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1414. ctx.lineTo(x + offset - 9, y + h);
  1415. }
  1416. ctx.stroke();
  1417. ctx.restore();
  1418. return offset;
  1419. },
  1420. checkData:function(col,setting, value) {
  1421. let result = true;
  1422. let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
  1423. if (validator === null) {
  1424. return result;
  1425. }
  1426. switch (validator) {
  1427. case 'number':
  1428. let regular = /^\d+(\.\d+)?$/;
  1429. result = regular.test(value);
  1430. break;
  1431. case 'boolean':
  1432. let booleanValue = [true, false];
  1433. result = booleanValue.indexOf(value) >= 0;
  1434. break;
  1435. }
  1436. return result;
  1437. },
  1438. // 延迟一段时间刷新表格,因为有的弹窗里面有表格,马上刷新可能会造成,弹窗界面还未完全显示完就完成了表格刷新,导致表格显示不完整
  1439. refreshWorkbookDelDefer(workbook, time) {
  1440. if (workbook) {
  1441. setTimeout(() => workbook.refresh(), time);
  1442. }
  1443. },
  1444. setRowsAutoFit(sheet, rows, col, wordWrap) {
  1445. console.time('rowFit');
  1446. rows.forEach(row => {
  1447. sheet.getCell(row, col).wordWrap(wordWrap);
  1448. sheet.autoFitRow(row);
  1449. });
  1450. console.timeEnd('rowFit');
  1451. }
  1452. }