I am using ant design Bar graph , I am trying to export Bar graph to excel worksheet.
I tried to convert <Bar/>
from UI to Object using html2canvas.
Currently I am getting the converted image URL instead of actual bar graph Image in the excel worksheet cell. Like below…
data:image/png;base64,iVBORw0k......
And I can see the actual bar graph image after visiting above URL in browser.
const exportToExcel=()=>{
const workbook= XLSX2.utils.book_new();
const chart = document.getElementById('myChart');
html2canvas(chart).then((canvas) => {
const imgData = canvas.toDataURL('image/png');
const worksheet = XLSX.utils.aoa_to_sheet([['Chart'], [imgData]]);
XLSX.utils.book_append_sheet(workbook, worksheet, "Chart");
XLSX.writeFile(workbook, U_${formattedDate}.xlsx, { compression: true });
});
};
I want to export Bar graph to excel worksheet