spreadjs_zh.js 89 KB

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