Skip to content

Commit b3a7877

Browse files
onlyexeptiongedinakovaChronosSF
authored
fix(exporter): custom date/number summaries format - 17.2.x (#14703)
* fix(exporter): custom date/number summaries format * fix(exporter): add additional check in getSummaryFunction --------- Co-authored-by: Galina Edinakova <[email protected]> Co-authored-by: Stamen Stoychev <[email protected]>
1 parent 1b270cd commit b3a7877

File tree

5 files changed

+626
-6
lines changed

5 files changed

+626
-6
lines changed

projects/igniteui-angular/src/lib/services/excel/excel-exporter-grid.spec.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import {
2020
GridWithThreeLevelsOfMultiColumnHeadersAndTwoRowsExportComponent,
2121
GroupedGridWithSummariesComponent,
2222
GridCurrencySummariesComponent,
23-
GridUserMeetingDataComponent
23+
GridUserMeetingDataComponent,
24+
GridCustomSummaryComponent,
25+
GridCustomSummaryWithNullAndZeroComponent,
26+
GridCustomSummaryWithUndefinedZeroAndValidNumberComponent,
27+
GridCustomSummaryWithUndefinedAndNullComponent,
28+
GridCustomSummaryWithDateComponent
2429
} from '../../test-utils/grid-samples.spec';
2530
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
2631
import { first } from 'rxjs/operators';
@@ -75,7 +80,12 @@ describe('Excel Exporter', () => {
7580
IgxHierarchicalGridSummariesExportComponent,
7681
GroupedGridWithSummariesComponent,
7782
GridCurrencySummariesComponent,
78-
GridUserMeetingDataComponent
83+
GridUserMeetingDataComponent,
84+
GridCustomSummaryComponent,
85+
GridCustomSummaryWithNullAndZeroComponent,
86+
GridCustomSummaryWithUndefinedZeroAndValidNumberComponent,
87+
GridCustomSummaryWithUndefinedAndNullComponent,
88+
GridCustomSummaryWithDateComponent
7989
]
8090
}).compileComponents();
8191
}));
@@ -1355,6 +1365,56 @@ describe('Excel Exporter', () => {
13551365

13561366
await exportAndVerify(grid, options, actualData.exportHierarchicalGridWithSummaries);
13571367
});
1368+
1369+
it('should export grid with custom summaries, only with summary label as string', async () => {
1370+
fix = TestBed.createComponent(GridCustomSummaryComponent);
1371+
fix.detectChanges();
1372+
await wait(300);
1373+
1374+
grid = fix.componentInstance.grid;
1375+
1376+
await exportAndVerify(grid, options, actualData.exportGridWithCustomSummaryOnlyWithSummaryLabel);
1377+
});
1378+
1379+
it('should export grid with custom summaries, with null and zero (as number)', async () => {
1380+
fix = TestBed.createComponent(GridCustomSummaryWithNullAndZeroComponent);
1381+
fix.detectChanges();
1382+
await wait(300);
1383+
1384+
grid = fix.componentInstance.grid;
1385+
1386+
await exportAndVerify(grid, options, actualData.exportGridCustomSummaryWithNullAndZero);
1387+
});
1388+
1389+
it('should export grid with custom summaries, with undefined, zero and positive number (as number)', async () => {
1390+
fix = TestBed.createComponent(GridCustomSummaryWithUndefinedZeroAndValidNumberComponent);
1391+
fix.detectChanges();
1392+
await wait(300);
1393+
1394+
grid = fix.componentInstance.grid;
1395+
1396+
await exportAndVerify(grid, options, actualData.exportGridCustomSummaryWithUndefinedZeroAndValidNumber);
1397+
});
1398+
1399+
it('should export grid with custom summaries, with undefined and null', async () => {
1400+
fix = TestBed.createComponent(GridCustomSummaryWithUndefinedAndNullComponent);
1401+
fix.detectChanges();
1402+
await wait(300);
1403+
1404+
grid = fix.componentInstance.grid;
1405+
1406+
await exportAndVerify(grid, options, actualData.exportGridCustomSummaryWithUndefinedAndNull);
1407+
});
1408+
1409+
it('should export grid with custom summaries, with date', async () => {
1410+
fix = TestBed.createComponent(GridCustomSummaryWithDateComponent);
1411+
fix.detectChanges();
1412+
await wait(300);
1413+
1414+
grid = fix.componentInstance.grid;
1415+
1416+
await exportAndVerify(grid, options, actualData.exportGridCustomSummaryWithDate);
1417+
});
13581418
});
13591419

13601420
describe('', () => {

projects/igniteui-angular/src/lib/services/excel/excel-files.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,34 @@ export class WorksheetFile implements IExcelFile {
454454
summaryFunc = this.getSummaryFunction(cellValue.label, key, dimensionMapKey, level, targetCol);
455455

456456
if (!summaryFunc) {
457-
const cellStr = `${cellValue.label}: ${cellValue.value}`;
458-
const savedValue = dictionary.saveValue(cellStr, false);
459-
return `<c r="${columnName}" t="s" s="1"><v>${savedValue}</v></c>`;
457+
let summaryValue;
458+
459+
const label = cellValue.label?.toString();
460+
const value = cellValue.value?.toString();
461+
462+
if (label && value) {
463+
summaryValue = `${cellValue.label}: ${cellValue.value}`;
464+
} else if (label) {
465+
summaryValue = cellValue.label;
466+
} else if (value) {
467+
summaryValue = cellValue.value;
468+
}
469+
470+
const savedValue = dictionary.saveValue(summaryValue, false);
471+
const isSavedAsString = savedValue !== -1;
472+
const isSavedAsDate = !isSavedAsString && summaryValue instanceof Date;
473+
474+
if (isSavedAsDate) {
475+
const timeZoneOffset = summaryValue.getTimezoneOffset() * 60000;
476+
const isoString = (new Date(summaryValue - timeZoneOffset)).toISOString();
477+
summaryValue = isoString.substring(0, isoString.indexOf('.'));
478+
}
479+
480+
const resolvedValue = isSavedAsString ? savedValue : summaryValue;
481+
const type = isSavedAsString ? `t="s"` : isSavedAsDate ? `t="d"` : '';
482+
const style = isSavedAsDate ? `s="2"` : `s="1"`;
483+
484+
return `<c r="${columnName}" ${type} ${style}><v>${resolvedValue}</v></c>`;
460485
}
461486

462487
return `<c r="${columnName}"><f t="array" ref="${columnName}">${summaryFunc}</f></c>`;
@@ -533,7 +558,7 @@ export class WorksheetFile implements IExcelFile {
533558
let result = '';
534559
const currencyInfo = this.currencyStyleMap.get(col.currencyCode);
535560

536-
switch(type.toLowerCase()) {
561+
switch(type?.toString().toLowerCase()) {
537562
case "count":
538563
return `"Count: "&amp;_xlfn.COUNTIF(${levelDimensions.startCoordinate}:${levelDimensions.endCoordinate}, ${recordLevel})`
539564
case "min":

0 commit comments

Comments
 (0)