spreadjs_zh.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. /**
  2. * Spreadjs 通用方法集
  3. *
  4. * @author Mai
  5. * @date 2018/02/06
  6. * @version
  7. */
  8. // 定义画点线的方法
  9. const proto = window.CanvasRenderingContext2D && CanvasRenderingContext2D.prototype;
  10. proto.dottedLine = function (x1, y1, x2, y2, interval = 4) {
  11. const isHorizontal = x1 == x2 ? false : true;
  12. const dotLen = 1;
  13. let len = isHorizontal ? x2 - x1 : y2 - y1;
  14. this.moveTo(x1, y1);
  15. let progress = 0;
  16. while (len > progress) {
  17. if (progress > len) { progress = len; }
  18. if (isHorizontal) {
  19. this.moveTo(x1 + progress, y1);
  20. this.lineTo(x1 + progress + dotLen, y1);
  21. } else {
  22. this.moveTo(x1, y1 + progress);
  23. this.lineTo(x1, y1 + progress + dotLen);
  24. }
  25. progress += interval;
  26. }
  27. };
  28. // 简写Spread常量
  29. const spreadNS = GC.Spread.Sheets;
  30. // 授权码
  31. spreadNS.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
  32. // SpreadJs常用方法
  33. const SpreadJsObj = {
  34. initSpreadSettingEvents: function (setting, events) {
  35. const getEvent = function (eventName) {
  36. const names = eventName.split('.');
  37. let event = events;
  38. for (let name of names) {
  39. if (event[name]) {
  40. event = event[name];
  41. } else {
  42. return null;
  43. }
  44. }
  45. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  46. return null;
  47. } else {
  48. return event;
  49. }
  50. };
  51. for (const col of setting.cols) {
  52. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  53. col.readOnly = getEvent(col.readOnly);
  54. }
  55. if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object String]") {
  56. col.getValue = getEvent(col.getValue);
  57. }
  58. }
  59. },
  60. DataType: {
  61. Data: 'data',
  62. Tree: 'tree',
  63. },
  64. /**
  65. * 创建Spread(默认1张表,3行数据)
  66. * @param obj 用于创建spreadjs的Dom元素
  67. * @returns {GC.Spread.Sheets.Workbook}
  68. */
  69. createNewSpread: function (obj) {
  70. const spread = new spreadNS.Workbook(obj, {sheetCount: 1});
  71. // spread.options.tabStripVisible = false;
  72. // spread.options.scrollbarMaxAlign = true;
  73. // spread.options.cutCopyIndicatorVisible = false;
  74. // spread.options.allowCopyPasteExcelStyle = false;
  75. // spread.options.allowUserDragDrop = false;
  76. spread.options.allowUserDragFill = false;
  77. // spread.options.showDragFillSmartTag = false;
  78. // spread.options.allowUserEditFormula = false;
  79. // spread.options.allowExtendPasteRange = true;
  80. // spread.options.copyPasteHeaderOptions = spreadNS.CopyPasteHeaderOptions.noHeaders;
  81. // spread.getActiveSheet().options.clipBoardOptions = spreadNS.ClipboardPasteOptions.values;//设置粘贴时只粘贴值
  82. // spread.getActiveSheet().setRowCount(3);
  83. return spread;
  84. },
  85. addCutEvents: function (spread, fun) {
  86. const cut = spreadNS.Commands.cut.execute;
  87. spreadNS.Commands.cut.execute = function (context, options, isUndo) {
  88. const self = this, sheet = context.getActiveSheet();
  89. const sels = sheet.getSelections();
  90. const sel = sels ? sels[0] : null;
  91. if (sel) {
  92. return fun(sheet, sel, function () {
  93. cut(context, options, isUndo);
  94. });
  95. }
  96. }
  97. },
  98. /**
  99. * 保护sheet(需设置保护后, 单元格的locked等属性方可生效)
  100. * @param {GC.Spread.Sheets.Worksheet} sheet
  101. */
  102. protectedSheet: function (sheet) {
  103. const option = {
  104. allowSelectLockedCells: true,
  105. allowSelectUnlockedCells: true,
  106. allowResizeRows: true,
  107. allowResizeColumns: true
  108. };
  109. // sheet.options.protectionOptions = option;
  110. // sheet.options.isProtected = true;
  111. // sheet.options.allowCellOverflow = false;
  112. },
  113. /**
  114. * sheet批量操作优化(sheet操作大批量数据时, 屏蔽数据刷新, 可优化大量时间)
  115. * @param {GC.Spread.Sheets.Worksheet} sheet
  116. * @param {function} operation
  117. */
  118. beginMassOperation: function (sheet) {
  119. sheet.suspendPaint();
  120. sheet.suspendEvent();
  121. },
  122. endMassOperation: function (sheet) {
  123. sheet.resumeEvent();
  124. sheet.resumePaint();
  125. },
  126. massOperationSheet: function (sheet, operation) {
  127. this.beginMassOperation(sheet);
  128. operation();
  129. this.endMassOperation(sheet);
  130. },
  131. /**
  132. * 获取Obj左顶点位置(部分功能需通过spreadjs左顶点位置计算)
  133. * @param obj
  134. * @returns {{x: number, y: number}}
  135. */
  136. getObjPos: function (obj) {
  137. if (!obj) return null;
  138. let target = obj;
  139. let pos = {x: obj.offsetLeft, y: obj.offsetTop};
  140. target = obj.offsetParent;
  141. while (target) {
  142. pos.x += target.offsetLeft;
  143. pos.y += target.offsetTop;
  144. target = target.offsetParent;
  145. }
  146. return pos;
  147. },
  148. /**
  149. * 以下四个方法来自Spread示例, 参见官网或文档
  150. */
  151. getHitTest: function (obj, e, sheet) {
  152. var offset = obj.offset(),
  153. x = e.pageX - offset.left,
  154. y = e.pageY - offset.top;
  155. return sheet.hitTest(x, y);
  156. },
  157. getTargetSelection: function (sheet, target) {
  158. if (target.hitTestType === spreadNS.SheetArea.colHeader) {
  159. return sheet.getRange(-1, target.col, sheet.getRowCount(), 1);
  160. } else if (target.hitTestType === spreadNS.SheetArea.rowHeader) {
  161. return sheet.getRange(target.row, -1, 1, sheet.getColumnCount());
  162. } else if (target.hitTestType === spreadNS.SheetArea.viewport) {
  163. return sheet.getRange(target.row, target.col, 1, 1);
  164. } else if (target.hitTestType === spreadNS.SheetArea.corner) {
  165. return sheet.getRange(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
  166. };
  167. },
  168. getCellInSelections: function (selections, row, col) {
  169. const count = selections.length;
  170. let range;
  171. for (var i = 0; i < count; i++) {
  172. range = selections[i];
  173. if (range.contains(row, col)) {
  174. return range;
  175. }
  176. }
  177. return null;
  178. },
  179. checkTargetInSelection: function (selections, range) {
  180. var count = selections.length, sel;
  181. for (var i = 0; i < count; i++) {
  182. sel = selections[i];
  183. if (sel.containsRange(range)) {
  184. return true;
  185. }
  186. }
  187. return false;
  188. },
  189. /**
  190. * 获取 spread 在鼠标右键时, spread的选中区域
  191. * viewport, 选中鼠标点击单元格X, X不在原选中区域内, 则选中X
  192. * colHeader, 选中整列
  193. * rowHeader, 选中整行
  194. * corner, 全选
  195. * 该方法返回不符合需求时,可通过getHitTest/getTargetSelection/getCellInSelections/checkTargetInSelection来确定鼠标右键点击时,spread当前Sheet应选中的单元格
  196. * @param obj: 创建Spread的Dom元素(jquery-contextmenu.build方法的第一个变量可读取)
  197. * @param e: jquery-contextmenu.build方法的第二个变量
  198. * @param {GC.Spread.Sheets.Workbook} spread
  199. * @returns {*}
  200. */
  201. safeRightClickSelection: function (obj, e, spread) {
  202. const sheet = spread.getActiveSheet();
  203. const selections = sheet.getSelections(), target = this.getHitTest(obj, e, sheet), range = this.getTargetSelection(sheet, target);
  204. if (!this.checkTargetInSelection(selections, range)) {
  205. sheet.setSelection(range.row, range.col, range.rowCount, range.colCount);
  206. }
  207. return target;
  208. },
  209. /**
  210. * 禁用右键菜单
  211. * @param selector
  212. * @param spread
  213. */
  214. forbiddenSpreadContextMenu: function (selector, spread) {
  215. $.contextMenu({
  216. selector: selector,
  217. build: function ($trigger, e) {
  218. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spread);
  219. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  220. }
  221. });
  222. },
  223. /**
  224. * 获取写入sheet的数据序列
  225. * data:sheet.zh_data, tree: sheet.zh_tree.nodes
  226. * @param sheet
  227. * @returns {*}
  228. */
  229. getSortData: function (sheet) {
  230. if (sheet.zh_dataType) {
  231. if (sheet.zh_dataType === this.DataType.Data) {
  232. return sheet.zh_data;
  233. } else if (sheet.zh_dataType === this.DataType.Tree) {
  234. return sheet.zh_tree.nodes;
  235. } else {
  236. return null;
  237. }
  238. } else {
  239. return null;
  240. }
  241. },
  242. /**
  243. * sheet中 使用delete键,触发EndEdited事件
  244. * @param {GC.Spreads.Sheets.Workbook} spread
  245. * @param {function} fun
  246. */
  247. addDeleteBind: function (spread, fun) {
  248. spread.commandManager().register('deleteEvent', function () {
  249. fun(spread.getActiveSheet());
  250. });
  251. spread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  252. spread.commandManager().setShortcutKey('deleteEvent', GC.Spread.Commands.Key.del, false, false, false, false);
  253. },
  254. _initSheetDeafult: function (sheet) {
  255. if (sheet.zh_setting.headerFont) {
  256. const vStyle = new spreadNS.Style();
  257. vStyle.font = sheet.zh_setting.headerFont;
  258. sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.colHeader);
  259. }
  260. if (sheet.zh_setting.font) {
  261. const vStyle = new spreadNS.Style();
  262. vStyle.font = sheet.zh_setting.font;
  263. sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.viewport);
  264. }
  265. },
  266. /**
  267. * 根据sheet.zh_setting初始化sheet表头
  268. * @param {GC.Spread.Sheets.Worksheet} sheet
  269. */
  270. _initSheetHeader: function (sheet) {
  271. if (!sheet.zh_setting) { return; }
  272. sheet.setColumnCount(sheet.zh_setting.cols.length);
  273. sheet.setRowCount(sheet.zh_setting.headRows, spreadNS.SheetArea.colHeader);
  274. for (let iRow = 0; iRow < sheet.zh_setting.headRowHeight.length; iRow ++) {
  275. sheet.setRowHeight(iRow, sheet.zh_setting.headRowHeight[iRow], spreadNS.SheetArea.colHeader);
  276. }
  277. for (let iCol = 0; iCol < sheet.zh_setting.cols.length; iCol++) {
  278. const col = sheet.zh_setting.cols[iCol];
  279. const title = col.title.split('|');
  280. const colSpan = col.colSpan ? col.colSpan.split('|'): ['1'], rowSpan = col.rowSpan ? col.rowSpan.split('|'): ['1'];
  281. for (let i = 0; i < title.length; i++) {
  282. const cell = sheet.getCell(i, iCol, spreadNS.SheetArea.colHeader);
  283. cell.text(title[i]).wordWrap(true);
  284. if ((colSpan[i] !== '' && colSpan[i] !== '1') || (rowSpan[i] !== '' && rowSpan[i] !== '1')) {
  285. sheet.addSpan(i, iCol, parseInt(rowSpan[i]), parseInt(colSpan[i]), spreadNS.SheetArea.colHeader);
  286. }
  287. }
  288. sheet.setColumnWidth(iCol, col.width);
  289. if (col.visible !== undefined && col.visible !== null) {
  290. sheet.setColumnVisible(iCol, col.visible);
  291. }
  292. }
  293. sheet.rowOutlines.direction(spreadNS.Outlines.OutlineDirection.backward);
  294. sheet.showRowOutline(false);
  295. if (sheet.zh_setting.defaultRowHeight) {
  296. sheet.defaults.rowHeight = sheet.zh_setting.defaultRowHeight;
  297. }
  298. },
  299. /**
  300. * 初始化sheet, 设置sheet.zh_setting, 并初始化表头
  301. * @param {GC.Spread.Sheets.Worksheet} sheet
  302. * @param setting
  303. */
  304. initSheet: function (sheet, setting) {
  305. this.beginMassOperation(sheet);
  306. setting.pos = sheet.getParent().pos;
  307. sheet.zh_setting = setting;
  308. this._initSheetDeafult(sheet);
  309. this._initSheetHeader(sheet);
  310. sheet.setRowCount(sheet.zh_setting.emptyRows);
  311. sheet.extendCellType = {};
  312. sheet.getRange(0, 0, sheet.getRowCount(), sheet.getColumnCount()).locked(setting.readOnly);
  313. this.endMassOperation(sheet);
  314. },
  315. _loadRowData: function (sheet, data, row) {
  316. // 单元格重新写入数据
  317. if (!data) { return }
  318. sheet.zh_setting.cols.forEach(function (col, j) {
  319. const cell = sheet.getCell(row, j);
  320. if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object Function]") {
  321. cell.value(col.getValue(data));
  322. } else if (col.field !== '' && data[col.field]) {
  323. cell.value(data[col.field]);
  324. }
  325. if (col.font) {
  326. cell.font(col.font);
  327. }
  328. if (col.foreColor) {
  329. if (Object.prototype.toString.apply(col.foreColor) === "[object Function]") {
  330. cell.foreColor(col.foreColor(data, sheet.getDefaultStyle().foreColor));
  331. } else {
  332. cell.foreColor(col.foreColor);
  333. }
  334. }
  335. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object Function]") {
  336. cell.locked(col.readOnly(data) || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  337. } else {
  338. cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  339. }
  340. if (col.formatter) {
  341. cell.formatter(col.formatter);
  342. } else if (col.type === 'Number') {
  343. cell.formatter('0.######');
  344. }
  345. if (sheet.zh_setting.getColor && Object.prototype.toString.apply(sheet.zh_setting.getColor) === "[object Function]") {
  346. cell.backColor(sheet.zh_setting.getColor(data, col, sheet.getDefaultStyle().backColor));
  347. }
  348. });
  349. },
  350. _defineColCellType: function (sheet, col, colSetting) {
  351. if(colSetting.cellType === 'ellipsis') {
  352. if (!sheet.extendCellType.ellipsis) {
  353. sheet.extendCellType.ellipsis = this.CellType.getEllipsisTextCellType();
  354. }
  355. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsis);
  356. }
  357. if(colSetting.cellType === 'ellipsisAutoTip') {
  358. if (!sheet.extendCellType.ellipsisAutoTip) {
  359. sheet.extendCellType.ellipsisAutoTip = this.CellType.getEllipsisTextAutoTipCellType();
  360. }
  361. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsisAutoTip);
  362. }
  363. if(colSetting.cellType === 'html') {
  364. if (!sheet.extendCellType.html) {
  365. sheet.extendCellType.html = this.CellType.getHtmlCellType();
  366. }
  367. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.html);
  368. }
  369. if (colSetting.cellType === 'image') {
  370. if (!sheet.extendCellType.image) {
  371. sheet.extendCellType.image = this.CellType.getImageCellType();
  372. }
  373. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.image);
  374. }
  375. if (colSetting.cellType === 'imageBtn') {
  376. if (!sheet.extendCellType.image) {
  377. sheet.extendCellType.imageBtn = this.CellType.getImageButtonCellType();
  378. }
  379. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.imageBtn);
  380. }
  381. if (colSetting.cellType === 'tree') {
  382. if (!sheet.extendCellType.tree) {
  383. sheet.extendCellType.tree = this.CellType.getTreeNodeCellType();
  384. }
  385. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.tree);
  386. }
  387. if (colSetting.cellType === 'tip') {
  388. if (!sheet.extendCellType.tip) {
  389. sheet.extendCellType.tip = this.CellType.getTipCellType();
  390. }
  391. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.tip);
  392. }
  393. if (colSetting.cellType === 'autoTip') {
  394. if (!sheet.extendCellType.autoTip) {
  395. sheet.extendCellType.autoTip = this.CellType.getAutoTipCellType();
  396. }
  397. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.autoTip);
  398. }
  399. if (colSetting.cellType === 'checkbox') {
  400. if (!sheet.extendCellType.checkbox) {
  401. sheet.extendCellType.checkbox = new spreadNS.CellTypes.CheckBox();
  402. }
  403. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.checkbox);
  404. }
  405. if (colSetting.cellType === 'unit') {
  406. if (!sheet.extendCellType.unit) {
  407. sheet.extendCellType.unit = this.CellType.getUnitCellType();
  408. sheet.bind(spreadNS.Events.LeaveCell, function (e, info) {
  409. const cellType = info.sheet.getCell(info.row, info.col).cellType();
  410. if (cellType === sheet.extendCellType.unit) {
  411. info.sheet.leaveCell = {row: info.row, col: info.col};
  412. } else {
  413. delete info.sheet.leaveCell;
  414. }
  415. });
  416. sheet.bind(spreadNS.Events.EnterCell, function (e, info) {
  417. if (info.sheet.leaveCell) {
  418. info.sheet.repaint(info.sheet.getCellRect(info.sheet.leaveCell.row, info.sheet.leaveCell.col));
  419. }
  420. });
  421. }
  422. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.unit);
  423. }
  424. if (colSetting.formatter) {
  425. sheet.getRange(-1, col, -1, 1).formatter(colSetting.formatter);
  426. }
  427. },
  428. /**
  429. * 整个sheet重新加载数据
  430. * @param {GC.Spread.Sheets.Worksheet} sheet
  431. */
  432. reLoadSheetData: function (sheet) {
  433. const self = this;
  434. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  435. this.beginMassOperation(sheet);
  436. try {
  437. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  438. // 设置总行数
  439. const totalRow = sortData.length + sheet.zh_setting.emptyRows;
  440. sheet.setRowCount(totalRow, spreadNS.SheetArea.viewport);
  441. // 控制空白行
  442. const emptyRows = sheet.getRange(sortData.length, -1, sheet.zh_setting.emptyRows, -1);
  443. emptyRows.locked(sheet.zh_dataType === 'tree');
  444. if (sortData) {
  445. // 单元格写入数据
  446. sortData.forEach(function (data, i) {
  447. self._loadRowData(sheet, data, i);
  448. sheet.setRowVisible(i, data.visible);
  449. });
  450. }
  451. // 设置列单元格格式
  452. sheet.zh_setting.cols.forEach(function (col, j) {
  453. //if (!col.cellType) { return; }
  454. self._defineColCellType(sheet, j, col);
  455. });
  456. this.endMassOperation(sheet);
  457. } catch (err) {
  458. this.endMassOperation(sheet);
  459. }
  460. },
  461. /**
  462. * 重新加载部分数据行
  463. * @param {GC.Spread.Sheets.Worksheet} sheet
  464. * @param {Number} row
  465. * @param {Number} count
  466. */
  467. reLoadRowData: function (sheet, row, count = 1) {
  468. if (row < 0) { return; }
  469. const self = this;
  470. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  471. this.beginMassOperation(sheet);
  472. try {
  473. // 清空原单元格数据
  474. sheet.clear(row, -1, count, -1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  475. // 单元格重新写入数据
  476. for (let i = row; i < row + count; i++) {
  477. const data = sortData[i];
  478. if (!data) { continue; }
  479. this._loadRowData(sheet, data, i);
  480. }
  481. this.endMassOperation(sheet);
  482. } catch (err) {
  483. this.endMassOperation(sheet);
  484. }
  485. },
  486. /**
  487. * 重新加载部分行数据
  488. * @param {GC.Spread.Sheets.Worksheet} sheet
  489. * @param {Array} rows
  490. */
  491. reLoadRowsData: function (sheet, rows) {
  492. const self = this;
  493. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  494. this.beginMassOperation(sheet);
  495. try {
  496. for (const row of rows) {
  497. if (row < 0) { continue; }
  498. // 清空原单元格数据
  499. sheet.clear(row, -1, 1, -1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  500. const data = sortData[row];
  501. // 单元格重新写入数据
  502. this._loadRowData(sheet, data, row);
  503. };
  504. this.endMassOperation(sheet);
  505. } catch (err) {
  506. this.endMassOperation(sheet);
  507. }
  508. },
  509. /**
  510. * 重新加载部分列数据
  511. * @param {GC.Spread.Sheets.Worksheet} sheet
  512. * @param {Array} cols
  513. */
  514. reLoadColsData: function (sheet, cols) {
  515. const self = this;
  516. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  517. this.beginMassOperation(sheet);
  518. try {
  519. for (const iCol of cols) {
  520. // 清空原单元格数据
  521. sheet.clear(-1, iCol, -1, 1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  522. const col = sheet.zh_setting.cols[iCol];
  523. sortData.forEach(function (data, i) {
  524. // 设置值
  525. const cell = sheet.getCell(i, iCol);
  526. if (col.field !== '' && data[col.field]) {
  527. cell.value(data[col.field]).locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  528. } else {
  529. cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  530. }
  531. // 设置单元格格式
  532. if (col.formatter) {
  533. cell.formatter(col.formatter);
  534. }
  535. });
  536. }
  537. this.endMassOperation(sheet);
  538. } catch (err) {
  539. this.endMassOperation(sheet);
  540. }
  541. },
  542. reLoadNodesData: function (sheet, nodes) {
  543. this.beginMassOperation(sheet);
  544. nodes = nodes instanceof Array ? nodes : [nodes];
  545. for (const node of nodes) {
  546. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  547. this._loadRowData(sheet, node, sortData.indexOf(node));
  548. }
  549. this.endMassOperation(sheet);
  550. },
  551. /**
  552. * 根据data加载sheet数据,合并了一般数据和树结构数据的加载
  553. * @param {GC.Spread.Sheets.Worksheet} sheet
  554. * @param {String} dataType - 1.'zh_data' 2.'zh_tree'
  555. * @param {Array|PathTree} data - 对dataType对应
  556. */
  557. loadSheetData: function (sheet, dataType, data){
  558. sheet.zh_dataType = dataType;
  559. if (dataType === 'tree') {
  560. sheet.zh_tree = data;
  561. } else {
  562. sheet.zh_data = data;
  563. }
  564. this.protectedSheet(sheet);
  565. this.reLoadSheetData(sheet);
  566. },
  567. /**
  568. * 获取复制数据HTML格式(过滤不可见单元格)
  569. * @param {GC.Spread.Sheets.Worksheet} sheet
  570. * @returns {string}
  571. */
  572. getFilterCopyHTML: function (sheet) {
  573. const sel = sheet.getSelections()[0];
  574. const html = [];
  575. html.push('<table>');
  576. for (let i = sel.row, iLen = sel.row + sel.rowCount; i < iLen; i++) {
  577. // 跳过隐藏行
  578. if (!sheet.getCell(i, -1).visible()) { continue; }
  579. const rowHtml = [];
  580. rowHtml.push('<tr>');
  581. for (let j = sel.col, jLen = sel.col + sel.colCount; j < jLen; j++) {
  582. const data = sheet.getText(i, j);
  583. rowHtml.push('<td>' + data + '</td>');
  584. }
  585. rowHtml.push('</tr>');
  586. html.push(rowHtml.join(''));
  587. }
  588. html.push('</table>');
  589. return html.join('');
  590. },
  591. /**
  592. * 获取复制数据Text格式(过滤不可见单元格)
  593. * @param {GC.Spread.Sheets.Worksheet} sheet
  594. * @returns {string}
  595. */
  596. getFilterCopyText: function (sheet) {
  597. const copyData = [];
  598. const sel = sheet.getSelections()[0];
  599. for(let i = sel.row, iLen = sel.row + sel.rowCount; i < iLen; i++) {
  600. // 跳过隐藏行
  601. if (!sheet.getCell(i, -1).visible()) { continue; }
  602. const rowText = [];
  603. for (let j = sel.col, jLen = sel.col + sel.colCount; j < jLen; j++) {
  604. const data = sheet.getText(i, j);
  605. rowText.push(data);
  606. }
  607. copyData.push(rowText.join('\t'));
  608. }
  609. return copyData.join('\n');
  610. },
  611. /**
  612. * 树表结构,定位至指定的节点
  613. * @param {GC.Spread.Sheets.Worksheet} sheet - 需要定位的sheet
  614. * @param {Number} id - 定位节点的id
  615. */
  616. locateTreeNode: function (sheet, id, autoExpand = false) {
  617. const tree = sheet.zh_tree;
  618. if (!tree) { return }
  619. const node = tree.getItems(id);
  620. if (!node) { return }
  621. if (autoExpand && !node.visible) {
  622. const parents = tree.autoExpandNode(node);
  623. if (parents && parents.length > 0) {
  624. SpreadJsObj.reLoadNodesData(sheet, parents);
  625. SpreadJsObj.refreshTreeRowVisible(sheet);
  626. }
  627. }
  628. const index = tree.nodes.indexOf(node);
  629. const sels = sheet.getSelections();
  630. sheet.setSelection(index, sels[0].col, 1, 1);
  631. sheet.showRow(index, spreadNS.VerticalPosition.center);
  632. },
  633. saveTopAndSelect: function (sheet, cacheKey) {
  634. const sel = sheet.getSelections()[0];
  635. const top = sheet.getViewportTopRow(1);
  636. setLocalCache(cacheKey, JSON.stringify({top: top, sel: sel}));
  637. },
  638. loadTopAndSelect: function (sheet, cacheKey) {
  639. let ts = getLocalCache(cacheKey);
  640. if (ts !== '') {
  641. ts = JSON.parse(ts);
  642. if (ts === undefined || ts === null) return;
  643. if (ts.sel) {
  644. sheet.setSelection(ts.sel.row, ts.sel.col, ts.sel.rowCount, ts.sel.colCount);
  645. }
  646. if (ts.top) {
  647. sheet.showRow(ts.top, spreadNS.VerticalPosition.top);
  648. }
  649. }
  650. },
  651. resetTopAndSelect: function (sheet) {
  652. sheet.setSelection(0, 0, 1, 1);
  653. sheet.showRow(0, spreadNS.VerticalPosition.top);
  654. },
  655. /**
  656. * 获取当前选行的数据对象
  657. * @param {GC.Spread.Sheets.Worksheet} sheet
  658. * @returns {Object}
  659. */
  660. getSelectObject: function (sheet) {
  661. if (!sheet) {
  662. return null;
  663. } else if (sheet.zh_dataType) {
  664. const sel = sheet.getSelections()[0];
  665. if (!sel) {
  666. return null;
  667. }
  668. if (sheet.zh_dataType === this.DataType.Tree) {
  669. return sheet.zh_tree.nodes[sel.row];
  670. } else if (sheet.zh_dataType === this.DataType.Data) {
  671. return sheet.zh_data[sel.row];
  672. } else {
  673. return null;
  674. }
  675. }
  676. },
  677. /**
  678. * 刷新列显示
  679. * @param sheet
  680. */
  681. refreshColumnVisible: function (sheet) {
  682. if(sheet.zh_setting) {
  683. sheet.zh_setting.cols.forEach(function (col, index) {
  684. if (col.visible !== undefined && col.visible !== null) {
  685. sheet.setColumnVisible(index, col.visible);
  686. }
  687. });
  688. }
  689. },
  690. /**
  691. * 刷新行显示
  692. * @param sheet
  693. */
  694. refreshTreeRowVisible: function (sheet) {
  695. this.beginMassOperation(sheet);
  696. const sortData = sheet.zh_dataType === this.DataType.Data ? sheet.zh_data : sheet.zh_tree.nodes;
  697. for (const iRow in sortData) {
  698. const node = sortData[iRow];
  699. if (node.visible !== undefined && node.visible !== null) {
  700. sheet.setRowVisible(iRow, node.visible);
  701. } else {
  702. sheet.setRowVisible(iRow, true);
  703. }
  704. }
  705. // if (sheet.zh_tree) {
  706. // for (const iRow in sheet.zh_tree.nodes) {
  707. // const node = sheet.zh_tree.nodes[iRow];
  708. // if (node.visible !== undefined && node.visible !== null) {
  709. // sheet.setRowVisible(iRow, node.visible);
  710. // } else {
  711. // sheet.setRowVisible(iRow, true);
  712. // }
  713. // }
  714. // }
  715. this.endMassOperation(sheet);
  716. },
  717. refreshColumnAlign: function (sheet) {
  718. if (sheet.zh_setting) {
  719. for (const iCol in sheet.zh_setting.cols) {
  720. const col = sheet.zh_setting.cols[iCol];
  721. sheet.getRange(-1, iCol, -1, 1).hAlign(col.hAlign);
  722. }
  723. }
  724. },
  725. /**
  726. * 刷新列是否只读
  727. * @param sheet
  728. * @param field
  729. * @param readonly
  730. */
  731. resetFieldReadOnly: function (sheet, field, readonly) {
  732. const fields = field instanceof Array ? field : [field];
  733. if (sheet.zh_setting) {
  734. sheet.zh_setting.cols.forEach(function (col, i) {
  735. if (fields.indexOf(col.field) !== -1) {
  736. col.readOnly = readonly;
  737. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  738. sheet.getCell(iRow, i).locked(col.readOnly || sheet.zh_setting.readOnly || false);
  739. }
  740. //sheet.getRange(-1, i, -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(col.readOnly || sheet.zh_setting.readOnly || false);
  741. }
  742. });
  743. }
  744. },
  745. CellType: {
  746. /**
  747. * 获取树结构CellType
  748. * 通过SpreadJsObj.loadSheetData(sheet, 'tree', tree)加载树结构数据
  749. * 要求tree类型为PathTree, 节点必须含有{id, pid, level, order, is_leaf}数据
  750. * @returns {TreeNodeCellType}
  751. */
  752. getTreeNodeCellType: function () {
  753. const indent = 20;
  754. const levelIndent = -5;
  755. const halfBoxLength = 5;
  756. const halfExpandLength = 3;
  757. /**
  758. * 画一条点线段
  759. * @param canvas - 画布
  760. * @param x1 - 线段起点 x
  761. * @param y1 - 线段起点 y
  762. * @param x2 - 线段终点 x
  763. * @param y2 - 线段终点 y
  764. * @param color - 线段颜色
  765. */
  766. const drawDotLine = function (canvas, x1, y1, x2, y2, color) {
  767. canvas.save();
  768. // 设置偏移量
  769. canvas.translate(0.5, 0.5);
  770. canvas.beginPath();
  771. canvas.strokeStyle = color;
  772. canvas.dottedLine(x1, y1, x2, y2);
  773. canvas.stroke();
  774. canvas.restore();
  775. };
  776. /**
  777. * 画一条线段
  778. * @param canvas - 画布
  779. * @param x1 - 线段起点 x
  780. * @param y1 - 线段起点 y
  781. * @param x2 - 线段终点 x
  782. * @param y2 - 线段终点 y
  783. * @param color - 线段颜色
  784. */
  785. const drawLine = function (canvas, x1, y1, x2, y2, color) {
  786. canvas.save();
  787. // 设置偏移量
  788. canvas.translate(0.5, 0.5);
  789. canvas.beginPath();
  790. canvas.moveTo(x1, y1);
  791. canvas.lineTo(x2, y2);
  792. canvas.strokeStyle = color;
  793. canvas.stroke();
  794. canvas.restore();
  795. };
  796. /**
  797. * 画一个方框
  798. * @param {Object} canvas - 画布
  799. * @param {Object} rect - 方框区域
  800. * @param {String} lineColor - 画线颜色
  801. * @param {String} fillColor - 填充颜色
  802. */
  803. const drawBox = function (canvas, rect, lineColor, fillColor) {
  804. canvas.save();
  805. // 设置偏移量
  806. canvas.translate(0.5, 0.5);
  807. canvas.strokeStyle = lineColor;
  808. canvas.beginPath();
  809. canvas.moveTo(rect.left, rect.top);
  810. canvas.lineTo(rect.left, rect.bottom);
  811. canvas.lineTo(rect.right, rect.bottom);
  812. canvas.lineTo(rect.right, rect.top);
  813. canvas.lineTo(rect.left, rect.top);
  814. canvas.stroke();
  815. canvas.fillStyle = fillColor;
  816. canvas.fill();
  817. canvas.restore();
  818. };
  819. /**
  820. * 画树结构-展开收起按钮
  821. * @param {Object} canvas - 画布
  822. * @param {Number} x - 单元格左顶点坐标 x
  823. * @param {Number} y - 单元格左顶点坐标 y
  824. * @param {Number} w - 单元格宽度
  825. * @param {Number} h - 单元格高度
  826. * @param {Number} centerX - 按钮中央坐标
  827. * @param {Number} centerY - 按钮中央坐标
  828. * @param {Boolean} expanded - 当前节点展开收起状态
  829. */
  830. const drawExpandBox = function (canvas, x, y, w, h, centerX, centerY, expanded) {
  831. let rect = {
  832. top: centerY - halfBoxLength,
  833. bottom: centerY + halfBoxLength,
  834. left: centerX - halfBoxLength,
  835. right: centerX + halfBoxLength
  836. };
  837. let h1, h2, offset = 1;
  838. if (rect.left < x + w) {
  839. // 方框超出单元格宽度时,超出部分不画。
  840. rect.right = Math.min(rect.right, x + w);
  841. drawBox(canvas, rect, '#808080', 'white');
  842. // 画中心十字
  843. // 画十字横线
  844. h1 = centerX - halfExpandLength;
  845. h2 = Math.min(centerX + halfExpandLength, x + w);
  846. if (h2 > h1) {
  847. drawLine(canvas, h1, centerY, h2, centerY, '#808080');
  848. }
  849. // 画十字竖线
  850. if (!expanded && (centerX < x + w)) {
  851. drawLine(canvas, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, '#808080');
  852. }
  853. }
  854. };
  855. let TreeNodeCellType = function (){};
  856. TreeNodeCellType.prototype = new spreadNS.CellTypes.Text();
  857. const proto = TreeNodeCellType.prototype;
  858. /**
  859. * 绘制方法
  860. * @param {Object} canvas - 画布
  861. * @param value - cell.value
  862. * @param {Number} x - 单元格左顶点坐标 x
  863. * @param {Number} y - 单元格左顶点坐标 y
  864. * @param {Number} w - 单元格宽度
  865. * @param {Number} h - 单元格高度
  866. * @param {Object} style - cell.style
  867. * @param {Object} options
  868. */
  869. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  870. // 清理 画布--单元格范围 旧数据
  871. if (style.backColor) {
  872. canvas.save();
  873. canvas.fillStyle = style.backColor;
  874. canvas.fillRect(x, y, w, h);
  875. canvas.restore();
  876. } else {
  877. canvas.clearRect(x, y, w, h);
  878. }
  879. const tree = options.sheet.zh_tree;
  880. // 使用TreeCellType前,需定义sheet.tree
  881. if (tree) {
  882. const node = options.row < tree.nodes.length ? tree.nodes[options.row] : null;
  883. if (node) {
  884. const showTreeLine = true;
  885. const centerX = Math.floor(x) + (node.level) * indent + (node.level) * levelIndent + indent / 2;
  886. const centerY = Math.floor((y + (y + h)) / 2);
  887. // Draw Sibling Line
  888. if (showTreeLine) {
  889. // Draw Horizontal Line
  890. if (centerX < x + w) {
  891. const x1 = centerX + indent / 2;
  892. //drawLine(canvas, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  893. drawDotLine(canvas, centerX, centerY, Math.min(x1, x + w), centerY, '#b8b8b8');
  894. }
  895. // Draw Vertical Line
  896. if (centerX < x + w) {
  897. const y1 = tree.isLastSibling(node) ? centerY : y + h;
  898. const parent = tree.getParent(node);
  899. const y2 = y1 - centerY;
  900. if (node.order === 1 && !parent) {
  901. //drawLine(canvas, centerX, centerY, centerX, y1, 'gray');
  902. drawDotLine(canvas, centerX, centerY, centerX, y1, '#b8b8b8');
  903. } else {
  904. //drawLine(canvas, centerX, y, centerX, y1, 'gray');
  905. drawDotLine(canvas, centerX, y, centerX, y1, '#b8b8b8');
  906. }
  907. }
  908. }
  909. // Draw Expand Box
  910. if (!node.is_leaf) {
  911. drawExpandBox(canvas, x, y, w, h, centerX, centerY, node.expanded);
  912. }
  913. // Draw Parent Line
  914. if (showTreeLine) {
  915. let parent = tree.getParent(node), parentCenterX = centerX - indent - levelIndent;
  916. while (parent) {
  917. if (!tree.isLastSibling(parent)) {
  918. if (parentCenterX < x + w) {
  919. //drawLine(canvas, parentCenterX, y, parentCenterX, y + h, 'gray');
  920. drawDotLine(canvas, parentCenterX, y, parentCenterX, y + h, '#b8b8b8');
  921. }
  922. }
  923. parent = tree.getParent(parent);
  924. parentCenterX -= (indent + levelIndent);
  925. }
  926. };
  927. // 重定位x
  928. const move = (node.level + 1) * indent + (node.level) * levelIndent;
  929. x = x + move;
  930. w = w - move;
  931. }
  932. }
  933. // Drawing Text
  934. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  935. };
  936. /**
  937. * 获取点击信息
  938. * @param {Number} x
  939. * @param {Number} y
  940. * @param {Object} cellStyle
  941. * @param {Object} cellRect
  942. * @param {Object} context
  943. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  944. */
  945. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  946. return {
  947. x: x,
  948. y: y,
  949. row: context.row,
  950. col: context.col,
  951. cellStyle: cellStyle,
  952. cellRect: cellRect,
  953. sheet: context.sheet,
  954. sheetArea: context.sheetArea
  955. };
  956. };
  957. /**
  958. * 鼠标点击 树结构按钮 响应展开收起(未加载子节点时,先加载子节点)
  959. * @param {Object} hitinfo - 见getHitInfo
  960. */
  961. proto.processMouseDown = function (hitinfo) {
  962. const offset = -1;
  963. const tree = hitinfo.sheet.zh_tree;
  964. if (!tree) { return; }
  965. const node = tree.nodes[hitinfo.row];
  966. if (!node) { return; }
  967. let centerX = hitinfo.cellRect.x + offset + (node.level) * indent + (node.level) * levelIndent + indent / 2;
  968. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  969. // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  970. if (Math.abs(hitinfo.x - centerX) < halfBoxLength && Math.abs(hitinfo.y - centerY) < halfBoxLength) {
  971. const children = tree.getChildren(node);
  972. if (!node.expanded && !node.is_leaf && children.length === 0 && tree.loadChildren) {
  973. tree.loadChildren(node, function () {
  974. node.expanded = true;
  975. const children = tree.getChildren(node);
  976. hitinfo.sheet.addRows(hitinfo.row + 1, children.length);
  977. SpreadJsObj.reLoadRowData(hitinfo.sheet, hitinfo.row + 1, children.length);
  978. });
  979. } else {
  980. tree.setExpanded(node, !node.expanded);
  981. SpreadJsObj.massOperationSheet(hitinfo.sheet, function () {
  982. const posterity = tree.getPosterity(node);
  983. for (const child of posterity) {
  984. hitinfo.sheet.setRowVisible(tree.nodes.indexOf(child), child.visible, hitinfo.sheetArea);
  985. }
  986. });
  987. hitinfo.sheet.repaint();
  988. }
  989. }
  990. };
  991. return new TreeNodeCellType();
  992. },
  993. /**
  994. * 获取 带悬浮提示的CellType
  995. * @returns {TipCellType}
  996. */
  997. getTipCellType: function () {
  998. const maxHintWidth = 200, indent = 15, borderIndent = 10;
  999. const TipCellType = function () {};
  1000. // 继承 SpreadJs定义的 普通的TextCellType
  1001. TipCellType.prototype = new spreadNS.CellTypes.Text();
  1002. const proto = TipCellType.prototype;
  1003. proto.getTextDisplayWidth = function(hitinfo, str, font) {
  1004. const xs = hitinfo.sheet.getParent().xs;
  1005. const ctx = xs.childNodes[0].getContext("2d");
  1006. if (font && font !== '') {
  1007. ctx.font = font;
  1008. } else {
  1009. ctx.font = hitinfo.cellStyle.font;
  1010. }
  1011. return ctx.measureText(str).width;
  1012. };
  1013. proto.showTip = function (hitinfo, text) {
  1014. return text && text !== '';
  1015. };
  1016. /**
  1017. * 获取点击信息
  1018. * @param {Number} x
  1019. * @param {Number} y
  1020. * @param {Object} cellStyle
  1021. * @param {Object} cellRect
  1022. * @param {Object} context
  1023. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1024. */
  1025. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1026. return {
  1027. x: x,
  1028. y: y,
  1029. row: context.row,
  1030. col: context.col,
  1031. cellStyle: cellStyle,
  1032. cellRect: cellRect,
  1033. sheet: context.sheet,
  1034. sheetArea: context.sheetArea,
  1035. ctx: context.sheet.getParent().xs,
  1036. };
  1037. };
  1038. /**
  1039. * 鼠标进入单元格事件 - 显示悬浮提示
  1040. * @param {Object} hitinfo - 见getHitInfo返回值
  1041. */
  1042. proto.processMouseEnter = function (hitinfo) {
  1043. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  1044. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1045. if (col.getTip && Object.prototype.toString.apply(col.getTip) === "[object Function]") {
  1046. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1047. text = col.getTip(sortData[hitinfo.row]);
  1048. }
  1049. const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
  1050. if (pos && this.showTip(hitinfo, text)) {
  1051. if (!this._toolTipElement) {
  1052. let div = $('#autoTip')[0];
  1053. if (!div) {
  1054. div = document.createElement("div");
  1055. $(div).css("position", "absolute")
  1056. .css("border", "1px #C0C0C0 solid")
  1057. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  1058. .css("font", "9pt Arial")
  1059. .css("background", "white")
  1060. .css("padding", 5)
  1061. .css("z-index", 999)
  1062. .css("max-width", maxHintWidth)
  1063. .css("word-wrap", "break-word")
  1064. .attr("id", 'autoTip');
  1065. document.body.insertBefore(div, null);
  1066. }
  1067. const validWidth = $(window).width() - (pos.x + hitinfo.x + indent) - borderIndent;
  1068. const textWidth = this.getTextDisplayWidth(hitinfo, text, "9pt Arial");
  1069. if (validWidth >= maxHintWidth || textWidth <= validWidth) {
  1070. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x + indent);
  1071. } else if (textWidth > maxHintWidth) {
  1072. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - maxHintWidth);
  1073. } else {
  1074. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - textWidth);
  1075. }
  1076. this._toolTipElement = div;
  1077. $(div).show("fast");
  1078. }
  1079. }
  1080. };
  1081. /**
  1082. * 鼠标移出单元格事件 - 隐藏悬浮提示
  1083. * @param {Object} hitinfo - 见getHitInfo返回值
  1084. */
  1085. proto.processMouseLeave = function (hitinfo) {
  1086. if (this._toolTipElement) {
  1087. $(this._toolTipElement).hide();
  1088. this._toolTipElement = null;
  1089. }
  1090. };
  1091. return new TipCellType();
  1092. },
  1093. getAutoTipCellType: function () {
  1094. const AutoTipCellType = function () {};
  1095. // 继承 TipCellType
  1096. AutoTipCellType.prototype = SpreadJsObj.CellType.getTipCellType();
  1097. const proto = AutoTipCellType.prototype
  1098. proto.showTip = function (hitinfo, text) {
  1099. return text && text !== '' && this.getTextDisplayWidth(hitinfo, text) > hitinfo.cellRect.width;
  1100. };
  1101. return new AutoTipCellType();
  1102. },
  1103. /**
  1104. * 获取 带图片的cellType(图片需在document中定义好img,并写入col的img属性)
  1105. *
  1106. * img:
  1107. * 1. 整列固定,则传入img的select
  1108. * e.g. {title: '附件', field: 'attachment', cellType: 'image', img = '#attachment-img'}
  1109. *
  1110. * 2. 各单元格自定义,则
  1111. * e.g. {title: '附件', field: 'attachment', cellType: 'image', img = getAttachmentImage}
  1112. * function getAttachmentImage (data) {
  1113. * $('#attachment-img').url = data.attachmentImageUrl;
  1114. * return $('#attachment-img')[0];
  1115. * }
  1116. *
  1117. * @returns {ImageCellType}
  1118. */
  1119. getImageCellType: function () {
  1120. const ImageCellType = function (){};
  1121. ImageCellType.prototype = new spreadNS.CellTypes.Text();
  1122. const proto = ImageCellType.prototype;
  1123. proto.getImage = function (sheet, iRow, iCol) {
  1124. const col = sheet.zh_setting.cols[iCol];
  1125. let imgSource = col.img;
  1126. if (imgSource && Object.prototype.toString.apply(imgSource) === "[object Function]") {
  1127. const sortData = SpreadJsObj.getSortData(sheet);
  1128. const data = sortData ? sortData[iRow] : null;
  1129. return data ? imgSource(data) : null;
  1130. } else {
  1131. return $(imgSource)[0] ? $(imgSource)[0] : null;
  1132. }
  1133. };
  1134. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  1135. const col = options.sheet.zh_setting.cols[options.col];
  1136. const img = this.getImage(options.sheet, options.row, options.col);
  1137. const indent = col.indent ? col.indent : 10;
  1138. if (img) {
  1139. if (style.backColor) {
  1140. canvas.save();
  1141. canvas.fillStyle = style.backColor;
  1142. canvas.fillRect(x, y, indent + img.width, h);
  1143. canvas.restore();
  1144. }
  1145. canvas.drawImage(img, x + indent, y + (h - img.height) / 2);
  1146. if (style.hAlign !== spreadNS.HorizontalAlign.left) {
  1147. style.hAlign = spreadNS.HorizontalAlign.left;
  1148. }
  1149. x = x + indent + img.width;
  1150. w = w - indent - img.width;
  1151. }
  1152. // Drawing Text
  1153. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1154. };
  1155. /**
  1156. * 获取点击信息
  1157. * @param {Number} x
  1158. * @param {Number} y
  1159. * @param {Object} cellStyle
  1160. * @param {Object} cellRect
  1161. * @param {Object} context
  1162. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1163. */
  1164. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1165. return {
  1166. x: x,
  1167. y: y,
  1168. row: context.row,
  1169. col: context.col,
  1170. cellStyle: cellStyle,
  1171. cellRect: cellRect,
  1172. sheet: context.sheet,
  1173. sheetArea: context.sheetArea
  1174. };
  1175. };
  1176. /**
  1177. * 鼠标点击
  1178. * @param {Object} hitinfo - 见getHitInfo
  1179. */
  1180. proto.processMouseDown = function (hitinfo) {
  1181. const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1182. if (img) {
  1183. const halfX = img.width / 2, halfY = img.height / 2;
  1184. const centerX = hitinfo.cellRect.x + indent + halfX;
  1185. const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1186. // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  1187. if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1188. const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1189. if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1190. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1191. const data = sortData ? sortData[hitinfo.row] : null;
  1192. imageClick(data);
  1193. }
  1194. }
  1195. }
  1196. };
  1197. return new ImageCellType();
  1198. },
  1199. /**
  1200. *
  1201. * 获取 带normal-hover-active按钮的cellType(需定义三张图片,须在document中定义好img,并写入col的normalImg, hoverImg, activeImg属性)
  1202. * 其中:normalImg必需,向下套用(不存在activeImg则使用hoverImg,不存在hoverImg则使用normalImg)
  1203. * 三个img均可像getImageCellType一样动态获取,参见getImageCellType注释
  1204. *
  1205. * @returns {ImageCellType}
  1206. */
  1207. getImageButtonCellType: function () {
  1208. let hover = 1, active = 2;
  1209. const ImageCellType = function (){};
  1210. ImageCellType.prototype = new spreadNS.CellTypes.Text();
  1211. const proto = ImageCellType.prototype;
  1212. proto.getImage = function (sheet, iRow, iCol) {
  1213. const col = sheet.zh_setting.cols[iCol];
  1214. let imgSource = col.normalImg;
  1215. const cell = sheet.getCell(iRow, iCol), tag = cell.tag();
  1216. if (tag === active) {
  1217. imgSource = col.activeImg ? col.activeImg : (col.hoverImg ? col.hoverImg : col.normalImg);
  1218. } else if (tag === hover) {
  1219. imgSource = col.hoverImg ? col.hoverImg : col.normalImg;
  1220. }
  1221. if (imgSource && Object.prototype.toString.apply(imgSource) === "[object Function]") {
  1222. const sortData = SpreadJsObj.getSortData(sheet);
  1223. const data = sortData ? sortData[iRow] : null;
  1224. return data ? imgSource(data) : null;
  1225. } else {
  1226. return $(imgSource)[0] ? $(imgSource)[0] : null;
  1227. }
  1228. };
  1229. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  1230. const col = options.sheet.zh_setting.cols[options.col];
  1231. const sortData = SpreadJsObj.getSortData(options.sheet);
  1232. const data = sortData ? sortData[options.row] : null;
  1233. let showImage = true;
  1234. if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
  1235. showImage = col.showImage(data);
  1236. }
  1237. const img = showImage ? this.getImage(options.sheet, options.row, options.col) : null;
  1238. const indent = col.indent ? col.indent : 10;
  1239. if (style.hAlign === spreadNS.HorizontalAlign.right) {
  1240. if (img) {
  1241. if (style.backColor) {
  1242. canvas.save();
  1243. canvas.fillStyle = style.backColor;
  1244. canvas.fillRect(x + w - indent - img.width, y, img.width, h);
  1245. canvas.restore();
  1246. }
  1247. canvas.drawImage(img, x + w - indent - img.width, y + (h - img.height) / 2);
  1248. w = w - indent - img.width;
  1249. }
  1250. // Drawing Text
  1251. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1252. } else {
  1253. if (img) {
  1254. if (style.backColor) {
  1255. canvas.save();
  1256. canvas.fillStyle = style.backColor;
  1257. canvas.fillRect(x, y, indent + img.width, h);
  1258. canvas.restore();
  1259. }
  1260. canvas.drawImage(img, x + 10, y + (h - img.height) / 2);
  1261. if (style.hAlign !== spreadNS.HorizontalAlign.left) {
  1262. style.hAlign = spreadNS.HorizontalAlign.left;
  1263. }
  1264. x = x + indent + img.width;
  1265. w = w - indent - img.width;
  1266. }
  1267. // Drawing Text
  1268. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1269. }
  1270. };
  1271. /**
  1272. * 获取点击信息
  1273. * @param {Number} x
  1274. * @param {Number} y
  1275. * @param {Object} cellStyle
  1276. * @param {Object} cellRect
  1277. * @param {Object} context
  1278. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1279. */
  1280. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1281. return {
  1282. x: x,
  1283. y: y,
  1284. row: context.row,
  1285. col: context.col,
  1286. cellStyle: cellStyle,
  1287. cellRect: cellRect,
  1288. sheet: context.sheet,
  1289. sheetArea: context.sheetArea
  1290. };
  1291. };
  1292. /**
  1293. * 鼠标点击
  1294. * @param {Object} hitinfo - 见getHitInfo
  1295. */
  1296. proto.processMouseEnter = function (hitinfo) {
  1297. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1298. // Drawing Image
  1299. if (col.hoverImg) {
  1300. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1301. cell.tag(hover);
  1302. hitinfo.sheet.repaint(hitinfo.cellRect);
  1303. }
  1304. };
  1305. proto.processMouseLeave = function (hitinfo) {
  1306. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1307. // Drawing Image
  1308. if (col.hoverImg) {
  1309. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1310. cell.tag(null);
  1311. hitinfo.sheet.repaint(hitinfo.cellRect);
  1312. }
  1313. };
  1314. proto.processMouseDown = function (hitinfo) {
  1315. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1316. if (col.activeImg) {
  1317. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1318. cell.tag(active);
  1319. hitinfo.sheet.repaint(hitinfo.cellRect);
  1320. }
  1321. };
  1322. proto.processMouseUp = function (hitinfo) {
  1323. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1324. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1325. const data = sortData ? sortData[hitinfo.row] : null;
  1326. if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
  1327. if (!col.showImage(data)) {
  1328. return;
  1329. }
  1330. }
  1331. const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1332. if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1333. imageClick(data);
  1334. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1335. cell.tag(null);
  1336. hitinfo.sheet.repaint(hitinfo.cellRect);
  1337. }
  1338. };
  1339. /*
  1340. 注释部分以进入鼠标进入图片,点击图片为基准更新图片,鼠标快速移动时,可能失效
  1341. */
  1342. // proto.processMouseDown = function (hitinfo) {
  1343. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1344. // const halfX = img.width / 2, halfY = img.height / 2;
  1345. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1346. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1347. //
  1348. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1349. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1350. // cell.tag(down);
  1351. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1352. // }
  1353. // };
  1354. // proto.processMouseUp = function (hitinfo) {
  1355. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1356. // const halfX = img.width / 2, halfY = img.height / 2;
  1357. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1358. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1359. //
  1360. // // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  1361. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1362. // const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1363. // if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1364. // const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1365. // const data = sortData ? sortData[hitinfo.row] : null;
  1366. // imageClick(data);
  1367. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1368. // cell.tag(null);
  1369. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1370. // }
  1371. // }
  1372. // };
  1373. // proto.processMouseMove = function (hitinfo) {
  1374. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1375. // const halfX = img.width / 2, halfY = img.height / 2;
  1376. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1377. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1378. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1379. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1380. // if (cell.tag() !== hover) {
  1381. // cell.tag(hover);
  1382. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1383. // }
  1384. // } else {
  1385. // if (cell.tag() === hover) {
  1386. // cell.tag(null);
  1387. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1388. // }
  1389. // }
  1390. // };
  1391. return new ImageCellType();
  1392. },
  1393. /**
  1394. * 获取 嵌入Html的cellType
  1395. * @returns {HTMLCellType}
  1396. */
  1397. getHtmlCellType: function () {
  1398. const HTMLCellType = function (){};
  1399. HTMLCellType.prototype = new spreadNS.CellTypes.Text;
  1400. const proto = ImageCellType.prototype;
  1401. proto.paint = function (ctx, value, x, y, w, h, style, context) {
  1402. let DOMURL = window.URL || window.webkitURL || window;
  1403. let cell = context.sheet.getCell(context.row, context.col);
  1404. let img = cell.tag();
  1405. if (img) {
  1406. try {
  1407. ctx.save();
  1408. ctx.rect(x, y, w, h);
  1409. ctx.clip();
  1410. ctx.drawImage(img, x + 2, y + 2)
  1411. ctx.restore();
  1412. cell.tag(null);
  1413. return;
  1414. }
  1415. catch (err) {
  1416. GC.Spread.Sheets.CustomCellType.prototype.paint.apply(this, [ctx, "#HTMLError", x, y, w, h, style, context])
  1417. cell.tag(null);
  1418. return;
  1419. }
  1420. }
  1421. let svgPattern = '<svg xmlns="http://www.w3.org/2000/svg" width="{0}" height="{1}">' +
  1422. '<foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml" style="font:{2}">{3}</div></foreignObject></svg>';
  1423. let data = svgPattern.replace("{0}", w).replace("{1}", h).replace("{2}", style.font).replace("{3}", value);
  1424. let doc = document.implementation.createHTMLDocument("");
  1425. doc.write(data);
  1426. // Get well-formed markup
  1427. data = (new XMLSerializer()).serializeToString(doc.body.children[0]);
  1428. img = new Image();
  1429. //var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
  1430. //var url = DOMURL.createObjectURL(svg);
  1431. //img.src = url;
  1432. img.src = 'data:image/svg+xml;base64,' + window.btoa(data);
  1433. cell.tag(img);
  1434. img.onload = function () {
  1435. context.sheet.repaint(new GC.Spread.Sheets.Rect(x, y, w, h));
  1436. }
  1437. };
  1438. return new HTMLCellType();
  1439. },
  1440. /**
  1441. * 获取 字符超长缩略的cellType
  1442. * @returns {EllipsisTextCellType}
  1443. */
  1444. getEllipsisTextCellType: function () {
  1445. const EllipsisTextCellType = function (){};
  1446. EllipsisTextCellType.prototype = new spreadNS.CellTypes.Text;
  1447. const proto = EllipsisTextCellType.prototype;
  1448. proto.getEllipsisText = function(c, str, maxWidth) {
  1449. var width = c.measureText(str).width;
  1450. var ellipsis = '…';
  1451. var ellipsisWidth = c.measureText(ellipsis).width;
  1452. if (width <= maxWidth || width <= ellipsisWidth) {
  1453. return str;
  1454. } else {
  1455. var len = str.length;
  1456. while (width >= maxWidth - ellipsisWidth && len-- > 0) {
  1457. str = str.substring(0, len);
  1458. width = c.measureText(str).width;
  1459. }
  1460. return str + ellipsis;
  1461. }
  1462. };
  1463. proto.paint = function (ctx, value, x, y, w, h, style, context) {
  1464. ctx.font = style.font;
  1465. value = this.getEllipsisText(ctx, value, w - 2);
  1466. spreadNS.CellTypes.Text.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, context]);
  1467. };
  1468. return new EllipsisTextCellType();
  1469. },
  1470. getEllipsisTextAutoTipCellType: function () {
  1471. const CellType = function () {};
  1472. // 继承 TipCellType
  1473. CellType.prototype = SpreadJsObj.CellType.getAutoTipCellType();
  1474. const proto = CellType.prototype;
  1475. const ellipsisTextCellType = SpreadJsObj.CellType.getEllipsisTextCellType();
  1476. proto.getEllipsisText = ellipsisTextCellType.getEllipsisText;
  1477. proto.paint = ellipsisTextCellType.paint;
  1478. return new CellType();
  1479. },
  1480. /**
  1481. * 获取 动态显示ComboBox的cellType
  1482. * @returns {ActiveComboCellType}
  1483. */
  1484. getActiveComboCellType: function () {
  1485. const ActiveComboCellType = function () {};
  1486. ActiveComboCellType.prototype = new spreadNS.CellTypes.ComboBox();
  1487. const proto = ActiveComboCellType.prototype;
  1488. proto.paintValue = function (ctx, value, x, y, w, h, style, options) {
  1489. const sheet = options.sheet;
  1490. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
  1491. && !sheet.getCell(options.row, options.col).locked()) {
  1492. spreadNS.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
  1493. } else {
  1494. spreadNS.CellTypes.Base.prototype.paintValue.apply(this, arguments);
  1495. }
  1496. };
  1497. proto.getHitInfo = function (x, y, cellStyle, cellRect, options) {
  1498. const sheet = options.sheet;
  1499. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
  1500. && !sheet.getCell(options.row, options.col).locked()) {
  1501. return spreadNS.CellTypes.ComboBox.prototype.getHitInfo.apply(this, [x, y, cellStyle, cellRect, options]);
  1502. } else {
  1503. return {
  1504. x: x,
  1505. y: y,
  1506. row: options.row,
  1507. col: options.col,
  1508. cellStyle: cellStyle,
  1509. cellRect: cellRect,
  1510. sheetArea: options.sheetArea
  1511. };
  1512. }
  1513. };
  1514. return new ActiveComboCellType();
  1515. },
  1516. /**
  1517. * 获取 单位的CellType
  1518. * @returns {GC.Spread.Sheets.CellTypes.ComboBox}
  1519. */
  1520. getUnitCellType: function () {
  1521. let combo = this.getActiveComboCellType();
  1522. combo.itemHeight(10).items(['m', 'km', 'm2', 'm3', 'dm3', 'kg', 't', 'm3·km',
  1523. '总额', '月' ,'项', '处' ,'个', '根', '棵', '块', '台', '系统', '每一试桩',
  1524. '桥长米', '公路公里', '株', '组', '座', '元', '工日', '套', '台班', '艘班', '亩',
  1525. 'm/处', 'm/道', 'm/座', 'm2/m', 'm3/m', 'm3/处', '根/米', 'm3/m2']);
  1526. return combo;
  1527. }
  1528. }
  1529. };