6

My html page contain a embedded image (png) that I like to insert into the excel file dynamically. I tried below that created the excel file with the name I like and a worksheet name as well * though the name of worksheet is same as file name, not sure how to set that, with below code

//creating a temporary HTML link element (they support setting file names)
                  var a = document.createElement('a');
                  var postfix = 'AKS'
                  //getting data from our div that contains the HTML table
                  var data_type = 'data:application/vnd.ms-excel';
                  var table_div = document.getElementById('myDynamicImage');
                  var table_html = table_div.outerHTML.replace(/ /g, '%20');
                  a.href = data_type + ', ' + table_html;
                  //setting the file name
                  a.download = 'exported_table_' + postfix + '.xls';
                  //triggering the function
                  a.click();

But the content of image in dataURI format is inserted in excel as a text rather then image. Can I setup this for image. can I control the position etc. can i control the worksheet name, I did that with some other but bit complicated way called tableToExcel.

AKS
  • 1,279
  • 11
  • 27
  • tableToExcel seems to be a jquery plugin to export data tables and not images, so i'd say you can't do it with this plugin. however you can edit the xlsx file directly, but that's more complicated. xlsx is a zipped folder of the source xml and the inserted objects, so it seems possible, but prepare for some serious coding. – robotik Sep 06 '16 at 17:01
  • You may be able to salvage something by looking at the following couple of links https://stackoverflow.com/questions/43925959/javascript-export-image-into-excel https://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata – JGFMK Jul 13 '17 at 08:47

0 Answers0