spreadjs_zh.js 89 KB

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