spreadjs_zh.js 89 KB

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