U.Excel.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. Namespace.register("U.Excel");
  2. U.Excel.TF = {
  3. "ID": { "RW": [[]],
  4. "TF": [[40, 20]],
  5. "Cell": [[]],
  6. "L": [[]],
  7. "T": [[]]
  8. }
  9. }; //数据库变量 原始变量
  10. U.Excel.SY = {
  11. "UW": window,
  12. "OL": true,
  13. "userid": "",
  14. "TF": [],
  15. "BC": false,
  16. "ID": "",
  17. "CP": [],
  18. "TD": false,
  19. "SEO": false,
  20. "C": [],
  21. "CE": {
  22. "RW": [],
  23. "TF": [],
  24. "Cell": [],
  25. "L": [],
  26. "T": []
  27. },
  28. Height: 25,
  29. Width: 160
  30. }; //Excel使用变量
  31. //userid正在使用Excel的ID ID使用文件的ID CP复制区域的实体 TD是否允许拉选 SEO拉选的编辑框 C拉选实体 CE数据库存储变量
  32. US = parent.US;
  33. //右键变量
  34. U.Excel.SY["RM"] = {
  35. "EO": [["U_E_OptionsImg", "插入", U.Excel.NewTZB],
  36. ["U_E_OptionsImg", "删除", U.Excel.DelectSheet]],
  37. "LO": [["U_E_OptionsImg", "在上面插入", U.M.apply(this, [[U.Excel.InsertRowsCols, ["T"]]])],
  38. ["U_E_OptionsImg", "在下面插入", U.M.apply(this, [[U.Excel.InsertRowsCols, ["B"]]])],
  39. ["U_E_OptionsImg", "删除行", U.M.apply(this, [[U.Excel.DeleteRowsCols, ['L']]])],
  40. ["U_E_OptionsImg", "锁定行", ""]],
  41. "TO": [["U_E_OptionsImg", "在左边插入", U.M.apply(this, [[U.Excel.InsertRowsCols, ["L"]]])],
  42. ["U_E_OptionsImg", "在右边插入", U.M.apply(this, [[U.Excel.InsertRowsCols, ["R"]]])],
  43. ["U_E_OptionsImg", "删除列", U.M.apply(this, [[U.Excel.DeleteRowsCols, ['T']]])], ["U_E_OptionsImg", "隐藏列", ""],
  44. ["U_E_OptionsImg", "锁定列", ""],
  45. ["U_E_OptionsImg", "排序", ""], ["U_E_OptionsImg", "筛选", ""],
  46. ["U_E_OptionsImg", "列属性", ""]],
  47. "SO": [["U_E_OptionsImg", "合并单元格", U.Excel.MergeCells],
  48. ["U_E_OptionsImg", "拆分单元格", U.Excel.SplitCell]], "CO": [["U_E_OptionsImg", "批注", ""]],
  49. "MO": [["U_E_ICO U_E_TUOJ", "剪切", U.Excel.Cut], ["U_E_ICO ico_07", "复制", U.Excel.CopyFunction],
  50. ["U_E_ICO U_E_TUOZ", "粘贴", U.Excel.Paste],
  51. ["U_E_OptionsImg", "清除内容", U.M.apply(this, [[U.Excel.EmptyContent, ['InnerHTML']]])]]
  52. };
  53. //-----------------------------------------------------------------------------------查看文件的Excel
  54. //#region Excel查看
  55. //连接查看Word资料
  56. window.onload = function () {
  57. U.D.TopForm();
  58. U.M.ShieldedRightAndSelect();
  59. var _UDID = U.M.QueryString("ID");
  60. if (_UDID) {
  61. parent.U.A.Request(US.Auth, ["GetFileContent", _UDID], U.Excel.AsynGOF, [[$("body")[0], true], _UDID]);
  62. };
  63. }
  64. //获取文件异步
  65. U.Excel.AsynGOF = function (r) {
  66. var _UST, _UDID = r.context[1];
  67. r = r.value;
  68. U.Excel.SY["ID"] = _UDID;
  69. r = U.Excel.CSOPBE(r, _UDID);
  70. U.Excel.BLSC(_UDID, r);
  71. parent.$("body").addAttrArray({ "innerHTML": U.Excel.CKLBCJ(), "style": { "position": "absolute", "overflow": "auto"} });
  72. }
  73. //创建查看列表的
  74. U.Excel.CKLBCJ = function (UWI) {
  75. var _UH, _UW, _UDSD, _UDTD, _UDMD,
  76. _UGE = U.Excel.SY["CE"]["TF"],
  77. _UDPD = $$("div", { "style": { "cssText": "width:100%;height:100%;overflow:auto;"} });
  78. _UDTD = $$("div", { "className": "U_E_CC U_E_CCO", "style": { "position": "static"} }, _UDPD);
  79. _UDSD = $$("div", { "className": "U_E_CCL" }, _UDTD);
  80. $$("div", { "className": "U_E_CCLT" }, _UDSD);
  81. _UDSD = $$("div", { "className": "U_E_CCLC U_E_CCLCO", "style": { "height": "100%"} }, _UDSD);
  82. _UDSD = $$("div", { "className": "U_E_LB", "id": "U_E_LB" }, _UDSD);
  83. _UH = U.Excel.SPTP(_UGE[0], _UDSD, "L");
  84. _UDSD = $$("div", { "className": "U_E_CCH" }, _UDTD);
  85. _UDMD = $$("div", { "className": "U_E_CCB" }, _UDSD);
  86. _UDMD = $$("div", { "className": "U_E_TB", "id": "U_E_TB" }, _UDMD);
  87. _UW = U.Excel.SPTP(_UGE[1], _UDMD, "T");
  88. _UDSD.style.width = _UW + "px"; _UDTD.style.width = _UW + 51 + "px"
  89. _UDMD = $$("div", { "className": "U_E_CCC", "style": { "height": _UH + "px"} }, _UDSD);
  90. _UDMD = $$("div", { "className": "U_E_CCCH U_E_CCCHO" }, _UDMD);
  91. _UDMD = $$("div", { "className": "U_E_TableArea", "id": "U_E_TableArea" }, _UDMD);
  92. U.Excel.CBG(_UGE, _UDMD);
  93. _UDSD = $$("div", { "className": "U_E_CX" }, _UDPD);
  94. _UDMD = $$("div", { "className": "UD_SYQEXR", "id": "UD_SYQEXR" }, _UDSD);
  95. U.Excel.RWD(_UDMD, U.Excel.QHRWL);
  96. return _UDPD.outerHTML;
  97. }
  98. //底部任务栏切换
  99. U.Excel.QHRWL = function (ITF, UW) {
  100. UW = UW || window;
  101. var _UW, _UH,
  102. _UDOD = UW.$("#U_E_TB"),
  103. _UDTD = UW.$("#U_E_TableArea"),
  104. _UDSD = UW.$("#U_E_LB"),
  105. _UKE = UD_SYQEXR,
  106. _UDE = U.Excel.SwitchSheetTabs(ITF, true);
  107. U.Excel.SY["UW"] = UW;
  108. if (_UDE) {
  109. document.body.scrollTop = 0;
  110. _UH = U.Excel.SPTP(_UDE["TF"][0], _UDSD[0], "L");
  111. _UW = U.Excel.SPTP(_UDE["TF"][1], _UDOD[0], "T");
  112. _UDOD.Parent(2).style.width = _UW + "px";
  113. _UDOD.Parent(3).style.width = _UW + 41 + "px";
  114. U.Excel.CBG(_UDE["TF"], _UDTD[0]);
  115. $(_UDTD).Parent(2).style.height = _UH + "px";
  116. U.M.SCT(0, UW.$("body"));
  117. U.MR.DHQH(this, "UD_SYQEXROO");
  118. }
  119. }
  120. //#endregion
  121. //-------------------------------------------------------------------------------Excel初始化--------------------------------------------------------------------------
  122. //#region Excel 初始化
  123. //打开保存数据的Excel
  124. U.Excel.OPBE = function (UDID, UDE, userid, UAE) {
  125. var UDE, _UGE = U.Excel.SY,
  126. _UOID = _UGE["ID"];
  127. (UAE && UAE["UFN"]) && (U.Ut.AddObj(U.Excel, UAE["UFN"]), delete UAE["UFN"]);
  128. U.Ut.AddObj(_UGE, { "BC": false, "UAE": UAE, "ID": UDID || "ID", "userid": userid, "ET": UDE });
  129. if (UDID) {
  130. UDE = UDE || (UDID ? _$(US.Disk.UserDisk[0]).Select({ "UserDirectoryID": UDID }, null, 1) : ""); //获取使用的Excel
  131. if (UDE && UDE.UsOffice != null) { UDE.UsOffice = U.Excel.CSOPBE(UDE.UsOffice); U.Excel.BLSC(UDID, UDE.UsOffice); } //设置变量
  132. else { parent.U.A.Request(US.Auth, ["GetFileContent", UDID], U.Excel.AsynOPBE, ["", UDID, UDE, userid, UAE]); return; }
  133. }
  134. else { UDE = U.Excel.TF["ID"]; U.Excel.BLSC("ID", UDE); } //生成空白的Excel
  135. U.Excel.Onload(UDE); //设置初始化Excel
  136. }
  137. //Office异步
  138. U.Excel.AsynOPBE = function (r) {
  139. var context = r.context,
  140. _UDID = context[1],
  141. _UDE = context[2],
  142. _userid = context[3],
  143. _UAE = context[4];
  144. r = r.value;
  145. r = U.Excel.CSOPBE(r, _UDE.UserDirectoryID);
  146. _UDE.UsOffice = r;
  147. U.Excel.OPBE(_UDID, _UDE, _userid, _UAE); //打印Excel
  148. }
  149. //office文件
  150. U.Excel.CSOPBE = function (UDE, UDID) {
  151. if ((!UDE || !UDE["Cell"]) || U.Ut.isString(UDE)) {
  152. try {
  153. eval("0,r=" + UDE);
  154. }
  155. catch (e) {
  156. parent.U.Alert("新初始化文件");
  157. UDE = { "RW": [[]], "TF": [[40, 20]], "Cell": [[]], "L": [[]], "T": [[]] };
  158. (UDID && parent.U.Adisk) && (parent.U.A.Request(US.Auth, ["SaveFileContent", UDID, U.MS.jsonToStr(UDE), ""]), U.M.apply(), [""]);
  159. }
  160. }
  161. return UDE;
  162. }
  163. //生成全局变量
  164. U.Excel.BLSC = function (UDID, UDE) {
  165. var i, j,
  166. _UTE = U.Excel.TF,
  167. _UGE = U.Excel.SY["CE"];
  168. _UTE[UDID] = UDE;
  169. for (j = 0; j < UDE["RW"].length; j++) {
  170. if (UDE["RW"][j]) { break; }
  171. } //查看的位置
  172. for (i in UDE) {
  173. if (UDE.hasOwnProperty(i)) {
  174. _UGE[i] = (i == "RW" ? UDE[i] : UDE[i][j]);
  175. }
  176. } //生成查看变量
  177. return _UGE;
  178. }
  179. //生成所有的Excel工具
  180. U.Excel.Onload = function () { }
  181. //#endregion
  182. //#region 页面生成
  183. //生成页面
  184. U.Excel.CNO = function () {
  185. var _UGE = U.Excel.SY;
  186. U.Excel.RWD(_UGE["UAE"]["XR"]);
  187. U.Excel.RefreshTable(); //生成Excel表格
  188. U.Excel.EditOnmousedown($("div", $("#U_E_TableArea")[0])[0], 0);
  189. _UGE["TD"] = false; //编辑区域设置 //取消点击
  190. }
  191. //生成底部任务栏
  192. U.Excel.RWD = function (UDOD, UTF) {
  193. var i,
  194. _UGE = U.Excel.SY,
  195. _UDE = _UGE["CE"]["RW"],
  196. _UDFD = $$("frag");
  197. UDOD = UDOD || _UGE["UAE"]["XR"];
  198. (_UDE.length == 1) && (_UDE[0] = true);
  199. UDOD.innerText = "";
  200. for (i = 0; i < _UDE.length; i++) {
  201. $$("div", { "innerHTML": "表格" + (i + 1), "className": "UD_SYQEXRO" + (_UDE[i] ? " UD_SYQEXROO" : ""), "onclick": [(UTF || U.Excel.SwitchSheetTabs), [i]], "oncontextmenu": UTF ? "" : [[U.M.StopBubble], [U.Excel.CreateContextMenu, ["Sheet"]]] }, _UDFD);
  202. }
  203. UDOD.appendChild(_UDFD);
  204. }
  205. //右键底部任务
  206. U.Excel.RWRD = function (UDOD) {
  207. var _UDTD,
  208. _UGE = U.Excel.SY,
  209. _UDE = _UGE["CE"]["RW"],
  210. i = _UDE.length,
  211. _UDRD = $(_UGE["UAE"]["D"] || "#U_E_RWRD"),
  212. _UDFD = $$("frag");
  213. if (_UDRD[0].style.display == "block") { _UDRD[0].style.display = "none"; } //隐藏列表
  214. else {//查看列表
  215. _UDRD[0].innerText = "";
  216. while (i--) {
  217. _UDTD = $$("div", { "className": "U_E_CMOT" + ((!(i % 4) && i != _UDE.length - 2) ? " U_E_CMOO" : ""), "onmousedown": U.M.StopBubble, "onclick": [[U.Excel.SwitchSheetTabs, [i]], [U.Excel.YCCD]] }, _UDFD);
  218. $$("div", { "innerHTML": "工作表" + (i + 1) }, _UDTD);
  219. }
  220. _UDRD.addAttrArray({ "style": { "display": "block", "top": (-(_UDE.length * 30) - 5) + "px", "height": (_UDE.length * 30) + "px"} }); _UDRD[0].appendChild(_UDFD);
  221. }
  222. }
  223. //重新打印表格信息
  224. U.Excel.RefreshTable = function () {
  225. var i,
  226. _UGE = U.Excel.SY,
  227. _UME = _UGE["UAE"],
  228. _UDE = _UGE["CE"]["TF"],
  229. _UAE = [_UME["L"], _UME["H"],
  230. _UME["E"]], _UBE = ["U_E_LB", "U_E_TB", "U_E_TableArea"],
  231. _USE = [["SPTP", 0, "L"], ["SPTP", 1, "T"], ["CBG"]];
  232. for (i = 0; i < _UAE.length; i++) {
  233. _UAE[i].innerText = "";
  234. _UBE[i] = $$("div", { "className": _UBE[i] }, _UAE[i]);
  235. }
  236. _UBE[2].id = _UBE[2].className; //生成查看的元素
  237. for (i = 0; i < _USE.length; i++) {
  238. U.Excel[_USE[i][0]](_UDE[_USE[i][1]] || _UDE, _UBE[i], _USE[i][2]);
  239. } //页面 头部 表格
  240. }
  241. //生成横竖排
  242. U.Excel.SPTP = function (UTF, UDOD, UTP) {
  243. var i, _UDTD,
  244. _UWH = 0,
  245. _UCE = {},
  246. _UDE = U.Excel.SY["CE"][UTP],
  247. _UAE = UTP == "L" ? ["height", U.Excel.SY.Height + "px", "U_E_LBC", "U_E_LBS", "Left"] : ["width", U.Excel.SY.Width + "px", "U_E_TBC", "U_E_TBS", "Top"], _UDFD = $$("frag");
  248. for (i = 0; i < UTF; i++) {
  249. (!_UDE[i]) && (_UCE[_UAE[0]] = _UAE[1], _UDE[i] = { "style": _UCE });
  250. _UWH += parseInt(_UDE[i].style[_UAE[0]]) + 1;
  251. _UDTD = $$("div", {}, _UDFD); $$("div", { "style": _UDE[i]["style"], "innerHTML": i + 1, "className": _UAE[2], "onclick": [[U.Excel.RowsColsOnclick, ["this", UTP, i]]], "oncontextmenu": [[U.M.StopBubble], [U.Excel.RowsColsOnclick, ["this", UTP, i]], [U.Excel.CreateContextMenu, [_UAE[4], i]]] }, _UDTD);
  252. $$("div", { "className": _UAE[3], "onmousedown": [[U.Excel.Draw, ["this", i, UTP]]] }, _UDTD);
  253. }
  254. try {
  255. UDOD.innerText = "";
  256. UDOD.appendChild(_UDFD);
  257. U.Excel.GSPTP(UDOD, UTP, _UWH);
  258. }
  259. catch (e) {
  260. _UDTD = $$("div");
  261. _UDTD.appendChild(_UDFD);
  262. UDOD.innerHTML = _UDTD.innerHTML;
  263. }
  264. return _UWH;
  265. }
  266. //生成表格
  267. U.Excel.CBG = function (UTF, UDOD) {
  268. var i, _UAE,
  269. _UWH = [U.Excel.SY.Height, U.Excel.SY.Width],
  270. _UGE = U.Excel.SY,
  271. _UDSD = $("#UD_SYQEFE")[0],
  272. _UDE = _UGE["CE"]["Cell"],
  273. _UL = _UDE.length ? _UDE.length : (UTF[0] * UTF[1]),
  274. _UDFD = $$("frag");
  275. for (i = 0; i < _UL; i++) {
  276. _UAE = _UDE[i] = _UDE[i] || { "style": { "top": (Math.floor(i / UTF[1])) * (_UWH[0] + 1) + "px", "left": (Math.floor(i % UTF[1])) * (_UWH[1] + 1) + "px", "height": _UWH[0] + "px", "width": _UWH[1] + "px"} };
  277. $$("div", { "innerHTML": (_UAE["innerHTML"] || "").replaceHtmlSign(), "ondblclick": [[U.Excel.EditFrameDoubleClick, [_UDSD]]], "style": _UAE["style"], "onmousedown": [[U.Excel.EditOnmousedown, ["this", i]]], "onmouseover": [[U.M.StopBubble], [U.Excel.CellOnmouseover, ["this", i]]], "oncontextmenu": [[U.M.StopBubble], [U.Excel.CreateContextMenu, ["Cell"]]] }, _UDFD);
  278. }
  279. try {
  280. UDOD.innerText = "";
  281. UDOD.appendChild(_UDFD);
  282. }
  283. catch (e) {
  284. _UAE = $$("div");
  285. _UAE.appendChild(_UDFD);
  286. UDOD.innerHTML = _UTS.innerHTML;
  287. }
  288. }
  289. //设置横竖排的滚动范围
  290. U.Excel.GSPTP = function (UDOD, UTF, UWH) {
  291. var _UTP, _UDTD, _UDSD,
  292. _UCE = { "style": {} },
  293. _UGE = U.Excel.SY,
  294. _UDE = _UGE["UAE"];
  295. if (_UDE) {
  296. _UDTD = _UDE["E"];
  297. _UDSD = _UDE["T"];
  298. _UTP = UTF == "L" ? "height" : "width";
  299. _UDTD.style[_UTP] = UDOD.style[_UTP] = UWH + "px";
  300. _UDSD.style[_UTP] = (UTF == "L" ? UWH + $(_UDSD).Parent().clientHeight - $(UDOD).Parent().clientHeight : UWH + 50) + "px";
  301. }
  302. }
  303. //设置Excel显示长宽
  304. window.onresize = U.Excel.SetWH = function () {
  305. var _UGE = U.Excel.SY["UAE"],
  306. _UDOD = $("body")[0],
  307. _UW = _UDOD.offsetWidth - 50 - (parent.U.D.SY.ET ? parent.U.D.SY.ET.GDTW : 13),
  308. _UH = _UDOD.offsetHeight - 40;
  309. if (_UGE && _UW) {
  310. $("#U_E_Table")[0].style.height = _UH + "px";
  311. $[_UGE["L"], _UGE["F"]].addAttrArray({ "style": { "height": (_UH - 46) + "px"} });
  312. $("#U_E_CCH")[0].style.width = (_UW) + "px";
  313. } //设置office长宽
  314. }
  315. //#endregion
  316. //-----------------------------------------------------------------------------底部任务切换------------------------------------------------------------------
  317. //工作表标签切换
  318. U.Excel.SwitchSheetTabs = function (UIF, UTF) {
  319. var i, _UGE = U.Excel.SY,
  320. _UDE = U.Excel.TF[U.Excel.SY["ID"]],
  321. _UKE = _UGE["CE"]; _UGE["UW"] = window;
  322. if (_UKE["TF"] !== _UDE["TF"][UIF]) {
  323. U.Ut.AddObj(_UKE, { "TF": _UDE["TF"][UIF], "Cell": _UDE["Cell"][UIF], "T": _UDE["T"][UIF], "L": _UDE["L"][UIF] }); //设置当前使用的变量
  324. for (i = 0; i < _UDE["RW"].length; i++) {
  325. _UDE["RW"][i] = (i == UIF);
  326. }; //切换到指定的工作目录
  327. (!UTF) && (U.Excel.CNO());
  328. return _UKE; //加载刷新表格
  329. }
  330. }
  331. //新建文件(新建工作表)
  332. U.Excel.NWWJ = function () {
  333. U.UI.Confirm("是否新建工作表", [U.Excel.NewTZB]);
  334. }
  335. //新建工作表
  336. U.Excel.NewTZB = function () {
  337. var _UGE = U.Excel.SY,
  338. _URE = _UGE["CE"]["RW"],
  339. _UL = _URE.length,
  340. _UDE = U.Excel.TF[U.Excel.SY["ID"]];
  341. _UDE["RW"][_UL] = false;
  342. _UDE["TF"][_UL] = [40, 20];
  343. _UDE["T"][_UL] = [];
  344. _UDE["L"][_UL] = [];
  345. _UDE["Cell"][_UL] = []; //创建新变量
  346. U.Excel.SwitchSheetTabs(_UL); //工作表标签切换
  347. }
  348. //--------------------------------------------------------------------------------保存--------------------------------------------------------------------------------
  349. //关闭保存文件
  350. U.Excel.CSave = function (UFUN) {
  351. if (U.Excel.SY["BC"] && parent.US.userInfo.userid && U.Excel.SY["userid"] == parent.US.userInfo.userid) {
  352. parent.U.UI.Confirm("是否更改保存文件", [U.Excel.Save, [UFUN]], UFUN);
  353. } //关闭判断是否保存文件 && parent.U.Dk.M.ufinfoarray("onefind", U.Excel.TF["ID"]).UsOffice
  354. else {
  355. U.M.apply(this, [UFUN])();
  356. } //关闭
  357. }
  358. //保存
  359. U.Excel.Save = function (UFUN) {
  360. var _UGE = U.Excel.SY;
  361. if (parent.US.userInfo.userid && _UGE["userid"] == parent.US.userInfo.userid) {
  362. return parent.U.Dk.LE.USOS(_UGE["ID"], U.MS.jsonToStr(U.Excel.TF[_UGE["ID"]]), "UE", UFUN);
  363. } //异步获取Excel
  364. else {
  365. parent.U.Alert("拒绝访问该文件");
  366. }
  367. }
  368. //空文件保存异步
  369. U.Excel.YBKWJ = function () {
  370. var _UGE = U.Excel.TF,
  371. _UDE = arguments,
  372. _UCB = _UDE[0];
  373. U.Excel.BLSC(_UDE[1][1].UserDirectoryID, _UGE["ID"]); _UCB(_UDE[1]);
  374. _UGE["ID"] = { "RW": [[]], "TF": [[40, 20]], "Cell": [[]], "L": [[]], "T": [[]] };
  375. U.Excel.SY["BC"] = false;
  376. }
  377. //文件下载成指定的格式
  378. U.Excel.XZZDGS = function () {
  379. top.U.D.Office.ZDGSXZ(U.Excel.TF["ID"], "html", U.Excel);
  380. }
  381. //#region 文件备份
  382. //备份
  383. U.Excel.Backup = function () {
  384. }
  385. //#endregion
  386. //#region
  387. //设置权限
  388. U.Excel.CoEd = function () {
  389. }
  390. //#endregion
  391. //---------------------------------------------------------------------------------功能------------------------------------------------------------------------------
  392. //----------------------------------------------------------------------------------------选择功能---------------------------------------------------------------------
  393. //选中效果
  394. U.Excel.RowsColsOnclick = function (UDOD, UTF, ITF) {
  395. var i, _UDTD, _UDSD, _UST, _UET, _UME,
  396. _UGE = U.Excel.SY,
  397. _UDED = $("div", (_UGE["UAE"]["CE"] || $("#U_E_CCCE")[0])),
  398. _UTL = _UGE["CE"]["TF"],
  399. _UDE = _UGE["CE"]["Cell"],
  400. _UDAD = $("div", $("#U_E_TableArea")[0]);
  401. (!UDOD) && (UDOD = _UDAD[0]);
  402. if (UTF == "D") {//选择区域变化
  403. //选择框大小区域
  404. _UST = _UDE[ITF[1]].style;
  405. _UME = [_UST.left, _UST.top, _UST.width, _UST.height];
  406. for (i = 0; i < _UME.length; i++) {
  407. _UME[i] = parseInt(_UME[i]);
  408. }
  409. _UDTD = UDOD[0] || UDOD;
  410. _UDSD = UDOD.length ? UDOD : [UDOD];
  411. _UME = [[_UDTD.offsetTop, _UDTD.offsetLeft, 2, (_UME[0] + _UME[2] - _UDTD.offsetLeft)], [_UME[1] + _UME[3], _UDTD.offsetLeft, 2, (_UME[0] + _UME[2] - _UDTD.offsetLeft)], [_UDTD.offsetTop, _UDTD.offsetLeft, (_UME[1] + _UME[3] - _UDTD.offsetTop), 2], [_UDTD.offsetTop, (_UME[0] + _UME[2]), (_UME[1] + _UME[3] - _UDTD.offsetTop), 2]]; //线条范围设置
  412. _UDED.addAttrArray({ "style": { "display": "block", "left": (_UME[3][1] - 6) + "px", "top": (_UME[1][0] - 6) + "px"} }, 2); //点的位置确定
  413. for (i = 0; i < _UME.length; i++) {
  414. _UDED.addAttrArray({ "style": { "display": "block", "top": _UME[i][0] + "px", "left": _UME[i][1] + "px", "height": _UME[i][2] + "px", "width": _UME[i][3] + "px"} }, i + 3);
  415. } //设置线条
  416. //设置选择的样式
  417. U.Excel.SetHS(); //清除横竖排效果
  418. U.Excel.SubTS(); //清除表格的样式
  419. U.Excel.ChangeEditFrame(_UDTD); //编辑框的效果
  420. U.Excel.ChangeSelectedCell(_UDSD); //改变选中的单元格的样式
  421. U.Excel.ChangeHL(ITF, UTF); //对应的行列变化
  422. }
  423. else {//设置选择范围
  424. UTF == "L" ? (_UST = _UTL[1] * ITF, _UET = _UST + _UTL[1] - 1) : UTF == "T" ? (_UST = ITF, _UET = ITF + (_UTL[1] * (_UTL[0] - 1))) : (_UST = 0, _UET = (_UTL[1] * _UTL[0]) - 1);
  425. U.Excel.EditOnmousedown(_UDAD[_UST], _UST, true);
  426. U.Excel.CellOnmouseover(_UDAD[_UET], _UET);
  427. _UGE["TD"] = false; //模拟点击 //模拟移动
  428. return;
  429. }
  430. }
  431. //编辑框的效果
  432. U.Excel.ChangeEditFrame = function (UDOD) {
  433. var _UDTD = $(U.Excel.SY["UAE"]["FE"] || "#U_E_EditFrame").addAttrArray({ "style": { "display": "block", "top": UDOD.offsetTop + "px", "left": UDOD.offsetLeft + "px"} }); //编辑框位置
  434. $("div", _UDTD[0]).addAttrArray({ "style": { "backgroundColor": "", "width": (UDOD.offsetWidth - 2) + "px", "height": (UDOD.offsetHeight - 2) + "px"} }); //可编辑大小
  435. }
  436. //改变选中的单元格的样式
  437. U.Excel.ChangeSelectedCell = function (UDOD) {
  438. var i, UST;
  439. if (UDOD && UDOD.length > 0) {
  440. if (U.M.HexBack((UST = UDOD[0].style).backgroundColor) == "#a6ffbf") {
  441. UST.backgroundColor = "";
  442. }
  443. for (i = 1; i < UDOD.length; i++) {
  444. (U.M.HexBack((UST = UDOD[i].style).backgroundColor) != "#a6ffbf") && (UST.backgroundColor = "#a6ffbf");
  445. }
  446. }
  447. }
  448. //清除单元格的样式
  449. U.Excel.SubTS = function () {
  450. var i, _UST,
  451. _UDAD = $("div", $("#U_E_TableArea")[0]),
  452. _UDE = U.Excel.SY["CE"]["Cell"],
  453. _UDSD = $$("div");
  454. for (i = 0; i < _UDAD.length; i++) {
  455. $(_UDSD).addAttrArray(_UDE[i]);
  456. _UST = _UDAD[i].style;
  457. if (_UST.backgroundColor && _UDSD.style.backgroundColor != _UST.backgroundColor) {
  458. _UST.backgroundColor = "";
  459. }
  460. }
  461. }
  462. //对应的行列变化
  463. U.Excel.ChangeHL = function (ITF, UTF) {
  464. var i, j, _UDAD,
  465. _UDE = [],
  466. _UGE = U.Excel.SY,
  467. _UIT = _UGE["CE"]["TF"],
  468. _UDOD = $($(U.Excel.SY["UAE"]["H"] || "#U_E_TitleBar").Child()[0]).Child(),
  469. _UDTD = $($(U.Excel.SY["UAE"]["L"] || "#U_E_LeftLine").Child()[0]).Child();
  470. _UDE = [[ITF[0] % _UIT[1], ITF[1] % _UIT[1], _UDOD], [ITF[0] / _UIT[1], ITF[1] / _UIT[1], _UDTD]]
  471. for (i = 0; i < _UDE.length; i++) {
  472. for (j = Math.floor(_UDE[i][0]); j <= Math.floor(_UDE[i][1]); j++) {
  473. $(_UDE[i][2][j]).Child()[0].style.backgroundColor = "#a6ffbf";
  474. }
  475. } //设置选择的颜色
  476. }
  477. //清理竖排的样式
  478. U.Excel.SetHS = function () {
  479. var i, j, _UTF = "backgroundColor",
  480. _UST, _UDOD,
  481. _UDAD = [$(U.Excel.SY["UAE"]["H"] || "#U_E_TitleBar"),
  482. $(U.Excel.SY["UAE"]["L"] || "#U_E_LeftLine")];
  483. for (i = 0; i < _UDAD.length; i++) {
  484. _UDOD = $(_UDAD[i].Child()[0]).Child();
  485. for (j = 0; j < _UDOD.length; j++) {
  486. _UST = $(_UDOD[j]).Child()[0].style;
  487. (U.M.HexBack(_UST[_UTF]) == "#a6ffbf") && (_UST[_UTF] = "");
  488. }
  489. }
  490. }
  491. //拉伸效果
  492. U.Excel.Draw = function (UDOD, UIF, UTF) {
  493. var _UGE = U.Excel.SY,
  494. _UDPD = $(UDOD).Parent(2),
  495. _UDTD = [_UGE["CE"][UTF][UIF], $("div", UDOD.parentNode)[0]],
  496. _UKE = { "style": {} },
  497. _UE = U.M.GetMousep(),
  498. _UTE = U.M.GetMousep(),
  499. _UDE = U.Excel.GetHSP(UIF, UTF)["Cell"],
  500. _UTP = UTF == "L" ? "height" : "width"; UDOD.setCapture(); //聚焦
  501. document.onmousemove = function () {
  502. var _UXE = U.M.GetMousep(),
  503. _UX = _UXE["X"] - _UE["X"],
  504. _UY = _UXE["Y"] - _UE["Y"];
  505. _UE = _UXE;
  506. _UDPD.style[_UTP] = parseInt(_UDPD.style[_UTP]) + (UTF == "L" ? _UY : _UX) + "px";
  507. _UKE["style"][_UTP] = Math.max(((parseInt(_UDTD[0].style[_UTP]) || 25) + (UTF == "L" ? _UY : _UX)), 0) + "px";
  508. $(_UDTD).addAttrArray(_UKE);
  509. $(_UDE).addAttrArray(_UKE); _UDTD[1].onclick(); //设置变化大小//选中的效果
  510. };
  511. document.onmouseup = function () {
  512. var _UDMD = $("#U_E_TableArea")[0], _UXE = U.M.GetMousep(), _UUE = { "left": (_UXE["X"] - _UTE["X"]), "top": (_UXE["Y"] - _UTE["Y"]) }; //变化的值
  513. U.Excel.GXTS(UIF, UTF, _UUE); //更新数据
  514. _UDMD.innerText = ""; U.Excel.CBG("", _UDMD); //从新刷新表格
  515. _UDTD[1].onclick(); //选中的效果
  516. U.Excel.GSPTP(_UDPD, UTF, parseInt(_UDPD.style[_UTP])); //重设滚动条大小
  517. //释放焦点
  518. UDOD.releaseCapture();
  519. document.onmousemove = document.onmouseup = null
  520. };
  521. }
  522. //获取指定横排 或者是竖排元素
  523. U.Excel.GetHSP = function (ITF, UTF) {
  524. var i,
  525. _UAE = { "Cell": [], "E": [] },
  526. _UGE = U.Excel.SY["CE"],
  527. _UDAD = $("div", $("#U_E_TableArea")[0]),
  528. _UDE = _UGE["Cell"],
  529. _UTL = _UGE["TF"],
  530. _UKE = UTF == "L" ? [_UTL[1] * ITF, _UTL[1] * (ITF + 1), 1] : [ITF, _UTL[1] * _UTL[0], _UTL[1]];
  531. for (i = _UKE[0]; i < _UKE[1]; i += _UKE[2]) {
  532. _UAE["Cell"].push(_UDE[i]);
  533. _UAE["E"].push(_UDAD[i]);
  534. };
  535. return _UAE; //选取横竖排指定的元素
  536. }
  537. //获取除拉伸区域外的元素
  538. U.Excel.GetNHSP = function (ITF, UTF) {
  539. var i,
  540. _UGE = U.Excel.SY["CE"],
  541. _UTL = _UGE["TF"],
  542. _UCE = _UGE["Cell"],
  543. _UDE = { "Cell": [], "E": [] },
  544. _UME = UTF == "L" ? [_UTL[1] * (ITF + 1), -1] : [ITF, ITF];
  545. for (i = _UME[0]; i < _UCE.length; i++) {
  546. if (i % _UTL[1] > _UME[1]) {
  547. _
  548. UDE["Cell"].push(_UCE[i]); _UDE["E"].push(i);
  549. }
  550. }; return _UDE;
  551. }
  552. //更新数据
  553. U.Excel.GXTS = function (ITF, UTF, UDE) {
  554. var i,
  555. _UAE = U.Excel.GetNHSP(ITF, UTF),
  556. _UCE = _UAE["Cell"],
  557. _UTP = UTF == "L" ? "top" : "left";
  558. for (i = 0; i < _UCE.length; i++) {
  559. _UCE[i].style[_UTP] = (parseInt(_UCE[i].style[_UTP]) + UDE[_UTP]) + "px";
  560. } //更新数据
  561. return _UAE;
  562. }
  563. //点击小点拖动
  564. U.Excel.DotOnclick = function () {
  565. var _UGE = U.Excel.SY,
  566. _USE = _UGE["SEO"],
  567. _UKE = _UGE["C"][0],
  568. _UDOD = (U.Excel.SY["UAE"]["FE"] || $("#U_E_EditFrame")[0]),
  569. _UDTD = $("div", _UDOD)[0];
  570. if (_USE[0]) {
  571. U.Excel.EditOnmousedown(_USE[0], _USE[1]); //开始选择多个
  572. (_UKE[_UKE.length - 1]) && (_UKE[_UKE.length - 1].onmouseover()); //移动到选择的位置
  573. document.onmouseup = U.M.apply(this, [[U.Excel.SetWZ, [_USE[0].innerHTML]], [U.Excel.ESF]]); //释放
  574. }
  575. }
  576. //固定区域插入文字
  577. U.Excel.SetWZ = function (UTH) {
  578. var i,
  579. _UGE = U.Excel.SY,
  580. _UDE = _UGE["C"][0],
  581. _UAE = _UGE["C"][1],
  582. _UCE = _UGE["CE"]["Cell"];
  583. $(_UDE).addAttrArray({ "innerHTML": UTH });
  584. for (i = 0; i < _UAE.length; i++) {
  585. _UCE[_UAE[i]].innerHTML = UTH;
  586. } //插入值
  587. }
  588. //#region 移动选择单元格
  589. //点击移动
  590. U.Excel.EditOnmousedown = function (UDOD, UIE, UTF) {
  591. if (UDOD != event) {
  592. var i,
  593. _UDSD = parent.$("#UD_SYQE input")[2],
  594. _URE = U.OU.R,
  595. _UDAD = parent.$("#UD_SYQE input"),
  596. _UGE = U.Excel.SY,
  597. _UDTD = $("div", (_UGE["UAE"]["FE"] || $("#U_E_EditFrame")[0]))[0];
  598. (U.OU.R && !U.OU.TF["FTF"] && U.OU.TF.D) && (U.OU.OUWLJ(_UDSD, "G"));
  599. U.OU.TF["FTF"] = true;
  600. document.body.focus();
  601. (_UDTD.onblur && _UDTD.onblur());
  602. (UDOD) && (_UGE["SEO"] = [UDOD, UIE]); //赋值
  603. if (event && event.keyCode < 2) {//非键盘事件
  604. (!UDOD) && (UDOD = _UGE["SEO"][0], UIE = _UGE["SEO"][1]);
  605. if (event.button != 2 || UTF) {//左键事件触发
  606. _UGE["TD"] = true;
  607. UDOD.onmouseover(); //移动选择
  608. (!document.onmouseup) && (document.onmouseup = U.Excel.ESF); //设置取消
  609. return;
  610. }
  611. }
  612. if (U.Excel.ISROC[UDOD], "D", [UIE]) {
  613. U.Excel.CellOnmouseover(UDOD, UIE, true);
  614. } //判断是否直接切换
  615. }
  616. }
  617. //释放
  618. U.Excel.ESF = function () {
  619. U.Excel.YCCD(); U.Excel.SY["TD"] = false; document.onmouseup = null;
  620. }
  621. //选择多个单元格
  622. U.Excel.CellOnmouseover = function (UDOD, ITF, UTF) {
  623. var _UGE = U.Excel.SY;
  624. if (UTF || (_UGE["SEO"] && _UGE["TD"] && !U.M.onmouseout(UDOD))) {//是否进行拉选范围
  625. var i, _UGE = U.Excel.SY,
  626. _UL = _UGE["CE"]["TF"][1],
  627. _UAE = U.Excel.GetHBTFW(UDOD, ITF),
  628. _UDE = [[], []],
  629. _UDAD = $("div", $("#U_E_TableArea")[0]);
  630. for (i = _UAE[0]; i <= _UAE[1]; i++) {
  631. if ((i % _UL >= _UAE[0] % _UL && i % _UL <= _UAE[1] % _UL)) {
  632. _UDE[0].push(_UDAD[i]);
  633. _UDE[1].push(i);
  634. }
  635. } //获取选择的
  636. U.Excel.RowsColsOnclick(_UDE[0], "D", _UAE); //选择单元格
  637. if (_UGE["SEO"][1] > _UAE[0]) {//编辑框的范围重新选择
  638. if (_UGE["SEO"][0].offsetWidth > 0) {
  639. U.Excel.ChangeEditFrame(_UGE["SEO"][0]); //编辑框的效果
  640. U.Excel.ChangeSelectedCell[_UGE["SEO"][0], _UDE[0][0]]; //改变选中的单元格的样式
  641. }
  642. else {
  643. _UGE["SEO"] = [_UDAD[_UAE[0]], _UAE[0]];
  644. }
  645. }
  646. return (_UGE["C"] = _UDE);
  647. }
  648. }
  649. //获取合并表格在的范围
  650. U.Excel.GetHBTFW = function (UDOD, ITF) {
  651. if (typeof ITF == "number") {
  652. var i, _UST, _UET,
  653. _UGE = U.Excel.SY,
  654. _UL = _UGE["CE"]["TF"][1],
  655. _USL = _UGE["SEO"][1],
  656. _UDE = _UGE["CE"]["Cell"], _UKE = [];
  657. if (_USL % _UL > ITF % _UL) {//左边计算
  658. if (_USL > ITF) {
  659. _UKE[0] = ITF;
  660. _UKE[1] = _USL;
  661. } //下到上
  662. else {
  663. _UKE[0] = (ITF % _UL) + (Math.floor(_USL / _UL) * _UL);
  664. _UKE[1] = (_USL % _UL) + (Math.floor(ITF / _UL) * _UL);
  665. } //上到下
  666. }
  667. else {//右边的计算
  668. if (_USL > ITF) {
  669. _UKE[0] = (_USL % _UL) + (Math.floor(ITF / _UL) * _UL);
  670. _UKE[1] = (ITF % _UL) + (Math.floor(_USL / _UL) * _UL);
  671. } //下到上
  672. else {
  673. _UKE[0] = _USL; _UKE[1] = ITF;
  674. } //上到下
  675. }
  676. for (i = _UKE[0]; i <= _UKE[1]; i++) {//判断是否有合并的单元格 重新计算范围
  677. if ((((_UST = _UDE[i]["Start"]) != null) && (_UET = _UDE[i]["End"])) && (i % _UL >= _UKE[0] % _UL && i % _UL <= _UKE[1] % _UL)) {//范围不在选择的范围 我们重新计算范围
  678. if (_UST % _UL < _UKE[0] % _UL) {
  679. if (_UST < _UKE[0]) {
  680. i = _UKE[0] = _UST;
  681. }
  682. else {
  683. i = _UKE[0] = (Math.floor(_UKE[0] / _UL) * _UL) + (_UST % _UL);
  684. }
  685. }
  686. else if (_UST < _UKE[0]) {
  687. i = _UKE[0] = Math.floor(_UST / _UL) * _UL + (_UKE[0] % _UL);
  688. }
  689. if (_UET % _UL > _UKE[1] % _UL) {
  690. if (_UET > _UKE[1]) {
  691. _UKE[1] = _UET;
  692. }
  693. else { _UKE[1] = (Math.floor(_UKE[1] / _UL) * _UL) + (_UET % _UL); }
  694. }
  695. else if (_UET > _UKE[1]) {
  696. _UKE[1] = (Math.floor(_UET / _UL) * _UL) + (_UKE[1] % _UL);
  697. }
  698. }
  699. }
  700. }
  701. return _UKE;
  702. }
  703. //判断是否变成选中效果
  704. U.Excel.ISROC = function (UDOD, UTF, ITF) {
  705. var i,
  706. _UFT = true,
  707. _UDE = U.Excel.SY["C"];
  708. if (event && event.button == 2 && UTF == "D") {
  709. for (i = 0; i < _UDE[1].length; i++) {
  710. if (_UDE[1][i] == ITF[0]) {
  711. _UFT = !_UFT; break;
  712. }
  713. }
  714. if (_UFT) {
  715. _UDE = [UDOD, ITF];
  716. }
  717. }
  718. return _UFT;
  719. }
  720. //#endregion
  721. //-------------------------------------------------------------------------------------编辑区域-----------------------------------------------------------------------
  722. document.onkeydown = function () {
  723. (event.srcElement.className != "U_E_ASRT") && (U.Excel.Onkeydown());
  724. }
  725. //双击变成可编辑
  726. U.Excel.EditFrameDoubleClick = function (UDOD) {
  727. var _UDTD = U.Excel.SY["SEO"][0],
  728. _UDSD = $("div", UDOD);
  729. _UDSD = _UDSD.addAttrArray({ "onblur": [U.Excel.EditFrameOnblur, ["this", _UDTD]], "onselectstart": null, "contentEditable": "true",
  730. "className": "U_E_CFEO", "style": { "cssText": "", "height": _UDSD[0].style.height, "width": _UDSD[0].style.width }
  731. }, 0)[0]; //设置可编辑
  732. _UDSD.focus();
  733. UDOD.onmousedown = UDOD.ondblclick = null;
  734. U.OU.SCJD(_UDSD, _UDTD.innerHTML, "");
  735. U.Excel.SY["BC"] = true;
  736. _UDTD.innerText = "";
  737. }
  738. //触发编辑应用
  739. U.Excel.Onkeydown = function () {
  740. if (U.Excel.SY["UAE"]) {
  741. var _UDOD = (U.Excel.SY["UAE"]["FE"] || $("#U_E_EditFrame")[0]),
  742. _UDPD = $("div", _UDOD)[0],
  743. _UKC = event.keyCode,
  744. _UKE = { 9: "R", 13: "B", 108: "B", 38: "T", 40: "B", 37: "L", 39: "R" };
  745. if (_UKE[_UKC]) {
  746. U.Excel.Enter(_UKE[_UKC]);
  747. } //移动选择 上下左右 tab enter
  748. else if (_UDPD.contentEditable != "true" && (_UKC == 229 || ((_UKC > 47 && _UKC < 58) || (_UKC > 64 && _UKC < 91)) || ((_UKC > 95 && _UKC < 112) && (_UKC != 100)))) { //输入直接选择
  749. U.Excel.EditFrameDoubleClick(_UDOD);
  750. }
  751. }
  752. }
  753. //单元格换格子事件
  754. U.Excel.Enter = function (UTF, UIT) {
  755. var _UDED,
  756. _UDAD = $("div", $("#U_E_TableArea")[0]),
  757. _UIE = U.Excel.SY["CE"]["TF"];
  758. UIT = UIT || U.Excel.SY["SEO"][1]; //UIT
  759. switch (UTF) {
  760. case "T": (UIT - _UIE[1] >= 0) && (_UDED = _UDAD[UIT - _UIE[1]]);
  761. break; //上
  762. case "L": (UIT - 1 >= Math.floor(UIT / _UIE[1]) * _UIE[1]) && (_UDED = _UDAD[UIT - 1]);
  763. break; //左 _UIE[0] * _UIE[1]
  764. case "B": (UIT + _UIE[1] < _UIE[0] * _UIE[1]) && (_UDED = _UDAD[UIT + _UIE[1]]);
  765. break; //下
  766. case "R": (UIT + 1 < (Math.floor(UIT / _UIE[1]) + 1) * _UIE[1]) && (_UDED = _UDAD[UIT + 1]);
  767. break; //右
  768. }
  769. if (_UDED) { _UDED.onmousedown(); }
  770. }
  771. //编辑框失去焦点
  772. U.Excel.EditFrameOnblur = function (UDOD, UDTD) {
  773. if (UDOD && UDOD != event && (UDOD.contentEditable == "true" || UDOD.innerText != "") && U.OU.TF["FTF"]) { //失去焦点
  774. var _UDS = UDTD.style,
  775. _UDPD = UDOD.parentNode,
  776. _UGE = U.Excel.SY,
  777. _UDE = _UGE["CE"]["Cell"][_UGE["SEO"][1]],
  778. _USE = UDOD.style.cssText;
  779. UDTD = _UGE["SEO"][0] || UDTD;
  780. //编辑成功保存设置
  781. $(UDTD).addAttrArray({ "innerHTML": (_UDE.innerHTML = UDOD.innerHTML), "style": { "cssText": _USE, "height": _UDS.height, "width": _UDS.width, "left": _UDS.left, "top": _UDS.top} }); _UDE.style.cssText = UDTD.style.cssText;
  782. //可编辑区域设置
  783. $(UDOD).addAttrArray({ "contentEditable": "false", "style": { "cssText": "" }, "className": "", "innerHTML": "", "onblur": null, "onselectstart": U.M.StopBubble });
  784. $(_UDPD).addAttrArray({ "ondblclick": [[U.Excel.EditFrameDoubleClick, [_UDPD, true]]], "onmousedown": U.Excel.EditOnmousedown }); //设置点击事件
  785. }
  786. else { } // U.OU.TF["FTF"] = true; U.OU.JDCR();
  787. }
  788. //--------------------------------------------------------------------------------右键菜单功能-----------------------------------------------------------------------
  789. //右键菜单出现和赋值
  790. U.Excel.CreateContextMenu = function (UTF, ITF) {
  791. U.M.StopDefault();
  792. var i, _UH, _UDTD,
  793. _UDSD = $("#UD_SYQET").Parent(),
  794. _UE = U.M.GetMousep(),
  795. _UDOD = $(U.Excel.SY["UAE"]["R"] || "#U_E_ContextMenu"),
  796. _UDFD = $$("frag"), _UKE = U.Excel.SY["RM"],
  797. _UAE = _UKE["MO"],
  798. _UCE = { "Cell": ["SO", "CO"], "CellS": ["SO"], "Left": ["LO"], "Top": ["TO"], "Sheet": "TO"}[UTF];
  799. if (_UCE) {//右键菜单
  800. if (_UCE instanceof Array) {
  801. for (i = 0; i < _UCE.length; i++) {
  802. _UAE = _UAE.concat(_UKE[_UCE[i]]);
  803. }
  804. }
  805. else { _UAE = _UKE[_UCE]; }
  806. }
  807. else { _UAE = _UKE["CO"]; }
  808. for (i = 0; i < _UAE.length; i++) {//生成右键菜单
  809. _UDTD = $$("div", { "className": "U_E_CMO", "style": (!((i + 1) % 4) && i != _UAE.length - 1) ? { "borderBottom": "1px solid #cbcbcb"} : {}, "onmousedown": U.M.StopBubble, "onclick": [[U.Excel.YCCD], [_UAE[i][2], [ITF]]] }, _UDFD);
  810. $$("div", { "innerHTML": _UAE[i][1] }, _UDTD);
  811. }
  812. _UH = _UAE.length * 31;
  813. (UTF == "Sheet") && (_UE = U.M.GetElementAllInfo(event.srcElement), _UE["X"] = _UE["TX"] - 1, _UE["Y"] = _UE["TY"] - _UH);
  814. (_UE["X"] + 100 > _UDSD.offsetWidth) && (_UE["X"] -= 100);
  815. (_UE["Y"] + _UH > _UDSD.offsetHeight) && (_UE["Y"] -= _UH); //位置重新定制
  816. _UDOD[0].innerText = "";
  817. _UDOD[0].appendChild(_UDFD);
  818. _UDOD.addAttrArray({ "style": { "display": "block", "left": _UE["X"] + "px", "top": _UE["Y"] + "px"} }); //弹出右键菜单
  819. }
  820. //合并单元格
  821. U.Excel.MergeCells = function () {
  822. var i, j,
  823. _UGE = U.Excel.SY,
  824. _UDE = _UGE["C"],
  825. _UCE = _UGE["CE"]["Cell"],
  826. _UST = _UDE[1][0],
  827. _UET = _UDE[1][_UDE[1].length - 1],
  828. _UDOD = _UDE[0][0],
  829. _UDTD = _UDE[0][_UDE[0].length - 1],
  830. _UPE = [[_UDTD, "left", "width", "top", "height"], [_UDOD, "left", "top"]];
  831. if (_UDE[0].length > 1) {
  832. for (i = 0; i < _UPE.length; i++) {
  833. for (j = 1; j < _UPE[i].length; j++) {
  834. _UPE[i][j] = parseInt(_UPE[i][0].style[_UPE[i][j]]);
  835. }
  836. }
  837. for (i = 0; i < _UDE[0].length; i++) {
  838. $(_UCE[_UDE[1][i]]).addAttrArray({ "style": { "display": "none" }, "Start": _UST, "End": _UET });
  839. } //设置值
  840. $(_UDE[0]).addAttrArray({ "style": { "display": "none"} }); //设定隐藏合并的范围
  841. $[_UDOD, _UCE[_UDE[1][0]]].addAttrArray({ "style": { "display": "block", "width": _UPE[0][1] + _UPE[0][2] - _UPE[1][1] + "px", "height": _UPE[0][3] + _UPE[0][4] - _UPE[1][2] + "px"} }); //设置可见值
  842. }
  843. U.Excel.EditOnmousedown(_UDE[0][0], _UDE[1][0]);
  844. U.Excel.SY["TD"] = false; //合并后的区域设为可编辑区域
  845. }
  846. //拆分单元格
  847. U.Excel.SplitCell = function () {
  848. var _UGE = U.Excel.SY,
  849. _UDE = _UGE["CE"]["Cell"],
  850. _USE = _UGE["SEO"],
  851. _US = _UDE[_USE[1]]["Start"],
  852. _UE = _UDE[_USE[1]]["End"];
  853. if (_US) {
  854. var i, _UW, _UH,
  855. _UDAD = $("div", $("#U_E_TableArea")[0]),
  856. _UTL = _UGE["CE"]["TF"][1],
  857. _UCE = _UGE["CE"]["Cell"],
  858. _UDOD = $($(U.Excel.SY["UAE"]["H"] || "#U_E_TitleBar").Child()[0]).Child(),
  859. _UDTD = $($(U.Excel.SY["UAE"]["L"] || "#U_E_LeftLine").Child()[0]).Child();
  860. for (i = _US; i <= _UE; i++) { //查封合并的
  861. if (i % _UTL >= _US % _UTL && i % _UTL <= _UE % _UTL) {
  862. if ($(_UDAD[i]).css("width").toInt() > _UDOD[Math.floor(i % _UTL)].offsetWidth) {
  863. $[_UDAD[i], _UCE[i]].css({ "width": _UDOD[Math.floor(i % _UTL)].offsetWidth - 1 + "px", "height": _UDTD[Math.floor(i % _UTL)].offsetHeight - 1 + "px" });
  864. }
  865. $(_UCE[i]).addAttrArray({ "style": { "display": (_UDAD[i].style.display = "block") }, "Start": null, "End": null });
  866. }
  867. }
  868. }
  869. }
  870. //清空内容
  871. U.Excel.EmptyContent = function () {
  872. var i,
  873. _UGE = U.Excel.SY,
  874. _ULE = _UGE["C"][1],
  875. _UDE = _UGE["CE"]["Cell"],
  876. _UDAD = $("div", $("#U_E_TableArea")[0]);
  877. for (i = 0; i < _ULE.length; i++) {
  878. _UDAD[_ULE[i]].innerHTML = _UDE[_ULE[i]].innerHTML = "";
  879. } //清空值
  880. }
  881. //复制
  882. U.Excel.CopyFunction = function () {
  883. var i,
  884. _UGE = U.Excel.SY,
  885. _UKE = _UGE["C"], _UL = _UKE[1],
  886. _UTL = _UGE["CE"]["TF"],
  887. _UCJ = (_UL[_UL.length - 1] - _UL[0]);
  888. _UGE["CP"] = { "Cell": [], "E": _UL, "CJ": [_UCJ % _UTL[1], Math.floor(_UCJ / _UTL[1])], "CI": [_UTL[0], _UTL[1]] };
  889. for (i = 0; i < _UL.length; i++) { _UGE["CP"]["Cell"].push(_UKE[0][i].innerHTML); } //复制值
  890. }
  891. //剪切
  892. U.Excel.Cut = function () {
  893. U.Excel.CopyFunction();
  894. U.Excel.EmptyContent();
  895. }
  896. //粘贴
  897. U.Excel.Paste = function () {
  898. var i, _UXC, _UOI, _UTF,
  899. _UME = [],
  900. _UGE = U.Excel.SY,
  901. _UTL = _UGE["CE"]["TF"],
  902. _UCE = _UGE["CP"],
  903. _UKE = _UGE["C"],
  904. _UTL = _UGE["CE"]["TF"],
  905. _UDAD = $("div", $("#U_E_TableArea")[0]);
  906. if (_UCE["E"].length) {
  907. _UXC = [((_UKE[1][0] % _UTL[1]) + _UCE["CJ"][0]) - _UTL[1] + 1, (Math.floor(_UKE[1][0] / _UTL[1]) + _UCE["CJ"][1] - _UTL[0]) + 1];
  908. for (i = 0; i < _UXC.length; i++) { //扩充横竖排
  909. if (_UXC[i] > 0) {
  910. for (j = 0; j < _UXC[i]; j++) {
  911. U.Excel.InsertRowsCols.apply(this, i ? ["B", [_UTL[1] * (_UTL[0] - 1), _UTL[1] * _UTL[0] - 1], _UTL[0] - 1, true] : ["R", [_UTL[1] - 1, _UTL[1] * _UTL[0] - 1], _UTL[1] - 1, true]);
  912. }
  913. _UTF = true;
  914. }
  915. }
  916. _UOI = (_UKE[1][0] + ((_UTL[1] - _UCE["CI"][1]) * Math.floor(_UKE[1][0] / _UCE["CI"][1]))) - ((Math.floor(_UCE["E"][0] / _UCE["CI"][1]) * _UTL[1]) + (_UCE["E"][0] % _UCE["CI"][1]));
  917. for (i = 0; i < _UCE["E"].length; i++) {
  918. _UME.push(_UOI + (Math.floor(_UCE["E"][i] / _UCE["CI"][1]) * _UTL[1]) + (_UCE["E"][i] % _UCE["CI"][1]));
  919. _UGE["CE"]["Cell"][_UME[_UME.length - 1]].innerHTML = _UCE["Cell"][i];
  920. } //设置粘贴值的位置
  921. if (_UTF) { U.Excel.RefreshTable(); }
  922. else {
  923. for (i = 0; i < _UME.length; i++) {
  924. _UDAD[_UME[i]].innerHTML = _UCE["Cell"][i];
  925. };
  926. } //值变化
  927. U.Excel.EditOnmousedown(_UDAD[_UME[0]], _UME[0]);
  928. U.Excel.CellOnmouseover(_UDAD[_UME[_UME.length - 1]], _UME[_UME.length - 1]);
  929. U.Excel.SY["TD"] = false; U.Excel.YCCD(); //重新聚焦位置
  930. }
  931. }
  932. //插入横竖排
  933. U.Excel.InsertRowsCols = function (UTF, UFW, UIT, UFT) {
  934. var i, j, k, _UTS = {},
  935. _UJE = [],
  936. _UDOD = $($(U.Excel.SY["UAE"]["H"] || "#U_E_TitleBar").Child()[0]).Child(),
  937. _UDTD = $($(U.Excel.SY["UAE"]["L"] || "#U_E_LeftLine").Child()[0]).Child(),
  938. _UGE = U.Excel.SY, _USE = U.Excel.SY["SEO"],
  939. _UTL = _UGE["CE"]["TF"], _UCE = _UGE["CE"]["Cell"];
  940. if ("TB".indexOf(UTF) > -1) {//插入横排
  941. (UFW && !UFW.length) && (UIT = UFW, UFW = null);
  942. UIT = UIT || (_USE[1] / _UTL[1]); UFW = UFW || [UIT * _UTL[1], (UIT + 1) * _UTL[1] - 1];
  943. (UTF == "B" && UIT != (_UTL[0] - 1)) && (UFW[0] += _UTL[1], UFW[1] += _UTL[1], UIT++); //向下插入
  944. for (i = UFW[0]; i <= UFW[1]; i++) {
  945. _UJE.push({ "innerHTML": _UCE[i].innerHTML, "style": { "width": U.Excel.SY.Width + "px", "height": U.Excel.SY.Height + "px", "top": _UCE[i].style.top, "left": _UCE[i].style.left, "display": _UCE[i].style.display || "" }, "End": _UCE[i]["End"], "Start": _UCE[i]["Start"] }); (_UCE[i]["End"]) && (_UTS[_UCE[i]["Start"]] = _UCE[i]["End"]);
  946. } //插入数据
  947. for (i in _UTS) {
  948. if (Math.floor(i / _UTL[1]) == UIT) {
  949. for (j = i % _UTL[1]; j <= _UTS[i] % _UTL[1]; j++) {
  950. $(_UJE[j]).addAttrArray({ "style": { "display": "block" }, "End": null, "Start": null });
  951. }
  952. } //显示
  953. else {
  954. _UCE[i].style.height = parseInt(_UCE[i].style.height) + 31 + "px"; //起始点大小
  955. for (j = i; j < UIT * _UTL[1]; j++) {
  956. if (_UCE[j]["End"] && (j % _UTL[1] >= i % _UTL[1] && j % _UTL[1] <= _UTS[i] % _UTL[1])) {
  957. _UJE[j % _UTL[1]]["End"] = (_UCE[j]["End"] += _UTL[1]);
  958. }
  959. }
  960. } //起始点放大到指定的大小
  961. }
  962. (UIT == (_UTL[1] - 1)) && (UFW[0] += 1); _UTL[0] += 1;
  963. for (i = _UJE.length - 1; i >= 0; i--) { _UCE.splice(UFW[0], 0, _UJE[i]); } //插入
  964. _UJE = U.Excel.GXTS(UIT, "L", { "left": 0, "top": 31 })["Cell"]; //改变变化
  965. for (i = 0; i < _UJE.length; i++) {
  966. if (((j = _UJE[i]["Start"]) != null)) {
  967. (parseInt(j / _UTL[1]) >= UIT) && (_UJE[i]["Start"] += _UTL[1]);
  968. _UJE[i]["End"] += _UTL[1];
  969. }
  970. }
  971. _UGE["CE"]["L"].splice(UIT, 0, { "style": { "height": U.Excel.SY.Height + "px"} }); //添加竖排选择
  972. }
  973. else {
  974. (UFW && !UFW.length) && (UIT = UFW, UFW = null);
  975. UIT = UIT || (_USE[1] % _UTL[1]); UFW = UFW || [UIT, _UTL[0] * _UTL[1]];
  976. (UTF == "R" && UIT != (_UTL[1] - 1)) && (UFW[0] += 1, UIT++);
  977. for (i = UFW[0]; i <= UFW[1]; i += _UTL[1]) {
  978. _UJE.push({ "style": { "width": U.Excel.SY.Width + "px", "height": U.Excel.SY.Height + "px", "top": _UCE[i].style.top, "left": _UCE[i].style.left, "display": _UCE[i].style.display || "" }, "End": _UCE[i]["End"], "Start": _UCE[i]["Start"] }); (_UCE[i]["End"]) && (_UTS[_UCE[i]["Start"]] = _UCE[i]["End"]);
  979. }
  980. for (i in _UTS) {
  981. i = parseInt(i);
  982. if ((i % _UTL[1] == UIT && UTF == "L") || (_UTS[i] % _UTL[1] - 1) == UIT && UTF == "R") { for (j = Math.floor(i / _UTL[1]); j <= (Math.floor(_UTS[i] / _UTL[1]) + 1); j++) { $(_UJE[j]).addAttrArray({ "style": { "display": "block" }, "End": null, "Start": null }); } } // _UJE[j].style.display = "block";
  983. else { _UCE[i].style.width = parseInt(_UCE[i].style.width) + 161 + "px"; } //起始点大小
  984. }
  985. (UIT == (_UTL[1] - 1)) && (UFW[0] += 1); _UTL[1]++;
  986. for (i = UFW[0]; i < _UTL[1] * _UTL[0];
  987. i += _UTL[1]) { _UCE.splice(i, 0, _UJE[Math.floor(i / _UTL[1])]); } //插入
  988. _UJE = U.Excel.GXTS(UIT, "T", { "left": 161, "top": 0 })["Cell"]; //改变变化
  989. for (i = 0; i < _UCE.length; i++) {
  990. if (_UCE[i]["End"]) {
  991. if (_UCE[i]["Start"] >= UIT) {
  992. _UCE[i]["Start"] += (parseInt(_UCE[i]["Start"] / (_UTL[1] - 1)) + ((_UCE[i]["Start"] % (_UTL[1] - 1) >= UIT) ? 1 : 0));
  993. }
  994. if (_UCE[i]["End"] > UIT) {
  995. _UCE[i]["End"] += (parseInt(_UCE[i]["End"] / (_UTL[1] - 1)) + ((_UCE[i]["End"] % (_UTL[1] - 1) < UIT) ? 0 : 1));
  996. }
  997. }
  998. }
  999. _UGE["CE"]["T"].splice(UIT, 0, { "style": { "width": "160px"} }); //添加竖排选择
  1000. }
  1001. (!UFT) && (U.Excel.RefreshTable(), (("TB".indexOf(UTF) > -1) ? _UDTD : _UDOD)[UIT].onclick()); //更新
  1002. }
  1003. //删除行
  1004. U.Excel.DeleteRowsCols = function (UTF, ITF) {
  1005. var i, _UST, _UET, _UDE,
  1006. _UGE = U.Excel.SY,
  1007. _UCE = _UGE["CE"],
  1008. _UTL = _UCE["TF"],
  1009. _UKE = _UCE["Cell"];
  1010. if (UTF == "L") {//行删除
  1011. _UDE = _UKE.splice(ITF * _UTL[1], _UTL[1]); //删除的表格数据
  1012. for (i = 0; i < _UDE.length; i++) {
  1013. if ((_UET = _UDE[i]["End"])) {
  1014. if (Math.floor((_UST = _UDE[i]["Start"]) / _UTL[1]) == ITF && Math.floor(_UET / _UTL[1]) > ITF) {
  1015. $(_UKE[_UST]).addAttrArray({ "style": { "width": _UDE[i].style.width, "height": parseInt(_UDE[i].style.height) - parseInt(_UCE["L"][ITF].style.height) - 1 + "px", "display": "block" }, "innerHTML": _UDE[i].innerHTML || "" });
  1016. } //重新设置
  1017. else if (Math.floor(_UST / _UTL[1]) != ITF && Math.floor(_UET / _UTL[1]) >= ITF) {
  1018. $(_UKE[_UST]).addAttrArray({ "style": { "height": parseInt(_UKE[_UST].style.height) - (parseInt(_UCE["L"][ITF].style.height) || U.Excel.SY.Height) - 1 + "px"} });
  1019. } //设置
  1020. i = _UET % _UTL[1];
  1021. }
  1022. }
  1023. U.Excel.GXTS(ITF - 1, UTF, { "top": -(parseInt(_UCE["L"][ITF].style.height) + 1), "left": 0 }); //删除后的修改
  1024. _UCE["L"].splice(ITF, 1); _UTL[0]--; //删除列的信息
  1025. for (i = 0; i < _UKE.length; i++) { //解决位置变化后的合并的起始结束的问题
  1026. if ((_UET = _UKE[i]["End"])) {
  1027. if (Math.floor((_UST = _UKE[i]["Start"]) / _UTL[1]) > ITF) {
  1028. _UKE[i]["Start"] -= _UTL[1];
  1029. }
  1030. _UKE[i]["End"] -= _UTL[1];
  1031. }
  1032. }
  1033. }
  1034. else {//列删除
  1035. _UDE = [];
  1036. for (i = 0; i < _UTL[0]; i++) {
  1037. _UDE.push(_UKE.splice(ITF + (i * _UTL[1]) - i, 1)[0]);
  1038. } //删除表格的值
  1039. for (i = 0; i < _UDE.length; i++) {
  1040. if ((_UET = _UDE[i]["End"])) {
  1041. if ((_UST = _UDE[i]["Start"]) % _UTL[1] == ITF && _UET % _UTL[1] > ITF) {
  1042. $(_UKE[_UST - Math.floor(_UST / _UTL[1])]).addAttrArray({ "style": { "width": parseInt(_UDE[i].style.width) - parseInt(_UCE["T"][ITF].style.width) - 1 + "px", "height": _UDE[i].style.height, "display": "block" }, "innerHTML": _UDE[i].innerHTML || "" });
  1043. }
  1044. else if (_UST % _UTL[1] != ITF && _UET % _UTL[1] >= ITF) {
  1045. $(_UKE[_UST - Math.floor(_UST / _UTL[1])]).addAttrArray({ "style": { "width": parseInt(_UKE[_UST - Math.floor(_UST / _UTL[1])].style.width) - (parseInt(_UCE["L"][ITF].style.width) || 160) - 1 + "px"} });
  1046. }
  1047. i = Math.floor(_UET / _UTL[1]);
  1048. }
  1049. }
  1050. _UCE["T"].splice(ITF, 1);
  1051. _UTL[1]--; //删除列的信息
  1052. U.Excel.GXTS(ITF - 1, UTF, { "top": 0, "left": -(parseInt(_UCE["T"][ITF].style.width) + 1) }); //删除后的修改
  1053. for (i = 0; i < _UKE.length; i++) { //解决位置变化后的合并的起始结束的问题
  1054. if ((_UET = _UKE[i]["End"])) {
  1055. _UKE[i]["Start"] -= parseInt(_UKE[i]["Start"] / (_UTL[1] + 1));
  1056. _UKE[i]["End"] -= (parseInt(_UET / (_UTL[1] + 1)) + 1);
  1057. }
  1058. }
  1059. }
  1060. U.Excel.RefreshTable(); //从新刷新表格
  1061. }
  1062. //删除工作页
  1063. U.Excel.DelectSheet = function () {
  1064. var i, j,
  1065. _UGE = U.Excel.TF[U.Excel.SY["ID"]],
  1066. _UDE = U.Excel.SY["CE"];
  1067. if (_UGE.length != 1) {//工作页要大于一
  1068. for (i = 0; i < _UGE.length; i++) {
  1069. if (_UGE[i]["Cell"] == _UDE["Cell"]) {
  1070. for (j in _UDE) { _UGE[i][j].splice(i, 1); }
  1071. } //移除工作表变量
  1072. }
  1073. U.Excel.SwitchSheetTabs(i - 1 < 0 ? 0 : i - 1); //切换到指定
  1074. }
  1075. }
  1076. //隐藏菜单
  1077. U.Excel.YCCD = function () {
  1078. var i, _UGE = U.Excel.SY["UAE"],
  1079. _UDE = [["D", "U_E_RWRD"], ["R", "U_E_ContextMenu"]];
  1080. U.OU.SDYC(null, true); //隐藏默认的菜单
  1081. for (i = 0; i < _UDE.length; i++) {
  1082. (_UGE[_UDE[i][0]] || $("#" + _UDE[i][1])).style.display = "none";
  1083. } //隐藏Excel菜单
  1084. }
  1085. //---------------------------------------------------------------------------------滚动条功能-------------------------------------------------------------------------
  1086. //滚动条
  1087. U.Excel.BS = function (UDOD) {
  1088. var _UGE = U.Excel.SY["UAE"],
  1089. _UT = UDOD.scrollTop,
  1090. _UL = UDOD.scrollLeft,
  1091. _UDTD = _UGE["F"] || $("#U_E_CellF")[0],
  1092. _UDSD = _UGE["L"] || $("#U_E_LeftLine")[0],
  1093. _UDMD = _UGE["H"] || $("#U_E_TitleBar")[0];
  1094. if (_UT - _UDTD.scrollTop) {
  1095. _UDTD.scrollTop = _UT; _UDSD.scrollTop = _UDTD.scrollTop;
  1096. } //滚动表和左边的变化
  1097. if (_UL - _UDTD.scrollLeft) {
  1098. _UDTD.scrollLeft = _UL; _UDMD.scrollLeft = _UDTD.scrollLeft;
  1099. } //滚动表头部的变化
  1100. }
  1101. //滚动条变化
  1102. U.Excel.GBH = function () {
  1103. var _UW = event.wheelDelta,
  1104. _UWD = _UW ? (_UW / 120) : (-event.detail / 3);
  1105. $(U.Excel.SY["UAE"]["T"] || "#U_E_CB").Parent().scrollTop -= _UWD * 50;
  1106. }
  1107. window.onerror = function () { return true; }
  1108. document.oncontextmenu = U.M.StopDefault;