Export CSV replace header names on columns

Export CSV replace header names on columns

bfarkasbfarkas Posts: 181Questions: 48Answers: 0

Has anyone ever replaced the header names on the columns for export only for CSV?
I was thinking of trying the data interception approach, but not sure if I am overthinking this.
For excel I can say don't include the header and then insert a line, but the insert does not seem to be available for csv.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,761
    Answer ✓

    See if this thread helps.

    Kevin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Thanks Kevin, that got me on the right track.
    I have hidden the real header and then can do the customize.
    One thing still trying to sort, the goal is to simulate a header, so I have the commas added, but if I do quotes it fails because of escaping and the function. Is there a way around that?

    So for instance, this is the customize function

    customize: function (csv) {
                    return "1,2,3,5,7,8,9,10,11,12,13,14,15,16,17,18\n"+  csv;
                    },
    

    If I update it to the below which is my goal, it fails:

    customize: function (csv) {
                    return ""1","2","3","5","7","8","9","10","11","12","13","14","15","16","17","18"\n"+  csv;
                    },
    
  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,761

    If you want each header wrapped in " then use single quotes for the string, for example:
    return '"1","2","3","5","7","8","9","10","11","12","13","14","15","16","17","18"\n'+ csv;

    Kevin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    So simple. Thanks Kevin!

This discussion has been closed.