Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82744

Excel Export to create new sheet for server side data

$
0
0

Hi @kthorngren
I was using you example here live.datatables.net/qinoxinu/6/edit for Excel Export to create new sheet.

While I was implementing the example on table with client side data and it works as expected.

However, when I used to include the table on new sheet where the data comes from server side, it shows invalid XML and the error looks like this:

Uncaught Error: Invalid XML: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac"><cols><col min="1" max="1" width="20" customWidth="1"/><col min="2" max="2" width="20" customWidth="1"/><col min="3" max="3" width="20" customWidth="1"/><col min="4" max="4" width="20" customWidth="1"/><col min="5" max="5" width="20" customWidth="1"/><col min="6" max="6" width="20" customWidth="1"/><col min="7" max="7" width="20" customWidth="1"/><col min="8" max="8" width="20" customWidth="1"/><col min="9" max="9" width="20" customWidth="1"/><col min="10" max="10" width="20" customWidth="1"/><col min="11" max="11" width="20" customWidth="1"/><col min="12" max="12" width="20" customWidth="1"/><col min="13" max="13" width="20" customWidth="1"/><col min="14" max="14" width="20" customWidth="1"/><col min="15" max="15" width="20" customWidth="1"/><col min="16" max="16" width="20" customWidth="1"/><col min="17" max="17" width="20" customWidth="1"/><col min="18" max="18" width="20" customWidth="1"/><col min="19" max="19" width="20" customWidth="1"/><col min="20" max="20" width="20" customWidth="1"/></cols><sheetData><row r="1"><c t="inlineStr" r="A1" s="51"><is><t>My Sheet2</t></is></c></row><row r="2"><c t="inlineStr" r="A2" s="2"><is><t>Product<br> Code</t></is></c><c t="inlineStr" r="B2" s="2"><is><t>Contract Prod</t></is></c><c t="inlineStr" r="C2" s="2"><is><t>Product Name</t></is></c><c t="inlineStr" r="D2" s="2"><is><t>Pack Size</t></is></c><c t="inlineStr" r="E2" s="2"><is><t>Start Date</t></is></c><c t="inlineStr" r="F2" s="2"><is><t>End Date</t></is></c><c t="inlineStr" r="G2" s="2"><is><t>CF</t></is></c><c t="inlineStr" r="H2" s="2"><is><t>BF</t></is></c><c t="inlineStr" r="I2" s="2"><is><t>TP</t></is></c><c t="inlineStr" r="J2" s="2"><is><t>Bl<br> F</t></is></c><c t="inlineStr" r="K2" s="2"><is><t>CF</t></is></c><c t="inlineStr" r="L2" s="2"><is><t>DF</t></is></c><c t="inlineStr" r="M2" s="2"><is><t>EFF</t></is></c><c t="inlineStr" r="N2" s="2"><is><t>HF</t></is></c><c t="inlineStr" r="O2" s="2"><is><t>HF</t></is></c><c t="inlineStr" r="P2" s="2"><is><t>SF</t></is></c><c t="inlineStr" r="Q2" s="2"><is><t>TR</t></is></c><c t="inlineStr" r="R2" s="2"><is><t>TF</t></is></c><c t="inlineStr" r="S2" s="2"><is><t>SSWF</t></is></c><c t="inlineStr" r="T2" s="2"><is><t>Group Total</t></is></c></row><row r="3"></row><row r="4"></row><row r="5"></row></sheetData><mergeCells count="1"><mergeCell ref="A1:T1"/></mergeCells></worksheet>
    at Function.error (datatables.js:317)
    at Function.jQuery.parseXML (datatables.js:8416)
    at addSheet (crg_contracts_print.php:751)
    at Object.customize (crg_contracts_print.php:936)
    at _Api.action (datatables.js:106760)
    at action (datatables.js:102041)
    at HTMLButtonElement.<anonymous> (datatables.js:102058)
    at HTMLButtonElement.dispatch (datatables.js:5195)
    at HTMLButtonElement.elemData.handle (datatables.js:5003)

I believe the error is coming from this function where it is not merging the cells properly.
function getTableData(table, title) {

        var header = getHeaderNames(table);
        var table = $(table).DataTable();
        console.log(table);
        var rowNum = 1;
        var mergeCells = '';
        var ws = '';

        ws += buildCols(header);
        ws += '<sheetData>';

        if (title.length > 0) {
          ws += buildRow([title], rowNum, 51);
          rowNum++;

          mergeCol = ((header.length - 1) + 10).toString(36).toUpperCase();

          mergeCells = '<mergeCells count="1">'+
            '<mergeCell ref="A1:' + mergeCol + '1"/>' +
                       '</mergeCells>';
        }

How to go with the problem when you use server side data?
Please help
Thank you


Viewing all articles
Browse latest Browse all 82744

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>