File size: 955 Bytes
dd4cbfc |
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 |
import jsPreviewExcel from '@js-preview/excel';
import '@js-preview/excel/lib/index.css';
import { useEffect } from 'react';
const Excel = ({ filePath }: { filePath: string }) => {
const fetchDocument = async () => {
const myExcelPreviewer = jsPreviewExcel.init(
document.getElementById('excel'),
);
const jsonFile = new XMLHttpRequest();
jsonFile.open('GET', filePath, true);
jsonFile.send();
jsonFile.responseType = 'arraybuffer';
jsonFile.onreadystatechange = () => {
if (jsonFile.readyState === 4 && jsonFile.status === 200) {
myExcelPreviewer
.preview(jsonFile.response)
.then((res: any) => {
console.log('succeed');
})
.catch((e) => {
console.log('failed', e);
});
}
};
};
useEffect(() => {
fetchDocument();
}, []);
return <div id="excel" style={{ height: '100%' }}></div>;
};
export default Excel;
|