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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] a.Readfile is not a function when exporting excel with images #1244
Comments
This also appears to affect v4.2.1 on the frontend (SPA) as well. To workaround this issue, I decided to load in via Buffer, e.g. // add image to workbook by buffer
const imageBuffer = await axios.get('path/to.image.png', { responseType: 'arraybuffer' });
const imageId2 = workbook.addImage({
buffer: imageBuffer.data,
extension: 'png',
}); Though you don't have to use axios. As long as you can get an ArrayBuffer from your request (either by conversion or directly), then you can use this method. |
Hello @FrederickGeek8 this is my code and am getting the same error. Please kindly help me out here. Thanks.
|
You Can Do this way Its work |
I try to use the image in another folder, but not work. So I draw the image to canvas and convert to base64Data, and add the base64Data in workbook to get a imgId, and use imgId in worksheet. const imageToUse = require('..path/name.png')
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const img = new Image()
img.onload = () => {
ctx.drawImg(img, x, y)
}
img.src = imageToUse
const base64Data = ctx.toDataURL()
const imgId = workbook.addImage({
base64: base64Data,
extension: 'jpeg'
})
worksheet.addBackgoundImage(imgId) |
馃挰 Questions and Help
I have successfully exported excel file with image using base64 file, however when I try to add an image using filename such as this
var imageId1 = workbook.addImage({ filename: 'path/to/image.jpg', extension: 'jpeg', });
An error occurs which is
TypeError: a.readFile is not a function
. I used this on frontend (Angular9) and my guess is that this library is nodejs that's why it does not work as expected.Please let me know if I miss something with my code or if my guess is correct, is there any alternative to add an image using a filename for frontend use.
Thanks in advance
The text was updated successfully, but these errors were encountered: