kailing
1 year ago
committed by
Gitee
11 changed files with 6537 additions and 1 deletions
After Width: | Height: | Size: 20 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,71 @@
|
||||
function isUTF8(bytes) { |
||||
var i = 0; |
||||
while (i < bytes.length) { |
||||
if ((// ASCII
|
||||
bytes[i] == 0x09 || |
||||
bytes[i] == 0x0A || |
||||
bytes[i] == 0x0D || |
||||
(0x20 <= bytes[i] && bytes[i] <= 0x7E) |
||||
) |
||||
) { |
||||
i += 1; |
||||
continue; |
||||
} |
||||
|
||||
if ((// non-overlong 2-byte
|
||||
(0xC2 <= bytes[i] && bytes[i] <= 0xDF) && |
||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) |
||||
) |
||||
) { |
||||
i += 2; |
||||
continue; |
||||
} |
||||
|
||||
if ((// excluding overlongs
|
||||
bytes[i] == 0xE0 && |
||||
(0xA0 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) |
||||
) || |
||||
(// straight 3-byte
|
||||
((0xE1 <= bytes[i] && bytes[i] <= 0xEC) || |
||||
bytes[i] == 0xEE || |
||||
bytes[i] == 0xEF) && |
||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) |
||||
) || |
||||
(// excluding surrogates
|
||||
bytes[i] == 0xED && |
||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x9F) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) |
||||
) |
||||
) { |
||||
i += 3; |
||||
continue; |
||||
} |
||||
|
||||
if ((// planes 1-3
|
||||
bytes[i] == 0xF0 && |
||||
(0x90 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && |
||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) |
||||
) || |
||||
(// planes 4-15
|
||||
(0xF1 <= bytes[i] && bytes[i] <= 0xF3) && |
||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0xBF) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && |
||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) |
||||
) || |
||||
(// plane 16
|
||||
bytes[i] == 0xF4 && |
||||
(0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x8F) && |
||||
(0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xBF) && |
||||
(0x80 <= bytes[i + 3] && bytes[i + 3] <= 0xBF) |
||||
) |
||||
) { |
||||
i += 4; |
||||
continue; |
||||
} |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
function stox(wb){var out=[];wb.SheetNames.forEach(function(name){var o={name:name,rows:{}};var ws=wb.Sheets[name];if(!ws||!ws["!ref"])return;var range=XLSX.utils.decode_range(ws["!ref"]);range.s={r:0,c:0};var aoa=XLSX.utils.sheet_to_json(ws,{raw:false,header:1,range:range});aoa.forEach(function(r,i){var cells={};r.forEach(function(c,j){cells[j]={text:c};var cellRef=XLSX.utils.encode_cell({r:i,c:j});if(ws[cellRef]!=null&&ws[cellRef].f!=null){cells[j].text="="+ws[cellRef].f}});o.rows[i]={cells:cells}});o.merges=[];(ws["!merges"]||[]).forEach(function(merge,i){if(o.rows[merge.s.r]==null){o.rows[merge.s.r]={cells:{}}}if(o.rows[merge.s.r].cells[merge.s.c]==null){o.rows[merge.s.r].cells[merge.s.c]={}}o.rows[merge.s.r].cells[merge.s.c].merge=[merge.e.r-merge.s.r,merge.e.c-merge.s.c];o.merges[i]=XLSX.utils.encode_range(merge)});out.push(o)});return out}function xtos(sdata){var out=XLSX.utils.book_new();sdata.forEach(function(xws){var ws={};var rowobj=xws.rows;var minCoord={r:0,c:0},maxCoord={r:0,c:0};for(var ri=0;ri<rowobj.len;++ri){var row=rowobj[ri];if(!row)continue;Object.keys(row.cells).forEach(function(k){var idx=+k;if(isNaN(idx))return;var lastRef=XLSX.utils.encode_cell({r:ri,c:idx});if(ri>maxCoord.r)maxCoord.r=ri;if(idx>maxCoord.c)maxCoord.c=idx;var cellText=row.cells[k].text,type="s";if(!cellText){cellText="";type="z"}else if(!isNaN(Number(cellText))){cellText=Number(cellText);type="n"}else if(cellText.toLowerCase()==="true"||cellText.toLowerCase()==="false"){cellText=Boolean(cellText);type="b"}ws[lastRef]={v:cellText,t:type};if(type=="s"&&cellText[0]=="="){ws[lastRef].f=cellText.slice(1)}if(row.cells[k].merge!=null){if(ws["!merges"]==null)ws["!merges"]=[];ws["!merges"].push({s:{r:ri,c:idx},e:{r:ri+row.cells[k].merge[0],c:idx+row.cells[k].merge[1]}})}})}ws["!ref"]=minCoord?XLSX.utils.encode_range({s:minCoord,e:maxCoord}):"A1";XLSX.utils.book_append_sheet(out,ws,xws.name)});return out} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}({3:function(e,t,n){"use strict";n.r(t);const r={toolbar:{undo:"撤销",redo:"恢复",print:"打印",paintformat:"格式刷",clearformat:"清除格式",format:"数据格式",fontName:"字体",fontSize:"字号",fontBold:"加粗",fontItalic:"倾斜",underline:"下划线",strike:"删除线",color:"字体颜色",bgcolor:"填充颜色",border:"边框",merge:"合并单元格",align:"水平对齐",valign:"垂直对齐",textwrap:"自动换行",freeze:"冻结",autofilter:"自动筛选",formula:"函数",more:"更多"},contextmenu:{copy:"复制",cut:"剪切",paste:"粘贴",pasteValue:"粘贴数据",pasteFormat:"粘贴格式",hide:"隐藏",insertRow:"插入行",insertColumn:"插入列",deleteSheet:"删除",deleteRow:"删除行",deleteColumn:"删除列",deleteCell:"删除",deleteCellText:"删除数据",validation:"数据验证",cellprintable:"可打印",cellnonprintable:"不可打印",celleditable:"可编辑",cellnoneditable:"不可编辑"},print:{size:"纸张大小",orientation:"方向",orientations:["横向","纵向"]},format:{normal:"正常",text:"文本",number:"数值",percent:"百分比",rmb:"人民币",usd:"美元",eur:"欧元",date:"短日期",time:"时间",datetime:"长日期",duration:"持续时间"},formula:{sum:"求和",average:"求平均值",max:"求最大值",min:"求最小值",concat:"字符拼接",_if:"条件判断",and:"和",or:"或"},validation:{required:"此值必填",notMatch:"此值不匹配验证规则",between:"此值应在 {} 和 {} 之间",notBetween:"此值不应在 {} 和 {} 之间",notIn:"此值不在列表中",equal:"此值应该等于 {}",notEqual:"此值不应该等于 {}",lessThan:"此值应该小于 {}",lessThanEqual:"此值应该小于等于 {}",greaterThan:"此值应该大于 {}",greaterThanEqual:"此值应该大于等于 {}"},error:{pasteForMergedCell:"无法对合并的单元格执行此操作"},calendar:{weeks:["日","一","二","三","四","五","六"],months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]},button:{next:"下一步",cancel:"取消",remove:"删除",save:"保存",ok:"确认"},sort:{desc:"降序",asc:"升序"},filter:{empty:"空白"},dataValidation:{mode:"模式",range:"单元区间",criteria:"条件",modeType:{cell:"单元格",column:"列模式",row:"行模式"},type:{list:"列表",number:"数字",date:"日期",phone:"手机号",email:"电子邮件"},operator:{be:"在区间",nbe:"不在区间",lt:"小于",lte:"小于等于",gt:"大于",gte:"大于等于",eq:"等于",neq:"不等于"}}};window&&window.x_spreadsheet&&(window.x_spreadsheet.$messages=window.x_spreadsheet.$messages||{},window.x_spreadsheet.$messages["zh-cn"]=r),t.default=r}}); |
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="UTF-8" /> |
||||
<title>${file.name}预览</title> |
||||
<#include "*/commonHeader.ftl"> |
||||
<link rel="stylesheet" href="xspreadsheet/xspreadsheet.css"/> |
||||
<script src="xspreadsheet/xspreadsheet.js"></script> |
||||
<script src="xspreadsheet/is-utf8.js"></script> |
||||
<script src="xspreadsheet/xlsx.full.min.js"></script> |
||||
<script src="xspreadsheet/xlsxspread.min.js"></script> |
||||
<script src="xspreadsheet/cptable.full.js"></script> |
||||
<script src="xspreadsheet/zh-cn.js"></script> |
||||
<script src="js/base64.min.js" type="text/javascript"></script> |
||||
</head> |
||||
<#if csvUrl?contains("http://") || csvUrl?contains("https://")> |
||||
<#assign finalUrl="${csvUrl}"> |
||||
<#elseif csvUrl?contains("ftp://") > |
||||
<#assign finalUrl="${csvUrl}"> |
||||
<#else> |
||||
<#assign finalUrl="${baseUrl}${csvUrl}"> |
||||
</#if> |
||||
<body> |
||||
<div id="htmlout"></div> |
||||
<script> |
||||
x_spreadsheet.locale('zh-cn'); |
||||
var HTMLOUT = document.getElementById('htmlout'); |
||||
var xspr = x_spreadsheet(HTMLOUT); |
||||
HTMLOUT.style.height = (window.innerHeight - 400) + "px"; |
||||
HTMLOUT.style.width = (window.innerWidth - 50) + "px"; |
||||
|
||||
var process_wb = (function() { |
||||
return function process_wb(wb) { |
||||
var data = stox(wb); |
||||
xspr.loadData(data); |
||||
if(typeof console !== 'undefined') console.log("output", new Date()); |
||||
}; |
||||
})(); |
||||
var url = '${finalUrl}'; |
||||
var baseUrl = '${baseUrl}'.endsWith('/') ? '${baseUrl}' : '${baseUrl}' + '/'; |
||||
if (!url.startsWith(baseUrl)) { |
||||
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url)); |
||||
} |
||||
let xhr = new XMLHttpRequest(); |
||||
xhr.open('GET',url); //文件所在地址
|
||||
xhr.responseType = 'blob'; |
||||
xhr.onload = () => { |
||||
let content = xhr.response; |
||||
let blob = new Blob([content]); |
||||
let file = new File([blob],'excel.csv',{ type: 'excel/csv' }); |
||||
var reader = new FileReader(); |
||||
reader.onload = function(e) { |
||||
if(typeof console !== 'undefined') console.log("onload", new Date()); |
||||
var data = e.target.result; |
||||
data = new Uint8Array(data); |
||||
let f = isUTF8(data); |
||||
if (f) { |
||||
var str = cptable.utils.decode(65001, data); |
||||
process_wb(XLSX.read(str, { type: "string" })); |
||||
} else { |
||||
var str = cptable.utils.decode(936, data); |
||||
process_wb(XLSX.read(str, { type: "string" })); |
||||
} |
||||
}; |
||||
reader.readAsArrayBuffer(file); |
||||
} |
||||
xhr.send(); |
||||
/*初始化水印*/ |
||||
if (!!window.ActiveXObject || "ActiveXObject" in window) |
||||
{ |
||||
}else{ |
||||
initWaterMark(); |
||||
} |
||||
</script> |
||||
|
||||
</body> |
||||
</html> |
Loading…
Reference in new issue