Skip to content

Commit 1c5bbe4

Browse files
authored
Merge branch 'master' into simeonoff/fix-9997
2 parents 82e3dcf + 3a936e0 commit 1c5bbe4

File tree

6 files changed

+194
-16
lines changed

6 files changed

+194
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All notable changes for each version of this project will be documented in this
99
The `rowData` argument may be `undefined` in remote scenarios/applying the callback on filtering labels
1010
so make sure to check its availability.
1111

12+
- `IgxExcelExporterService`
13+
- Added support for freezing column headers in **Excel**. By default, the column headers would not be frozen but this behavior can be controlled by the `freezeHeaders` option of the IgxExcelExporterOptions object.
14+
1215
## 12.1.0
1316

1417
### New Features

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,33 @@ describe('Excel Exporter', () => {
235235
await wrapper.verifyDataFilesContent(actualData.gridJobTitleIdFrozen, 'Not all pinned columns are frozen in the export!');
236236
});
237237

238+
it('should honor \'freezeHeaders\' option.', async () => {
239+
const result = await TestMethods.createGridAndPinColumn([1]);
240+
const fix = result.fixture;
241+
const grid = result.grid;
242+
243+
options.ignorePinning = false;
244+
options.freezeHeaders = true;
245+
fix.detectChanges();
246+
247+
let wrapper = await getExportedData(grid, options);
248+
wrapper.verifyStructure();
249+
await wrapper.verifyDataFilesContent(actualData.gridNameFrozenHeaders,
250+
'One frozen column and frozen headers should have been exported!');
251+
252+
options.ignorePinning = true;
253+
fix.detectChanges();
254+
wrapper = await getExportedData(grid, options);
255+
await wrapper.verifyDataFilesContent(actualData.gridFrozenHeaders,
256+
'No frozen columns and frozen headers should have been exported!');
257+
258+
options.freezeHeaders = false;
259+
fix.detectChanges();
260+
wrapper = await getExportedData(grid, options);
261+
await wrapper.verifyDataFilesContent(actualData.gridNameIDJobTitle,
262+
'No frozen columns and no frozen headers should have been exported!');
263+
});
264+
238265
it('should honor applied sorting.', async () => {
239266
const fix = TestBed.createComponent(GridIDNameJobTitleComponent);
240267
fix.detectChanges();
@@ -796,6 +823,13 @@ describe('Excel Exporter', () => {
796823

797824
await exportAndVerify(hGrid, options, actualData.exportHierarchicalDataWithExpandedRows);
798825
});
826+
827+
it('should export hierarchical grid data with frozen headers', async () => {
828+
options.freezeHeaders = true;
829+
fix.detectChanges();
830+
831+
await exportAndVerify(hGrid, options, actualData.exportHierarchicalDataWithFrozenHeaders);
832+
});
799833
});
800834

801835
describe('', () => {
@@ -1043,6 +1077,12 @@ describe('Excel Exporter', () => {
10431077

10441078
await exportAndVerify(grid, options, actualData.exportMultiColumnHeadersDataWithoutMultiColumnHeaders);
10451079
});
1080+
1081+
it('should export grid with frozen multi column headers', async () => {
1082+
options.freezeHeaders = true;
1083+
fix.detectChanges();
1084+
await exportAndVerify(grid, options, actualData.exportFrozenMultiColumnHeadersData, false);
1085+
});
10461086
});
10471087

10481088
const getExportedData = (grid, exportOptions: IgxExcelExporterOptions) => {

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export class WorksheetFile implements IExcelFile {
151151
sheetData += `</row>`;
152152
}
153153

154+
const multiColumnHeaderLevel = worksheetData.options.ignoreMultiColumnHeaders ? 0 : owner.maxLevel;
155+
const freezeHeaders = worksheetData.options.freezeHeaders ? 2 + multiColumnHeaderLevel : 1;
156+
154157
if (!isHierarchicalGrid) {
155158
this.dimension =
156159
'A1:' + ExcelStrings.getExcelColumn(worksheetData.columnCount - 1) + (worksheetData.rowCount + owner.maxLevel);
@@ -177,18 +180,29 @@ export class WorksheetFile implements IExcelFile {
177180
cols += '</cols>';
178181

179182
const indexOfLastPinnedColumn = worksheetData.indexOfLastPinnedColumn;
180-
183+
const frozenColumnCount = indexOfLastPinnedColumn + 1;
184+
let firstCell = ExcelStrings.getExcelColumn(frozenColumnCount) + freezeHeaders;
181185
if (indexOfLastPinnedColumn !== -1 &&
182186
!worksheetData.options.ignorePinning &&
183187
!worksheetData.options.ignoreColumnsOrder) {
184-
const frozenColumnCount = indexOfLastPinnedColumn + 1;
185-
const firstCell = ExcelStrings.getExcelColumn(frozenColumnCount) + '1';
186188
this.freezePane =
187-
`<pane xSplit="${frozenColumnCount}" topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
189+
`<pane xSplit="${frozenColumnCount}" ySplit="${freezeHeaders - 1}"
190+
topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
191+
} else if (worksheetData.options.freezeHeaders) {
192+
firstCell = ExcelStrings.getExcelColumn(0) + freezeHeaders;
193+
this.freezePane =
194+
`<pane xSplit="0" ySplit="${freezeHeaders - 1}"
195+
topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
188196
}
189197
} else {
190198
const columnWidth = worksheetData.options.columnWidth ? worksheetData.options.columnWidth : 20;
191199
cols += `<cols><col min="1" max="${worksheetData.columnCount}" width="${columnWidth}" customWidth="1"/></cols>`;
200+
if (worksheetData.options.freezeHeaders) {
201+
const firstCell = ExcelStrings.getExcelColumn(0) + freezeHeaders;
202+
this.freezePane =
203+
`<pane xSplit="0" ySplit="${freezeHeaders - 1}"
204+
topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
205+
}
192206
}
193207

194208
this.processDataRecordsAsync(worksheetData, (rows) => {

0 commit comments

Comments
 (0)