I want to export html elements or form to excel(.xlsm) template in php or javascript just as in this image file. I searched for possible solutions but all I get was to export table data to excel, I can use that too but I need the input fields as they are just as in this image.
Till now I have user basic code to export a table into excel but when I change the extenstion of the file then excel says it is a corrupted file, the code I used is like:
function exportTableToExcel(tableID, filename = ''){
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
filename = filename?filename+'.xlsm':'excel_data.xlsm';
// Create download link element
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {type: dataType});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
}
This code returns the excel file with or without the custom name.