修复前端解析csv 某些文件解码错误问题

修复前端解析csv 某些文件解码错误问题

Signed-off-by: 高雄 <admin@cxcp.com>
This commit is contained in:
高雄 2024-03-21 06:43:58 +00:00 committed by Gitee
parent ebd35803c6
commit c3155204eb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -9,7 +9,6 @@
<script src="xspreadsheet/is-utf8.js"></script> <script src="xspreadsheet/is-utf8.js"></script>
<script src="xspreadsheet/xlsx.full.min.js"></script> <script src="xspreadsheet/xlsx.full.min.js"></script>
<script src="xspreadsheet/xlsxspread.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="xspreadsheet/zh-cn.js"></script>
<script src="js/base64.min.js" type="text/javascript"></script> <script src="js/base64.min.js" type="text/javascript"></script>
</head> </head>
@ -55,12 +54,20 @@ reader.onload = function(e) {
data = new Uint8Array(data); data = new Uint8Array(data);
let f = isUTF8(data); let f = isUTF8(data);
if (f) { if (f) {
var str = cptable.utils.decode(65001, data); try {
process_wb(XLSX.read(str, { type: "string" })); var str = cptable.utils.decode(65001, data);
} else {
var str = cptable.utils.decode(936, data);
process_wb(XLSX.read(str, { type: "string" })); process_wb(XLSX.read(str, { type: "string" }));
} } catch (error) {
process_wb(XLSX.read(data));
}
} else {
try {
var str = cptable.utils.decode(936, data);
process_wb(XLSX.read(str, { type: "string" }));
} catch (error) {
process_wb(XLSX.read(data));
}
}
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
} }