sheet_common.js 66 KB

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