excel.js 824 B

1234567891011121314151617181920212223242526272829303132333435
  1. layui.define([], function (exports) {
  2. var MOD_NAME = 'excel';
  3. var modFile = layui.cache.modules['excel'];
  4. var modPath = modFile.substr(0, modFile.lastIndexOf('.'));
  5. var settings = {
  6. name: '表格'
  7. };
  8. var excel = {
  9. init: function (tableId, options) {
  10. loadScript();
  11. var opts = $.extend({}, settings, options);
  12. $('#'+tableId).table2excel({
  13. name: opts.name,
  14. filename: opts.name + new Date().getTime() + ".xls",
  15. exclude: ".noExl",
  16. exclude_img: false,
  17. exclude_links: false,
  18. exclude_inputs: false,
  19. preserveColors:true
  20. });
  21. }
  22. }
  23. function loadScript() {
  24. if (typeof table2excel == 'undefined') {
  25. $.ajax({ //获取插件
  26. url: modPath + '/table2excel.js' ,
  27. dataType: 'script',
  28. cache: true,
  29. async: false
  30. });
  31. }
  32. }
  33. loadScript();
  34. exports(MOD_NAME, excel);
  35. });