-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
51 lines (49 loc) · 1.53 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>WebAssembly</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
</head>
<body>
<label>
Select an image from your computer:
<input type="file" id="file" accept="image/*" />
</label>
<p id="loading">
Loading...
</p>
<button id="download" style="display: none;">Download</button>
<script src="wasm_exec.js"></script>
<script>
function downloadFile(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
document.body.removeChild(a);
}
async function loadImage() {
const input = document.querySelector("#file");
if (input.files) {
const ab = await input.files[0].arrayBuffer();
const excel = convertToExcel(new Uint8Array(ab));
const blob = new Blob([excel], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
downloadFile(blob, "output.xlsx");
} else {
alert("Please select a file.");
}
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
go.run(result.instance);
document.querySelector("#loading").style = "display: none";
document.querySelector("#download").style = "display: block";
});
document.querySelector("#download").addEventListener("click", loadImage);
</script>
</body>
</html>