|
235 | 235 | * <br/>Defaults to false
|
236 | 236 | */
|
237 | 237 | gridOptions.exporterOlderExcelCompatibility = gridOptions.exporterOlderExcelCompatibility === true;
|
| 238 | + /** |
| 239 | + * @ngdoc object |
| 240 | + * @name exporterIsExcelCompatible |
| 241 | + * @propertyOf ui.grid.exporter.api:GridOptions |
| 242 | + * @description Separator header, used to set a custom column separator in a csv file, only works on MS Excel. |
| 243 | + * Used it on other programs will make csv content display unproperly. Setting this option to false won't add this header. |
| 244 | + * <br/>Defaults to false |
| 245 | + */ |
| 246 | + gridOptions.exporterIsExcelCompatible = gridOptions.exporterIsExcelCompatible === true; |
238 | 247 | /**
|
239 | 248 | * @ngdoc object
|
240 | 249 | * @name exporterMenuItemOrder
|
|
634 | 643 | var exportData = self.getData(grid, rowTypes, colTypes);
|
635 | 644 | var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator);
|
636 | 645 |
|
637 |
| - self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility); |
| 646 | + self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility, grid.options.exporterIsExcelCompatible); |
638 | 647 | });
|
639 | 648 | },
|
640 | 649 |
|
|
917 | 926 | * @param {string} csvContent the csv content that we'd like to
|
918 | 927 | * download as a file
|
919 | 928 | * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF)
|
| 929 | + * @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X') |
920 | 930 | */
|
921 |
| - downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility) { |
| 931 | + downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) { |
922 | 932 | var D = document;
|
923 | 933 | var a = D.createElement('a');
|
924 | 934 | var strMimeType = 'application/octet-stream;charset=utf-8';
|
925 | 935 | var rawFile;
|
926 | 936 | var ieVersion = this.isIE();
|
927 | 937 |
|
| 938 | + if (exporterIsExcelCompatible) { |
| 939 | + csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent; |
| 940 | + } |
| 941 | + |
928 | 942 | // IE10+
|
929 | 943 | if (navigator.msSaveBlob) {
|
930 | 944 | return navigator.msSaveOrOpenBlob(
|
|
940 | 954 | document.body.appendChild(frame);
|
941 | 955 |
|
942 | 956 | frame.contentWindow.document.open('text/html', 'replace');
|
943 |
| - frame.contentWindow.document.write('sep=' + columnSeparator + '\r\n' + csvContent); |
| 957 | + frame.contentWindow.document.write(csvContent); |
944 | 958 | frame.contentWindow.document.close();
|
945 | 959 | frame.contentWindow.focus();
|
946 | 960 | frame.contentWindow.document.execCommand('SaveAs', true, fileName);
|
|
0 commit comments