xlsx-preview
Version:
Preview the .xlsx in the browser, convert to HTML with styles.
54 lines (50 loc) • 1.39 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>xlsx-preview</title>
<style>
#result {
margin: 10px auto;
border: 1px solid #eee;
}
.res-obj {
width: 1000px;
height: 800px;
}
</style>
</head>
<body>
<input id="choose-file" type="file" accept=".xlsx" name="xlsx">
<h3>Result:</h3>
<div id="result">
<label for="choose-file">
<p style="text-align:center; line-height: 80px;">
Choose .xlsx file to preview.
</p>
</label>
</div>
<script src="./dist/xlsxPreview.demo.js"></script>
<script>
const item = document.querySelector('[name="xlsx"]');
item.addEventListener('change', async e => {
const files = e.target.files;
const buffer = await files[0].arrayBuffer()
const result = await xlsxPreview.xlsx2Html(buffer, {
output: 'arrayBuffer',
minimumRows: 50,
minimumCols: 30,
});
console.log(result);
const url = URL.createObjectURL(new Blob([result], {
type: 'text/html'
}));
document.querySelector('#result').innerHTML =
`<object class="res-obj" type="text/html" data="${url}"></object>`
})
console.log(xlsxPreview);
</script>
</body>
</html>