Skip to content

Commit 29c4fb1

Browse files
ccreed1988mportuga
authored andcommitted
fix(exporter): remove extra double quotes in excel export
Remove code that is adding a duplicate double quote for each double quote it sees in a string value when exporting from excel. Also change test file to reflect this change. The motivation is that it does not seem like normal behavior to add extra double quotes for excel exports and these extra double quotes become confusing for the end user.
1 parent c4ec5a4 commit 29c4fb1

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

packages/exporter/src/js/exporter.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1558,25 +1558,21 @@
15581558
* @ngdoc function
15591559
* @name formatFieldAsExcel
15601560
* @methodOf ui.grid.exporter.service:uiGridExporterService
1561-
* @description Renders a single field as a csv field, including
1562-
* quotes around the value
1563-
* @param {field} field the field to be turned into a csv string,
1561+
* @description Renders a single field as a excel-ified field
1562+
* @param {field} field the field to be excel-ified,
15641563
* may be of any type
15651564
* @returns {string} a excel-ified version of the field
15661565
*/
15671566
formatFieldAsExcel: function (field, workbook, sheet, formatters) {
15681567
if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
15691568
return '';
15701569
}
1571-
if (typeof(field.value) === 'number') {
1570+
if ((typeof(field.value) === 'number') || (typeof(field.value) === 'string')) {
15721571
return field.value;
15731572
}
15741573
if (typeof(field.value) === 'boolean') {
15751574
return (field.value ? 'TRUE' : 'FALSE') ;
15761575
}
1577-
if (typeof(field.value) === 'string') {
1578-
return field.value.replace(/"/g,'""');
1579-
}
15801576

15811577
return JSON.stringify(field.value);
15821578
},

packages/exporter/test/exporter.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ describe('ui.grid.exporter', function() {
12551255
it('should "FALSE" when the type of the field value is boolean', function() {
12561256
expect(uiGridExporterService.formatFieldAsExcel({value: false})).toEqual('FALSE');
12571257
});
1258-
it('should double the amount of double quotes when the type of the field value is string', function() {
1259-
expect(uiGridExporterService.formatFieldAsExcel({value: '"test"'})).toEqual('""test""');
1258+
it('should not double the amount of double quotes when the type of the field value is string', function() {
1259+
expect(uiGridExporterService.formatFieldAsExcel({value: '"test"'})).toEqual('"test"');
12601260
});
12611261
it('should transform the field value into a string when the type of the field value is anything else', function() {
12621262
expect(uiGridExporterService.formatFieldAsExcel({value: {foo: 'bar'}})).toEqual('{"foo":"bar"}');

0 commit comments

Comments
 (0)