sheet_common.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. sheet.suspendPaint();
  24. sheet.suspendEvent();
  25. sheet.setRowCount(1, spreadNS.SheetArea.colHeader);
  26. sheet.setColumnCount(setting.header.length, spreadNS.SheetArea.viewport);
  27. if (setting && setting.view && setting.view.colHeaderHeight) {
  28. sheet.setRowHeight(0, setting.view.colHeaderHeight, spreadNS.SheetArea.colHeader);
  29. };
  30. if (setting && setting.view && setting.view.rowHeaderWidth) {
  31. sheet.setColumnWidth(0, setting.view.rowHeaderWidth, spreadNS.SheetArea.rowHeader);
  32. };
  33. sheet.options.colHeaderAutoTextIndex = 1;
  34. sheet.options.colHeaderAutoText = spreadNS.HeaderAutoText.numbers;
  35. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  36. sheet.options.protectionOptions = {
  37. allowResizeColumns: true
  38. };
  39. sheet.showRowOutline(false);
  40. me.buildHeader(sheet, setting);
  41. if (rowCount > 0)
  42. sheet.setRowCount(rowCount)
  43. else
  44. sheet.setRowCount(1);
  45. sheet.resumeEvent();
  46. sheet.resumePaint();
  47. },
  48. // buildSheet 在一个Spread、一个Sheet的情况下使用。
  49. buildSheet: function(container, setting, rowCount) {
  50. var me = this;
  51. var spreadBook = me.createSpread(container, { sheetCount: 1 });
  52. var sheet = spreadBook.getSheet(0);
  53. me.initSheet(sheet, setting, rowCount);
  54. return spreadBook;
  55. },
  56. buildHeader: function(sheet, setting){
  57. var me = this, ch = GC.Spread.Sheets.SheetArea.colHeader;
  58. for (var i = 0; i < setting.header.length; i++) {
  59. sheet.setValue(0, i, setting.header[i].headerName, ch);
  60. sheet.setColumnWidth(i, setting.header[i].headerWidth?setting.header[i].headerWidth:100);
  61. sheet.setColumnVisible(i,setting.header[i].visible === false ? false:true);
  62. }
  63. },
  64. cleanSheet: function(sheet, setting, rowCount) {
  65. sheet.suspendPaint();
  66. sheet.suspendEvent();
  67. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  68. if (rowCount > 0) sheet.setRowCount(rowCount);
  69. sheet.clearSelection();
  70. sheet.resumeEvent();
  71. sheet.resumePaint();
  72. },
  73. cleanData: function (sheet, setting, rowCount) {
  74. sheet.suspendPaint();
  75. sheet.suspendEvent();
  76. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  77. if (rowCount > 0) sheet.setRowCount(rowCount);
  78. sheet.resumeEvent();
  79. sheet.resumePaint();
  80. },
  81. setAreaAlign: function(area, hAlign, vAlign){
  82. if (!(hAlign) || hAlign === "left") {
  83. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  84. } else if (hAlign === "right") {
  85. area.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  86. } else if (hAlign === "center") {
  87. area.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  88. } else {
  89. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  90. }
  91. if (!(vAlign) || vAlign === "center") {
  92. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  93. } else if (vAlign === "top") {
  94. area.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  95. } else if (vAlign === "bottom") {
  96. area.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  97. } else {
  98. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  99. }
  100. },
  101. showData: function(sheet, setting, data,distTypeTree) {
  102. var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  103. sheet.suspendPaint();
  104. sheet.suspendEvent();
  105. //sheet.addRows(row, 1);
  106. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  107. if(sheet.getRowCount()<data.length){
  108. data.length<30? sheet.setRowCount(30):sheet.setRowCount(data.length);
  109. }else if(sheet.getRowCount()==0){
  110. sheet.setRowCount(30);
  111. }
  112. for (var col = 0; col < setting.header.length; col++) {
  113. var hAlign = "left", vAlign = "center";
  114. if (setting.header[col].hAlign) {
  115. hAlign = setting.header[col].hAlign;
  116. } else if (setting.header[col].dataType !== "String"){
  117. hAlign = "right";
  118. }
  119. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  120. me.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  121. if (setting.header[col].formatter) {
  122. //var style = new GC.Spread.Sheets.Style();
  123. //style.formatter = setting.header[col].formatter;
  124. //sheet.setStyle(row,col,style,GC.Spread.Sheets.SheetArea.viewport);
  125. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  126. }
  127. if(setting.header[col].cellType === "checkBox"||setting.header[col].cellType === "button"){//clear and reset
  128. var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
  129. sheet.deleteColumns(col,1);
  130. sheet.addColumns(col, 1);
  131. sheet.setValue(0, col, setting.header[col].headerName, header);
  132. sheet.setColumnWidth(col, setting.header[col].headerWidth?setting.header[col].headerWidth:100);
  133. }
  134. }
  135. for (var row = 0; row < data.length; row++) {
  136. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  137. this.showRowData(sheet,setting,row,data,distTypeTree);
  138. }
  139. this.lockCells(sheet,setting);
  140. sheet.resumeEvent();
  141. sheet.resumePaint();
  142. //me.shieldAllCells(sheet);
  143. },
  144. showRowData:function (sheet,setting,row,data,distTypeTree=null) {
  145. let ch = GC.Spread.Sheets.SheetArea.viewport;
  146. for (var col = 0; col < setting.header.length; col++) {
  147. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  148. var val = data[row][setting.header[col].dataCode];
  149. if(val&&setting.header[col].dataType === "Number"){
  150. if(setting.header[col].hasOwnProperty('tofix')){
  151. val =scMathUtil.roundToString(val,setting.header[col].tofix);
  152. }
  153. else if(setting.header[col].hasOwnProperty('decimalField')){
  154. var decimal = getDecimal(setting.header[col].decimalField);
  155. val =scMathUtil.roundToString(val,decimal);
  156. sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
  157. }else {
  158. val =val+'';
  159. }
  160. }
  161. if(val!=null&&setting.header[col].cellType === "checkBox"){
  162. this.setCheckBoxCell(row,col,sheet,val)
  163. }
  164. if(setting.header[col].cellType === "comboBox"){
  165. this.setComboBox(row,col,sheet,setting.header[col].options,setting.header[col].editorValueType);
  166. }
  167. if(setting.header[col].cellType === "selectButton"){
  168. this.setSelectButton(row,col,sheet,setting.header[col]);
  169. }
  170. if(setting.owner==='gljTree'){
  171. if(setting.header[col].cellType === "checkBox"){
  172. val==1?val:0;
  173. this.setCheckBoxCell(row,col,sheet,val);
  174. }
  175. if(setting.header[col].dataCode === 'gljType' && data[row].gljType){
  176. let distTypeVal = distTypeTree.distTypes[distTypeTree.prefix + data[row].gljType].data.fullName;
  177. val=distTypeVal;
  178. }
  179. }
  180. if(setting.header[col].getText){
  181. val = setting.getText[setting.header[col].getText](data[row],val)
  182. }
  183. sheet.setValue(row, col, val, ch);
  184. }
  185. this.setRowStyle(row,sheet,data[row].bgColour);
  186. if(setting.autoFit==true){
  187. sheet.getRange(row, -1, 1, -1, GC.Spread.Sheets.SheetArea.viewport).wordWrap(true);
  188. sheet.autoFitRow(row);
  189. }
  190. },
  191. //todo
  192. analyzePasteData: function(setting, pastedInfo) {
  193. var rst = [], propId = pastedInfo.cellRange.col, preStrIdx = 0, itemObj = {};//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  194. for (var i = 0; i < pastedInfo.pasteData.text.length; i++) {
  195. if (pastedInfo.pasteData.text[i] === "\n") {
  196. propId = pastedInfo.cellRange.col;//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  197. preStrIdx = i + 1;
  198. rst.push(itemObj);
  199. if (i < pastedInfo.pasteData.text.length - 1) {
  200. itemObj = {};
  201. }
  202. } else if (pastedInfo.pasteData.text[i] === "\t" || pastedInfo.pasteData.text[i] === "\r") {
  203. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx, i);
  204. propId++;
  205. preStrIdx = i + 1;
  206. //if the last copied-cell were empty, should check whether the end of text
  207. if (i == pastedInfo.pasteData.text.length - 1) {
  208. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  209. rst.push(itemObj);
  210. }
  211. } else if (i == pastedInfo.pasteData.text.length - 1) {
  212. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  213. rst.push(itemObj);
  214. }
  215. }
  216. return rst;
  217. },
  218. combineRowData: function(sheet, setting, row) {
  219. var rst = {};
  220. for (var col = 0; col < setting.header.length; col++) {
  221. rst[setting.header[col].dataCode] = sheet.getValue(row, col);
  222. }
  223. return rst;
  224. },
  225. shieldAllCells: function(sheet) {
  226. sheet.options.isProtected = true;
  227. },
  228. unShieldAllCells: function(sheet) {
  229. sheet.options.isProtected = false;
  230. },
  231. lockCells: function(sheet, setting){
  232. if (setting && setting.view.lockColumns && setting.view.lockColumns.length > 0) {
  233. sheet.options.isProtected = true;
  234. sheet.getRange(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  235. for (var i = 0; i < setting.view.lockColumns.length; i++) {
  236. sheet.getRange(-1,setting.view.lockColumns[i], -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  237. }
  238. }
  239. },
  240. setCheckBoxCell(row,col,sheet,val){
  241. var c = new GC.Spread.Sheets.CellTypes.CheckBox();
  242. c.isThreeState(false);
  243. sheet.setCellType(row, col,c,GC.Spread.Sheets.SheetArea.viewport);
  244. sheet.getCell(row, col).value(val);
  245. sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  246. },
  247. setComboBox(row,col,sheet,options,editorValueType){
  248. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  249. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  250. if(options){
  251. dynamicCombo.itemHeight(options.length).items(options);
  252. if(editorValueType==true){
  253. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  254. }
  255. }
  256. sheet.setCellType(row, col,dynamicCombo,GC.Spread.Sheets.SheetArea.viewport);
  257. },
  258. setRowStyle(row,sheet,bgColour) {
  259. if(bgColour){
  260. let style = new GC.Spread.Sheets.Style();
  261. style.backColor = bgColour;
  262. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  263. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  264. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  265. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  266. sheet.setStyle(row, -1, style);
  267. }
  268. },
  269. setSelectButton(row,col,sheet,header){
  270. let getSelectButton = function (cellWidth=100) {
  271. function moreButton() {
  272. }
  273. moreButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  274. moreButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  275. GC.Spread.Sheets.CellTypes.Button.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
  276. let buttonW = cellWidth/5;
  277. let endX = x+w-2;
  278. if(value){
  279. let textWidth = ctx.measureText(value).width;
  280. let spaceWidth = cellWidth - buttonW;
  281. let textEndX = x+2+textWidth;
  282. if(spaceWidth<textWidth){
  283. for(let i = value.length-1;i>1;i--){
  284. let newValue = value.substr(0,i);
  285. let newTestWidth = ctx.measureText(newValue).width;
  286. if(spaceWidth>newTestWidth){
  287. value = newValue;
  288. textEndX = x+2+newTestWidth;
  289. break;
  290. }
  291. }
  292. }
  293. ctx.fillText(value,textEndX,y+h-5);
  294. }
  295. //画三个点
  296. ctx.save();
  297. ctx.beginPath();
  298. ctx.arc(endX-buttonW/2,y+h/2,1,0,360,false);
  299. ctx.arc(endX-buttonW/2-4,y+h/2,1,0,360,false);
  300. ctx.arc(endX-buttonW/2+4,y+h/2,1,0,360,false);
  301. ctx.fillStyle="black";//填充颜色,默认是黑色
  302. ctx.fill();//画实心圆
  303. ctx.closePath();
  304. ctx.restore();
  305. };
  306. moreButton.prototype.processMouseLeave= function (hitinfo) {
  307. let newCell = new selectButton();
  308. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, newCell, GC.Spread.Sheets.SheetArea.viewport);
  309. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(false);
  310. };
  311. function selectButton() {
  312. }
  313. selectButton.prototype = new GC.Spread.Sheets.CellTypes.Text();
  314. selectButton.prototype.paint = function (ctx, value, x, y, w, h, style, options){
  315. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this,arguments);
  316. };
  317. selectButton.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  318. return {
  319. x: x,
  320. y: y,
  321. row: context.row,
  322. col: context.col,
  323. cellStyle: cellStyle,
  324. cellRect: cellRect,
  325. sheetArea: context.sheetArea
  326. };
  327. };
  328. selectButton.prototype.processMouseDown = function (hitinfo){
  329. if(hitinfo.sheet.getCell(hitinfo.row,hitinfo.col).locked()!=true){
  330. let b1 = new moreButton();
  331. b1.marginLeft(cellWidth*4/5);
  332. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, b1, GC.Spread.Sheets.SheetArea.viewport);
  333. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(true);
  334. }
  335. };
  336. return new selectButton();
  337. };
  338. sheet.setCellType(row, col,getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
  339. },
  340. chkIfEmpty: function(rObj, setting) {
  341. var rst = true;
  342. if (rObj) {
  343. for (var i = 0; i < setting.header.length; i++) {
  344. if (rObj[setting.header[i].dataCode]) {
  345. rst = false;
  346. break;
  347. }
  348. }
  349. }
  350. return rst;
  351. },
  352. //add by zhong 2017-10-10
  353. //动态下拉框,配合EnterCell, args.sheet.repaint();
  354. getDynamicCombo: function (forLocked) {
  355. let ComboCellForActiveCell = function () { };
  356. ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
  357. ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
  358. let sheet = options.sheet;
  359. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  360. GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
  361. } else {
  362. GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
  363. }
  364. };
  365. ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
  366. let sheet = options.sheet;
  367. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  368. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  369. } else {
  370. return GC.Spread.Sheets.CellTypes.Base.prototype.getHitInfo.apply(this, arguments);
  371. }
  372. };
  373. return new ComboCellForActiveCell();
  374. },
  375. setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  376. let me = this;
  377. sheet.suspendPaint();
  378. let combo = me.getDynamicCombo();
  379. for(let i = 0, len = rowCount; i < len; i++){
  380. if(itemsHeight) combo.itemHeight(itemsHeight);
  381. if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  382. else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  383. else combo.items(items);
  384. sheet.getCell(beginRow + i, col).cellType(combo);
  385. }
  386. sheet.resumePaint();
  387. },
  388. setStaticCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  389. sheet.suspendPaint();
  390. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  391. for(let i = 0, len = rowCount; i < len; i++){
  392. if(itemsHeight) combo.itemHeight(itemsHeight);
  393. if(itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  394. else if(itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  395. else combo.items(items);
  396. sheet.getCell(beginRow + i, col).cellType(combo);
  397. }
  398. sheet.resumePaint();
  399. },
  400. //设置系统粘贴板数据,需要用户触发事件,直接调用会失败
  401. copyTextToClipboard: function(text) {
  402. let textArea = document.createElement("textarea");
  403. textArea.style.position = 'fixed';
  404. textArea.style.top = 0;
  405. textArea.style.left = 0;
  406. textArea.style.width = '2em';
  407. textArea.style.height = '2em';
  408. textArea.style.padding = 0;
  409. textArea.style.border = 'none';
  410. textArea.style.outline = 'none';
  411. textArea.style.boxShadow = 'none';
  412. textArea.style.background = 'transparent';
  413. textArea.value = text;
  414. document.body.appendChild(textArea);
  415. textArea.select();
  416. try {
  417. let successful = document.execCommand('copy');
  418. let msg = successful ? 'successful' : 'unsuccessful';
  419. console.log('Copying text command was ' + msg);
  420. } catch (err) {
  421. console.log('Oops, unable to copy');
  422. }
  423. document.body.removeChild(textArea);
  424. },
  425. //获取选中区域的表格类型数据(可粘贴到excel)
  426. getTableData: function (sheet, colSettings = null) {
  427. let rst = '';
  428. let sel = sheet.getSelections()[0];
  429. let pasteText = [];
  430. for(let row = sel.row; row < sel.row + sel.rowCount; row++){
  431. if(!sheet.getCell(row, -1).visible())
  432. continue;
  433. let rowText = [];
  434. for(let j = 0; j < sel.colCount; j++){
  435. let col = sel.col + j;
  436. if(!sheet.getCell(-1, col).visible())
  437. continue;
  438. if(colSettings && (colSettings[col]['data']['field'] === 'itemCharacterText' || colSettings[col]['data']['field'] === 'jobContentText'))
  439. rowText.push(sheet.getText(row, col) ? `"${sheet.getText(row, col)}"` : '');
  440. else
  441. rowText.push(sheet.getText(row, col) ? sheet.getText(row, col): '');
  442. }
  443. pasteText.push(rowText.join('\t'));
  444. }
  445. return pasteText.join('\n');
  446. },
  447. transferToTreeSetting:function(setting,treeSetting,treeCol){
  448. for(let h of setting.header){
  449. treeSetting.cols.push(getSettingCol(h))
  450. }
  451. for(let l of setting.view.lockColumns){
  452. treeSetting.cols[l].readOnly = true;
  453. }
  454. return treeSetting;
  455. function getSettingCol(header) {
  456. let aMap ={left:0,center:1,right:2};
  457. let hAlign = header.hAlign?aMap[header.hAlign]:0;
  458. let col = {
  459. "width":header.headerWidth?header.headerWidth:100,
  460. "head":{
  461. "titleNames":Array.isArray(header.headerName)?header.headerName:[header.headerName],
  462. "spanCols":header.spanCols?header.spanCols:[1],
  463. "spanRows":header.spanRows?header.spanRows:[1],
  464. "vAlign":[1],
  465. "hAlign":[1],
  466. "font":["Arial"]
  467. },
  468. "data": {
  469. "field": header.dataCode,
  470. "vAlign": 1,
  471. "hAlign": hAlign,
  472. "font": "Arial"
  473. }
  474. };
  475. if(header.showHint == true){
  476. col.showHint = true;
  477. }
  478. if(header.cellType){
  479. col.data.cellType = getCellType(header);
  480. }
  481. if(header.decimalField){//设置formatter
  482. let decimal = getDecimal(header.decimalField);
  483. col.formatter = getFormatter(decimal);
  484. }
  485. if(header.getText && treeCol){
  486. col.data.getText = treeCol.getEvent(header.getText);
  487. }
  488. /*col.readOnly = function (node) {
  489. if(node.data.ParentID == -1 || node.data.id == 'GJ'){//三材类别项不能编辑)
  490. return true;
  491. }
  492. return false;
  493. };*/
  494. return col;
  495. }
  496. function getCellType(header) {
  497. return function () {
  498. if(header.cellType === "checkBox"){
  499. return new GC.Spread.Sheets.CellTypes.CheckBox();
  500. }
  501. if(header.cellType === "comboBox"){
  502. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  503. if(header.options){
  504. dynamicCombo.itemHeight(header.options.length).items(header.options);
  505. if(header.editorValueType==true){
  506. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  507. }
  508. }
  509. return dynamicCombo
  510. }
  511. }
  512. }
  513. }
  514. }