• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 4447082138

pending completion
4447082138

push

github

GitHub
fix(excel-exporter): escape special chars in column headers (#12784)

14993 of 17636 branches covered (85.01%)

1 of 1 new or added line in 1 file covered. (100.0%)

26710 of 28903 relevant lines covered (92.41%)

29820.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.47
/projects/igniteui-angular/src/lib/services/excel/worksheet-data-dictionary.ts
1
import { ExportUtilities } from '../exporter-common/export-utilities';
2

3
/** @hidden */
4
export class WorksheetDataDictionary {
5
    private static DEFAULT_FONT = '11pt Calibri';
118✔
6
    private static TEXT_PADDING = 5;
118✔
7

118✔
8
    public hasNumberValues = false;
118✔
9
    public hasDateValues = false;
118✔
10

118✔
11
    public stringsCount: number;
118✔
12

118✔
13
    private _dictionary: any;
87✔
14
    private _widthsDictionary: any;
15

16
    private _keys: string[];
31✔
17
    private _keysAreValid: boolean;
18

118✔
19
    private _counter: number;
20
    private _columnWidths: number[];
2✔
21
    private _context: any;
2✔
22

23
    constructor(columnCount: number, columnWidth: number, columnWidthsList: number[]) {
283✔
24
        this._dictionary = {};
25
        this._widthsDictionary = {};
6,244✔
26
        this._counter = 0;
6,812✔
27
        this.dirtyKeyCollections();
6,812✔
28

6,812✔
29
        this._columnWidths = new Array<number>(columnCount);
6,812✔
30

5,056✔
31
        if (columnWidth) {
5,056✔
32
            this._columnWidths.fill(columnWidth);
3,828✔
33
        } else {
3,828✔
34
            this._columnWidths = columnWidthsList;
35
        }
5,056✔
36

37
        this.stringsCount = 0;
1,756✔
38
    }
186✔
39

40
    public get columnWidths() {
41
        return this._columnWidths;
1,570✔
42
    }
43

6,812✔
44
    public saveValue(value: any, isHeader: boolean, shouldSanitizeValue: boolean = true): number {
45
        let sanitizedValue = '';
46
        const isDate = value instanceof Date;
×
47
        const isSavedAsString = isHeader || (typeof value !== 'number' && value !== Number(value) && !Number.isFinite(value) && !isDate);
48

49
        if (isSavedAsString) {
8,884✔
50
            sanitizedValue = shouldSanitizeValue ? ExportUtilities.sanitizeValue(value) : value;
51

52
            if (this._dictionary[sanitizedValue] === undefined) {
113!
53
                this._dictionary[sanitizedValue] = this._counter++;
113✔
54
                this.dirtyKeyCollections();
113✔
55
            }
56

113✔
57
            this.stringsCount ++;
58
        } else if (isDate) {
59
            this.hasDateValues = true;
×
60
        } else {
×
61
            this.hasNumberValues = true;
×
62
        }
×
63

64
        return isSavedAsString ? this.getSanitizedValue(sanitizedValue) : -1;
×
65
    }
66

67
    public getValue(value: string): number {
×
68
        return this.getSanitizedValue(ExportUtilities.sanitizeValue(value));
×
69
    }
×
70

×
71
    public getSanitizedValue(sanitizedValue: string): number {
72
        return this._dictionary[sanitizedValue];
×
73
    }
74

75
    public getKeys(): string[] {
3,946✔
76
        if (!this._keysAreValid) {
77
            this._keys = Object.keys(this._dictionary);
78
            this._keysAreValid = true;
79
        }
80

81
        return this._keys;
82
    }
83

84
    private getTextWidth(value: any): number {
85
        if (this._widthsDictionary[value] === undefined) {
86
            const context = this.getContext();
87
            const metrics = context.measureText(value);
88
            this._widthsDictionary[value] = metrics.width + WorksheetDataDictionary.TEXT_PADDING;
89
        }
90

91
        return this._widthsDictionary[value];
92
    }
93

94
    private getContext(): any {
95
        if (!this._context) {
96
            const canvas = document.createElement('canvas');
97
            this._context = canvas.getContext('2d');
98
            this._context.font = WorksheetDataDictionary.DEFAULT_FONT;
99
        }
100

101
        return this._context;
102
    }
103

104
    private dirtyKeyCollections(): void {
105
        this._keysAreValid = false;
106
    }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc