Skip to content
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

workbook.addImage is not a function #322

Open
ishantiw opened this issue May 23, 2017 · 19 comments
Open

workbook.addImage is not a function #322

ishantiw opened this issue May 23, 2017 · 19 comments

Comments

@ishantiw
Copy link

ishantiw commented May 23, 2017

I have installed latest version of exceljs, however I'm still getting error workbook.addImage is not a function when i'm trying to add any image to the workbook.
PS: I have 0.4.10 version

@ishantiw
Copy link
Author

I am using Excel.stream.xlsx.WorkbookWriter() to create a workbook writer stream

@ishantiw
Copy link
Author

Problem is when we create a workbook using writer stream then it doesn't find function addImage(). However you can also use the following to add an image.

let workbook = Excel.stream.xlsx.WorkbookWriter()
workbook.media.push({
    filename: './Picture1.png',
    extension: 'png',
  })
worksheet.addImage(0, 'B1:E6')
// where 0 is the index of the image you added in workbook, basically its an index of the image you pushed to media array

Otherwise simply use below to create a worksheet and it works,
let workbook = new Excel.Workbook()

@bala-drg
Copy link

bala-drg commented Aug 11, 2017

@guyonroche @ishantiw i'm using the above code but i'm getting "worksheet.addImage is not a function".here is the code

var workbook = Excel.stream.xlsx.WorkbookWriter();
workbook.media.push({
filename: './Picture1.png',
extension: 'png',
})
var worksheet = workbook.addWorksheet();
worksheet.addImage(0, 'B1:E6')

@ishantiw
Copy link
Author

@guyonroche If you will create a worksheet from stream.xlsx.WorkbookWriter() then you will have to use
workbook.media.push({ filename: './Picture1.png', extension: 'png', })
You can get these images using index workbook.media[0]. This is just a hack and its better not to use this one.

Recommended usage,
let workbook = new Excel.Workbook() to create a workbook and then workbook.addImage will work. Cheers!

@dong-qian
Copy link

dong-qian commented Oct 12, 2017

@ishantiw @guyonroche
I follow the docs but add images are not working

let workbook = new Excel.Workbook()
const imageId1 = workbook.addImage({
filename: './Picture1.png',
extension: 'png',
});
worksheet.addBackgroundImage(imageId1);

error: imageId1 returns 0

Please help

@ishantiw
Copy link
Author

@qiandongyq
workbook.addImage({}) returns index of the image you pushed into the image array of workbook. Since it is your first image so you got index as 0 (imageId1). Now you have to use, worksheet.addImage(0, 'A1:B6') to add it over specified cells. But if you are using addBackgroundImage function you just need to pass the index. In my case it is working. Can you please make sure your image is getting added without any error. Try to check using worksheet.addBackgroundImage(0)

@dong-qian
Copy link

dong-qian commented Oct 15, 2017

@ishantiw I think the issue is that i'm using buffer to download the excel file. Everything is working before add images. It is browser, can't see any errors

 this.workbook.xlsx.writeBuffer().then(data => {
      const blob = new Blob([data], {
        type:
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      });
      FileSaver.saveAs(blob, "pshsa.xlsx");
    });

@JackGit
Copy link

JackGit commented Nov 16, 2017

@qiandongyq got same issue here, stopped at addImage and no errors

@kkor
Copy link

kkor commented Nov 28, 2017

@ishantiw the workaround you posted earlier doesn't work:

let workbook = Excel.stream.xlsx.WorkbookWriter()
workbook.media.push({
    filename: './Picture1.png',
    extension: 'png',
  })
worksheet.addImage(0, 'B1:E6') <--- addImage is not a function

This will throw worksheet.addImage is not a function (Note: sheet, not workbook).

Using the recommended let workbook = new Excel.Workbook() is not option, because we need to use a stream. Do you know if it is possible to add images with the Excel.stream.xlsx.WorkbookWriter?
Thanks!

@Abouyer20
Copy link

Anyone know if this is getting fixed anytime soon?
I have had a look at the code, but it's a bit to complex for me at this stage, for me to try and fix.
Like @kkor said my problem is worksheet.addImage is not a function when the file is getting streamed.
Any solution or fixes will be very appreciated. I will still have a look at the code and try and fix it.
Thanks in advance

@kkor
Copy link

kkor commented Jan 30, 2018

@Abouyer20 The maintainer is too busy and won't be able to contribute for the next few months. The non-streaming version had the same problem and was fixed, maybe you can get some pointers from here: #374

@ritesh-nitw
Copy link

This issue is a major release blocker. Surprised that, its not being addressed..
Right now, its impossible to use addImage using the WorkbookWriter.
Any workaround mentioned here won't work.

Guys, do you know any other library that supports all functionality in WorkbookWriter and easy to switch from exceljs(semantically similar)?

@JoaoAlrc
Copy link

JoaoAlrc commented Apr 9, 2019

nothing yet? I'm trying to create a stream too, but, also having this error

workbook.media.push({ filename: './img/logo.png', extension: 'png', }) worksheet.addImage(0, 'B1:E6') <- TypeError: worksheet.addImage is not a function

@amlagazon
Copy link

got the same thing. no error, but it does not work tho. it does not proceed in writeBuffer().

@brunoargolo
Copy link
Contributor

Same issue. Printing excel with over 500k rows about 15 columns. Regular workbook won't work, so the stream workbook writer is my only option and it works great besides not allowing images. Any workaround would be greatly appreciated.

@ritesh-nitw
Copy link

Anyone able to find any workaround?

@akshaykhurana123
Copy link

Got this working by converting my image to base64 via https://www.base64-image.de/
and then adding it in. Please see code below. Work Great!

var myBase64Image = "data:image/jpeg;base64,/9.......................";
var logo = workbook.addImage({
base64: myBase64Image,
extension: 'jpeg',
});
worksheet.addImage(logo, 'N2:O2');

@michaelparkadze
Copy link

Still getting this error when using ExcelJS.stream.xlsx.WorkbookWriter

@GGimenez96
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests