excel.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html dir="ltr" mozdisallowselectionprint>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>预览excel</title>
  6. <link rel='stylesheet' href='./excel/pluginsCss.css' />
  7. <link rel='stylesheet' href='./excel/plugins.css' />
  8. <link rel='stylesheet' href='./excel/luckysheet.css' />
  9. <link rel='stylesheet' href='./excel/iconfont.css' />
  10. <script src="./utils/flexible.js"></script>
  11. <script src="./utils/getQueryVariable.js"></script>
  12. <script src="./excel/plugin.js"></script>
  13. <script src="./excel/luckysheet.umd.js"></script>
  14. <script src="./excel/luckyexcel.umd.js"></script>
  15. <link rel="resource" type="application/l10n" href="./excel/viewer.properties" />
  16. </head>
  17. <style type="text/css">
  18. *{padding: 0;margin: 0;}
  19. body {
  20. height: 100vh;
  21. width: 100vw;
  22. }
  23. #container {
  24. width: 100%;
  25. height: calc(100% - 10px);
  26. font-size: 18px;
  27. }
  28. .luckysheet-sta-c {
  29. /* display: flex; */
  30. }
  31. /* .luckysheet-sta-c {
  32. height: 0.77rem;
  33. }
  34. .luckysheet-zoom-content {
  35. width: 4rem;
  36. height: 0.77rem;
  37. line-height: 0.77rem;
  38. }
  39. .luckysheet-zoom-content .luckysheet-zoom-minus-icon {
  40. width: 0.4rem;
  41. height: 0.08rem;
  42. }
  43. .luckysheet-zoom-content .luckysheet-zoom-plus .luckysheet-zoom-plus-icon {
  44. width: 0.4rem;
  45. height: 0.4rem;
  46. }
  47. .luckysheet-zoom-content .luckysheet-zoom-slider {
  48. width: 1.8rem;
  49. left: 0.5rem;
  50. } */
  51. </style>
  52. <script>
  53. (async function () {
  54. const fileUrl = decodeURIComponent(getQueryVariable('file') || '')
  55. console.log('excel', fileUrl)
  56. LuckyExcel.transformExcelToLuckyByUrl(fileUrl, '测试.xlsl', (exportJson, luckysheetfile) => {
  57. if (exportJson.sheets == null || exportJson.sheets.length === 0) {
  58. console.warn('暂不支持该文件预览')
  59. return
  60. }
  61. const safeBottom = getQueryVariable('safeBottom')
  62. document.getElementById('container').style.height = `calc(100% - ${safeBottom}px)`
  63. const firstData = []
  64. const secondData = {}
  65. for (let i = 0; i < exportJson.sheets.length; i++) {
  66. firstData[i] = {
  67. name: exportJson.sheets[i].name,
  68. index: exportJson.sheets[i].index,
  69. order: exportJson.sheets[i].order,
  70. status: exportJson.sheets[i].status,
  71. config: exportJson.sheets[i].config,
  72. }
  73. firstData[i].config.row = 10
  74. parseInt(exportJson.sheets[i].status) === 1 ? (firstData[i].celldata = exportJson.sheets[i].celldata) : 0 == 0
  75. secondData[exportJson.sheets[i].index] = exportJson.sheets[i].celldata
  76. }
  77. // luckysheet生成网页excel
  78. window?.luckysheet.destroy()
  79. window?.luckysheet.create({
  80. lang: 'zh',
  81. container: 'container', // 设定DOM容器的id
  82. allowUpdate: true,
  83. showtoolbar: false, // 是否显示工具栏
  84. showinfobar: false, // 是否显示顶部信息栏
  85. showstatisticBar: true, // 是否显示底部计数栏
  86. sheetBottomConfig: false, // sheet页下方的添加行按钮和回到顶部按钮配置
  87. allowEdit: false, // 是否允许前台编辑
  88. enableAddRow: false, // 是否允许增加行
  89. enableAddCol: false, // 是否允许增加列
  90. sheetFormulaBar: false, // 是否显示公式栏
  91. data: exportJson.sheets, //表格内容
  92. enableAddBackTop: true, //返回顶部
  93. title: exportJson.info.name, //表格标题
  94. sheetRightClickConfig: {
  95. delete: false, // 删除
  96. copy: false, // 复制
  97. rename: false, //重命名
  98. color: false, //更改颜色
  99. hide: false, //隐藏,取消隐藏
  100. move: false, //向左移,向右移
  101. },
  102. showsheetbarConfig: {
  103. add: false,
  104. },
  105. devicePixelRatio: window.devicePixelRatio, //分辨率
  106. defaultFontSize: 20, //默认字体大小
  107. cellRightClickConfig: {
  108. copy: false, // 复制
  109. copyAs: false, // 复制为
  110. paste: false, // 粘贴
  111. insertRow: false, // 插入行
  112. insertColumn: false, // 插入列
  113. deleteRow: false, // 删除选中行
  114. deleteColumn: false, // 删除选中列
  115. deleteCell: false, // 删除单元格
  116. hideRow: false, // 隐藏选中行和显示选中行
  117. hideColumn: false, // 隐藏选中列和显示选中列
  118. rowHeight: false, // 行高
  119. columnWidth: false, // 列宽
  120. clear: false, // 清除内容
  121. matrix: false, // 矩阵操作选区
  122. sort: false, // 排序选区
  123. filter: false, // 筛选选区
  124. chart: false, // 图表生成
  125. image: false, // 插入图片
  126. link: false, // 插入链接
  127. data: false, // 数据验证
  128. cellFormat: false, // 设置单元格格式
  129. },
  130. })
  131. })
  132. }())
  133. </script>
  134. <body id="body">
  135. <div id="container"></div>
  136. </body>
  137. </html>