when exporting to xls/csv

when exporting to xls/csv

tbartbar Posts: 4Questions: 0Answers: 0
edited November 2012 in TableTools
I'm using TableTools to export table to csv/xls without problems. I've got cells containing multiple lines separated by a
and I would like this functionality present in the exported file.

I've tried initialising with "sNewLine": "auto" and "sNewLine": "" but this doesn't give the wanted behaviour.

Is it even possible to do what I want?

Replies

  • tbartbar Posts: 4Questions: 0Answers: 0
    It appears (http://stackoverflow.com/questions/1241220/generating-csv-file-for-excel-how-to-have-a-newline-inside-a-value) that for Excel to create the newlines as expected the format of the file has to carefully crafted to support what I want/need. I've been unable to do this with TableTools. Can anybody help?
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    You'd need to use the cell renderer method ( http://datatables.net/extras/tabletools/button_options#fnCellRender ) to define a formatting function that will manipulate the data in the way you want - specifically inserting newline (\n) characters.

    Allan
  • tbartbar Posts: 4Questions: 0Answers: 0
    I ended up with this formatting function:

    [code]
    "fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
    return '"'+sValue.replace(/
    |/g,"\n")+'"';
    }
    [/code]

    This works when opening the file with Excel 2007. Please notice that cells containing multiple values initially appears within excel as if they only contains one value. Change the view of the file to see all values.
  • shanita713shanita713 Posts: 1Questions: 0Answers: 0
    not working!! please help me.

    "fnCellRender": function (sValue, iColumn, nTr, iDataindex){

    var valueExport = "";
    var data = $(sValue)[0];

    var tag = data.tagName;

    if(tag=='li'){

    valueExport = data.innerHTML;

    }

    return valueExport;

    }
    },
This discussion has been closed.