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