-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check browser support #4
Comments
@Siemienik Under the hood you're using exceljs which supports 3 types of importing: from a file, from a stream, from a buffer. ImporterFactory currently supports importing from a file. This is not going to work in browsers due to security reasons. I think there's no way to extract file path from uploaded files (uploaded with input type file). Therefore I have proposal. In exceljs docs you can find section called "Browser" which points you to this test file. Basically they're using Buffer (node js) or similar concept ArrayBuffer for browsers. So I think we can use FileReader in order to support browsers. Particulary method readAsArrayBuffer. It has good browser support. FileReader too. My proposal
public async from(path: string | ArrayBuffer | Buffer): Promise<IImporter> {
const wb = new Workbook();
if (typeof path === 'string') {
await wb.xlsx.readFile(path);
} else {
await wb.xlsx.load(path);
}
return new Importer(wb);
}
const factory = new ImporterFactory();
export const importInvoice = async (buffer: ArrayBuffer): Promise<IInvoice> => {
// ...import invoice here
};
function App() {
const [invoice, setInvoice] = useState<IInvoice | null>(null);
const onUpload = useCallback((event) => {
const invoiceFile = event.target.files[0];
const reader = new FileReader();
reader.readAsArrayBuffer(invoiceFile);
reader.addEventListener('loadend', (e) => {
if (reader.result instanceof ArrayBuffer) {
importInvoice(reader.result).then(setInvoice);
}
})
}, []);
return (
<div className="App">
{/* ...render invoice here */}
</div>
);
} UPD: UPD2: |
Thank you, for extensive research 👍 it will be fine to handle data url and fetching from url (for instance Then this issue will be fulfilled by checking if this works: import {Importer} from 'xlsx-import/lib/Importer';
function App() {
const [invoice, setInvoice] = useState<IInvoice | null>(null);
const onUpload = useCallback((event) => {
const invoiceFile = event.target.files[0];
const reader = new FileReader();
reader.readAsArrayBuffer(invoiceFile);
reader.addEventListener('loadend', (e) => {
if (reader.result instanceof ArrayBuffer) {
const wb = new Workbook();
await wb.xlsx.load(reader.result);
const importer = new Importer(wb);
const seller = importer.getAllItems(sellerCfg)[0];
// ...
}
})
}, []);
return (
<div className="App">
{/* ...render invoice here */}
</div>
);
} I mean it will be great to prove it by at least one selenium (or cypress) test runned under Chrome and Firefox |
@Siemienik
|
AD3. In scope of this issue I think is enough to create (I'm going to create new issue for AD6. Using selenium to assert that result is right AD7. Profit - we have proved by test that our lib working with browsers, thats enable us to work further with browsers features P.S. I'm afraid about same problem like here: https://github.com/Siemienik/xlsx-renderer/issues/13#issuecomment-704589977 |
@Siemienik |
@Metastasis I created #52, could you check if I've nothing forget?
Fully agree! |
#57 prove that xlsx-import may works on browsers, I'm really happy of that 💯 |
In |
No description provided.
The text was updated successfully, but these errors were encountered: