Skip to content

Commit 933ced6

Browse files
committed
fix(ExcelExporter): Remove the null char from cell value
1 parent d76232a commit 933ced6

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ describe('Excel Exporter', () => {
134134
await wrapper.verifyDataFilesContent(actualData.contactsDataSkippedColumnContent);
135135
});
136136

137+
it('should not fail when data contains null characters (#14944).', async () => {
138+
options.columnWidth = 50;
139+
const wrapper = await getExportedData([
140+
'Terrance\u0000Orta',
141+
'Richard Mahoney\x00LongerName',
142+
'Donna\0Price',
143+
'Lisa Landers',
144+
'Dorothy H. Spencer'
145+
], options);
146+
147+
wrapper.verifyStructure();
148+
await wrapper.verifyTemplateFilesContent();
149+
await wrapper.verifyDataFilesContent(actualData.noHeadersStringDataWithNullChars);
150+
});
151+
137152
const getExportedData = (data: any[], exportOptions: IgxExcelExporterOptions) => {
138153
const result = new Promise<ZipWrapper>((resolve) => {
139154
exporter.exportEnded.pipe(first()).subscribe((value) => {

projects/igniteui-angular/src/lib/services/excel/test-data.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,4 +1911,22 @@ export class FileContentData {
19111911

19121912
return this.createData();
19131913
}
1914+
1915+
public get noHeadersStringDataWithNullChars() {
1916+
this._sharedStringsData = `count="6" uniqueCount="6"><si><t>Column1</t></si><si><t>TerranceOrta</t></si>` +
1917+
`<si><t>Richard MahoneyLongerName</t></si><si><t>DonnaPrice</t></si><si><t>Lisa Landers</t></si><si><t>` +
1918+
`Dorothy H. Spencer</t></si>`;
1919+
1920+
this._tableData = `ref="A1:A6" totalsRowShown="0"><autoFilter ref="A1:A6"/><tableColumns count="1">` +
1921+
`<tableColumn id="1" name="Column1"/></tableColumns>`;
1922+
1923+
this._worksheetData = `<dimension ref="A1:A6"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"></sheetView>` +
1924+
`</sheetViews><sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/><cols><col min="1" max="1" ` +
1925+
`width="50" customWidth="1"/></cols><sheetData><row r="1"><c r="A1" t="s"><v>0</v></c></row><row r="2">` +
1926+
`<c r="A2" t="s"><v>1</v></c></row><row r="3"><c r="A3" t="s"><v>2</v></c></row><row r="4"><c r="A4" t="s"><v>3</v>` +
1927+
`</c></row><row r="5"><c r="A5" t="s"><v>4</v></c></row><row r="6"><c r="A6" t="s"><v>5</v></c></row></sheetData>`;
1928+
1929+
return this.createData();
1930+
}
1931+
19141932
}

projects/igniteui-angular/src/lib/services/exporter-common/export-utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export class ExportUtilities {
6868
.replace(/</g, '&lt;')
6969
.replace(/>/g, '&gt;')
7070
.replace(/"/g, '&quot;')
71-
.replace(/'/g, '&apos;');
71+
.replace(/'/g, '&apos;')
72+
// Bug #14944 - Remove the not supported null character (\u0000, \x00)
73+
.replace(/\x00/g, '');
7274
}
7375
}
7476
}

0 commit comments

Comments
 (0)