Forum Discussion

Abdulrahman_Shahin's avatar
2 years ago
Solved

Trouble Exporting HTML Table to Excel in Aras Innovator Custom Button

Hello everyone,

I've been working on a custom button within the search tab for parts in Aras Innovator. The goal is to export a list of specific parts and their properties through a query and display them in an HTML table.

Here's a snippet of the code I'm using to convert the HTML table to Excel and download the Excel file:

[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:4ac1465e-c931-489c-a19e-bb242bc1c5f6:type=javascript&text=var%20htmlCode%20%3D%60%0A%3Chtml%3E%0A%3Chead%3E%0A%3Cmeta%20http-equiv%3D%27Content-Type%27%20content%3D%27text%2Fhtml%3B%20charset%3Dutf-8%27%20%2F%3E%0A%3Cscript%20src%3D%27https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fxlsx%2F0.16.9%2Fxlsx.full.min.js%27%3E%3C%2Fscript%3E%0A%3Cscript%20src%3D%27https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2FFileSaver.js%2F2.0.5%2FFileSaver.min.js%27%3E%3C%2Fscript%3E%0A%3Cscript%3E%0Afunction%20substituteTableToExcel%28%29%7B%0Avar%20table%20%3D%20document.getElementById%28%27all_Parts_AML%27%29%3B%0Avar%20sheet_name%20%3D%20%27ALL_Parts_AML%27%3B%0Avar%20workbook%20%3D%20XLSX.utils.table_to_book%28table%2C%20%7Bsheet%3A%20sheet_name%2C%20cellStyles%3A%20true%7D%29%3B%0Avar%20wbout%20%3D%20XLSX.write%28workbook%2C%20%7B%20bookType%3A%20%27xlsx%27%2C%20bookSST%3A%20true%2C%20type%3A%20%27array%27%2C%20cellStyles%3A%20true%20%7D%29%3B%0AsaveAs%28new%20Blob%28%5Bwbout%5D%2C%20%7B%20type%3A%20%27application%2Foctet-stream%27%20%7D%29%2C%20%27ALL_Parts_AML.xlsx%27%29%3B%0A%7D%0Adocument.addEventListener%28%27DOMContentLoaded%27%2C%20function%28%29%20%7B%0AsubstituteTableToExcel%28%29%3B%0A%7D%29%3B%0A%3C%2Fscript%3E%0A%3Clink%20rel%3D%27stylesheet%27%20type%3D%27text%2Fcss%27%20href%3D%27styles.css%27%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%24%7BexcelTable%7D%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E%60%3B]

return htmlCode;

I'm encountering issues with the export functionality. When I click the custom button, the HTML table is generated correctly, but the Excel file download doesn't seem to work.

Could someone kindly review the code snippet above and provide any insights or suggestions on how to troubleshoot and resolve this issue? I would greatly appreciate it.

Thank you in advance!
Version 12.0 SP8

  • hey Angela, thanks for you replay.
    i take an easer solution, where i call the report, which i already created, in the method like here: link  and assign the js method as an on click method for the costum button. the problem faced me there is that ,after assigning the method to the button i cant edit this method or i will constantly get notification error says that the method has been updated or removed. so i had to reconfigure the button from the start for each edit.

    its solved, thanks

2 Replies

  • As you use a custom library for generating the spreadsheet, it´s hard to tell what's wrong. Do you get an error message in your browser debugger? Is the function triggered at all? (I am not sure if DOMContentLoaded is really the best event type for this one).

    As you asked for a review: I personally would embed the external library in the codetree and don´t use links to external sources.

    Hope you can solve your issue!

    • Abdulrahman_Shahin's avatar
      Abdulrahman_Shahin
      Ideator I

      hey Angela, thanks for you replay.
      i take an easer solution, where i call the report, which i already created, in the method like here: link  and assign the js method as an on click method for the costum button. the problem faced me there is that ,after assigning the method to the button i cant edit this method or i will constantly get notification error says that the method has been updated or removed. so i had to reconfigure the button from the start for each edit.

      its solved, thanks