Pranav Kumar
Pranav Kumar

Reputation: 87

Exporting JSON to Excel is saving in .xls format! Require to save in '.xlsx' format

Exporting data from UI to Excel. But it is saving in '.xls' format. Need to save in '.xlsx' format.

Here is the link of my fiddle

I tried to change the uri to

var uri = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,'

But Showing the downloaded file in '.xlsx' format corrupted.

One field contains the data like

'<p><strong>Test</strong></p>'

Can anyone help me to resolve this issue ??

Here my field data is with html tags & style e.g Bold/Italic/Hyperlink etc. Expected output is conversion that text with styling like if any text is bold , Ine xcel also it should be exported like Bold text. Same with other styles.

Upvotes: 0

Views: 2241

Answers (1)

Carlangueitor
Carlangueitor

Reputation: 425

As .xls and .xlsx are completely different formats you can't simply change the extension to get that working.

I'll suggest you to send the data to the backend via a form, and let the backend generate de .xlsx file, there are a lot of libraries in a lot of languages that can help you with that:

If you can't use a backend solution, you can use js-xlsx library which can generate .xlsx files in the client-side, you can see the demo of exporting a table, or construct the file like this:

var filename = "write.xlsx";
var data = [
    ['Code-Page ID', 'Name', 'ACP   OEMCP', 'Windows NT 3.1', 'Windows NT 3.1', 'Windows 95'],
  [1200, 'Unicode (BMP of ISO/IEC-10646)', null, 'X', 'X', '*'],
  [1250, 'Windows 3.1 Eastern European', 'X', 'X', 'X', 'X'],
 ];

var ws_name = "Code Page Support";
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.aoa_to_sheet(data);

XLSX.utils.book_append_sheet(wb, ws, ws_name);
XLSX.writeFile(wb, filename);

Upvotes: 2

Related Questions