0

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.

Pranav Kumar
  • 79
  • 3
  • 17
  • See this post, https://stackoverflow.com/questions/37498713/how-to-export-an-html-table-as-an-xlsx-file – kvb Mar 16 '18 at 15:42
  • 1
    Possible duplicate of [How to export an html table as an xlsx file](https://stackoverflow.com/questions/37498713/how-to-export-an-html-table-as-an-xlsx-file) – phuzi Mar 16 '18 at 15:43
  • From backend, one of my field contains html tags. Expected output : In excel , it should convert that tag to text with respective styling in excel. No where I found this question or answer – Pranav Kumar Mar 16 '18 at 15:46

1 Answers1

2

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);
Carlangueitor
  • 425
  • 2
  • 15
  • Developing application with SAP UI5 & ABAP. Front end, I can use Javascript or JQuerry – Pranav Kumar Mar 16 '18 at 16:17
  • Updated de answer with a pure client-side solution @PranavKumar :) – Carlangueitor Mar 16 '18 at 16:41
  • I tried this one. But here issue with the data. My data is in HTML format like bold/italic. e.g 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', '

    Test

    ', '*'], [1250, 'Windows 3.1 Eastern European', 'X', 'X', 'X', 'X'], ];
    – Pranav Kumar Mar 16 '18 at 16:52
  • Sorry for asking you again. Can u help me how to pares the data manually ? I tried with jQuery.parseHTML() . In excel also data should be reflected as bold/Italic & hyperlink – Pranav Kumar Mar 16 '18 at 16:55