当前位置:   article > 正文

开源在线excel展示插件 js excel 在线插件 合并单元格 设置单元格样式 编辑工具_js在线表格插件

js在线表格插件

 源码:https://github.com/yufb12/dataexcel.git

在线预览地地址 http://www.dataexcel.cn/dataexceljs.html

1、js 版本 es6

 2、绘图引擎 zrender 地址  ZRender 文档 (ecomfe.github.io)

 3、 文件保存格式json 

4、创建并初始化

  1. <div id="maingrid" style="position: static; width: 100%; height: 100%; box-sizing: border-box ">
  2. <div id="grid" style="position: relative; width: 1200px; height: 600px; "> </div>
  3. </div>

  1. <script type="text/javascript">
  2. var domgrid = document.getElementById("grid");
  3. var input = document.getElementById("maininput");
  4. var grid = new DataExcel();
  5. grid.Width = domgrid.Width;
  6. grid.Height = domgrid.Height;
  7. grid.InitDom(domgrid);
  8. grid.InitEdit(input);
  9. grid.Refresh();
  10. grid.Paint();
  11. grid.On(Events.FocusedCellChanged, FocusedCellChanged);
  12. function FocusedCellChanged(args)
  13. {
  14. console.log("事件触发测试:" + args);
  15. }
  16. </script>

 5、文件 新建保存

  1. <!--File-->
  2. <script type="text/javascript">
  3. function New()
  4. {
  5. grid.Clear();
  6. grid.VScroll.Visible = true;
  7. grid.HScroll.Visible = true;
  8. grid.Refresh();
  9. grid.RePaint();
  10. }
  11. function Open()
  12. {
  13. let inputObj = document.createElement('input')
  14. inputObj.setAttribute('id', '_ef');
  15. inputObj.setAttribute('type', 'file');
  16. inputObj.setAttribute("style", 'visibility:hidden');
  17. document.body.appendChild(inputObj);
  18. inputObj.addEventListener("change", fileopen)
  19. //inputObj. = fileopen()
  20. inputObj.click();
  21. }
  22. function fileopen(e)
  23. {
  24. let inputObj = e.target;
  25. let file = inputObj.files[0];
  26. console.log(file);
  27. grid.OpenFile(file);
  28. document.body.removeChild(inputObj);
  29. grid.Refresh();
  30. grid.RePaint();
  31. }
  32. function Save()
  33. {
  34. //let domfile = document.getElementById("file");
  35. let content = JSON.stringify(grid.GetData());
  36. //domfile.innerText = content;
  37. let fileName = "grid.json";
  38. let downLink = document.createElement('a')
  39. downLink.download = fileName
  40. let blob = new Blob([content], { type: 'text/json' })
  41. downLink.href = URL.createObjectURL(blob)
  42. document.body.appendChild(downLink)
  43. downLink.click()
  44. document.body.removeChild(downLink)
  45. }
  46. function OpenDialogSize()
  47. {
  48. //let dialog = document.getElementById("modaldomwidthheight");
  49. //dialog.modal({
  50. // keyboard: false
  51. //});
  52. let domwidth = document.getElementById("gridwidth");
  53. let width = grid.Width;
  54. let domheight = document.getElementById("gridheight");
  55. let height = grid.Height;
  56. domwidth.value = width;
  57. domheight.value = height;
  58. $('#modaldomwidthheight').modal({
  59. keyboard: false
  60. })
  61. }
  62. function SaveGridSize()
  63. {
  64. let domwidth = document.getElementById("gridwidth");
  65. let width = Number(domwidth.value);
  66. let domheight = document.getElementById("gridheight");
  67. let height = Number(domheight.value);
  68. grid.SetSize(width, height);
  69. grid.Refresh();
  70. grid.RePaint();
  71. }
  72. function Preview()
  73. {
  74. let key = (Math.round(Math.random() * 65536)).toString(16) +
  75. (Math.round(Math.random() * 65536)).toString(16) +
  76. (Math.round(Math.random() * 65536)).toString(16) +
  77. (Math.round(Math.random() * 65536)).toString(16) +
  78. (Math.round(Math.random() * 65536)).toString(16);
  79. let arg = "?k=" + key + "&zoom=true";
  80. let content = JSON.stringify(grid.GetData());
  81. localStorage.setItem(key, content);
  82. window.open("demo.html" + arg);
  83. }
  84. function Scale()
  85. {
  86. var zw = 0.7;
  87. var zh = 0.7;
  88. document.body.style.transformOrigin = '0 0';
  89. document.body.style.transform = 'scale(' + zw + ',' + zh + ')';
  90. document.body.style.width = window.innerWidth / zw + 'px';
  91. document.body.style.height = window.innerHeight / zh + 'px';
  92. grid.SetSize(grid.Width, grid.Height);
  93. grid.Refresh();
  94. grid.Paint();
  95. }
  96. function Restore()
  97. {
  98. var zw = 1;
  99. var zh = 1;
  100. document.body.style.transformOrigin = '0 0';
  101. document.body.style.transform = 'scale(' + zw + ',' + zh + ')';
  102. document.body.style.width = window.innerWidth / zw + 'px';
  103. document.body.style.height = window.innerHeight / zh + 'px';
  104. grid.SetSize(grid.Width, grid.Height);
  105. grid.Refresh();
  106. grid.Paint();
  107. }
  108. function ReadOnly()
  109. {
  110. grid.ReadOnly = CheckState.Check;
  111. grid.Refresh();
  112. grid.RePaint();
  113. }
  114. function UnReadOnly()
  115. {
  116. grid.ReadOnly = CheckState.UnCheck;
  117. grid.Refresh();
  118. grid.RePaint();
  119. }
  120. </script>

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号