|
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 exporterPdfDefaultStyle
|
|
626 | 635 | var exportData = self.getData(grid, rowTypes, colTypes);
|
627 | 636 | var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator);
|
628 | 637 |
|
629 |
| - self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility); |
| 638 | + self.downloadFile (grid.options.exporterCsvFilename, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility, grid.options.exporterIsExcelCompatible); |
630 | 639 | });
|
631 | 640 | },
|
632 | 641 |
|
|
909 | 918 | * @param {string} csvContent the csv content that we'd like to
|
910 | 919 | * download as a file
|
911 | 920 | * @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF)
|
| 921 | + * @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X') |
912 | 922 | */
|
913 |
| - downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility) { |
| 923 | + downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) { |
914 | 924 | var D = document;
|
915 | 925 | var a = D.createElement('a');
|
916 | 926 | var strMimeType = 'application/octet-stream;charset=utf-8';
|
917 | 927 | var rawFile;
|
918 | 928 | var ieVersion = this.isIE();
|
919 |
| - |
| 929 | + |
| 930 | + if (exporterIsExcelCompatible) { |
| 931 | + csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent; |
| 932 | + } |
| 933 | + |
920 | 934 | // IE10+
|
921 | 935 | if (navigator.msSaveBlob) {
|
922 | 936 | return navigator.msSaveOrOpenBlob(
|
|
926 | 940 | fileName
|
927 | 941 | );
|
928 | 942 | }
|
929 |
| - |
930 |
| - if (ieVersion) { |
| 943 | + |
| 944 | + if (ieVersion){ |
931 | 945 | var frame = D.createElement('iframe');
|
932 | 946 | document.body.appendChild(frame);
|
933 | 947 |
|
934 | 948 | frame.contentWindow.document.open('text/html', 'replace');
|
935 |
| - frame.contentWindow.document.write('sep=' + columnSeparator + '\r\n' + csvContent); |
| 949 | + frame.contentWindow.document.write(csvContent); |
936 | 950 | frame.contentWindow.document.close();
|
937 | 951 | frame.contentWindow.focus();
|
938 | 952 | frame.contentWindow.document.execCommand('SaveAs', true, fileName);
|
939 | 953 |
|
940 | 954 | document.body.removeChild(frame);
|
941 | 955 | return true;
|
942 | 956 | }
|
943 |
| - |
| 957 | + |
944 | 958 | //html5 A[download]
|
945 | 959 | if ('download' in a) {
|
946 | 960 | var blob = new Blob(
|
|
0 commit comments