This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (54 loc) · 1.9 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Copyright (c) 2013-present The TagSpaces Authors.
* Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */
/* globals sendMessageToHost, getParameterByName, initI18N, $, isElectron, XLSX */
// const locale = getParameterByName('locale');
const filePath = getParameterByName('file');
const readFile = filePath => {
const oReq = new XMLHttpRequest();
oReq.open('GET', filePath, true);
oReq.responseType = 'arraybuffer';
oReq.onload = () => {
const arrayBuffer = oReq.response; // Note: not oReq.responseText
if (arrayBuffer) {
const byteArray = new Uint8Array(arrayBuffer);
processWb(XLSX.read(byteArray, { type: 'array' }));
}
};
oReq.send(null);
};
// if (filePath.toLowerCase().endsWith('.csv')) {
// sendMessageToHost({ command: 'loadDefaultTextContent', preview: true });
// } else {
// // TODO check web
readFile(filePath);
// }
const processWb = wb => {
const HTMLOUT = document.getElementById('htmlout');
HTMLOUT.innerHTML = '';
wb.SheetNames.forEach(sheetName => {
const htmlstr = XLSX.utils.sheet_to_html(wb.Sheets[sheetName], {
editable: false
});
HTMLOUT.innerHTML += htmlstr;
});
$('body')
.find('a[href]')
.each((index, link) => {
const currentSrc = $(link).attr('href');
$(link).off();
$(link).on('click', e => {
e.preventDefault();
sendMessageToHost({ command: 'openLinkExternally', link: currentSrc });
});
});
};
// function setContent(content, fileDir) {
// processWb(XLSX.read(content, { type: 'string' }));
// }
// function saveFile(type, fn, dl) {
// const elt = document.getElementById('data-table');
// const wb = XLSX.utils.table_to_book(elt, {sheet:"Sheet JS"});
// return dl ?
// XLSX.write(wb, {bookType:type, bookSST:true, type: 'base64'}) :
// XLSX.writeFile(wb, fn || ('test.' + (type || 'xlsx')));
// }