Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion demos/aurelia/src/examples/slickgrid/example55.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { type AureliaGridInstance, type Column, type GridOption } from 'aurelia-slickgrid';
import './example55.scss';

Expand Down Expand Up @@ -47,12 +48,15 @@ export class Example55 {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
gridHeight: 560,
gridWidth: 1080,
Expand Down
6 changes: 5 additions & 1 deletion demos/aurelia/src/examples/slickgrid/example56.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { type AureliaGridInstance, type Column, type GridOption } from 'aurelia-slickgrid';
import './example56.scss';

Expand Down Expand Up @@ -61,12 +62,15 @@ export class Example56 {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
frozenRow: 2,
gridHeight: 560,
Expand Down
6 changes: 5 additions & 1 deletion demos/react/src/examples/slickgrid/Example55.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import React, { useEffect, useRef, useState } from 'react';
import { SlickgridReact, type Column, type GridOption, type SlickgridReactInstance } from 'slickgrid-react';
import './example55.scss';
Expand Down Expand Up @@ -45,12 +46,15 @@ const Example55: React.FC = () => {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
gridHeight: 560,
gridWidth: 1080,
Expand Down
6 changes: 5 additions & 1 deletion demos/react/src/examples/slickgrid/Example56.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import React, { useEffect, useRef, useState } from 'react';
import { SlickgridReact, type Column, type GridOption, type SlickgridReactInstance } from 'slickgrid-react';
import './example56.scss';
Expand Down Expand Up @@ -60,12 +61,15 @@ const Example56: React.FC = () => {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
frozenRow: 2,
gridHeight: 560,
Expand Down
6 changes: 5 additions & 1 deletion demos/vanilla/src/examples/example44.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Column, GridOption } from '@slickgrid-universal/common';
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { Slicker, type SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
import { ExampleGridOptions } from './example-grid-options.js';
import './example44.scss';
Expand Down Expand Up @@ -52,12 +53,15 @@ export default class Example44 {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
gridHeight: 560,
gridWidth: 1080,
Expand Down
6 changes: 5 additions & 1 deletion demos/vanilla/src/examples/example45.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Column, GridOption } from '@slickgrid-universal/common';
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { Slicker, type SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
import { ExampleGridOptions } from './example-grid-options.js';
import './example45.scss';
Expand Down Expand Up @@ -67,12 +68,15 @@ export default class Example45 {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
frozenRow: 2,
gridHeight: 560,
Expand Down
6 changes: 5 additions & 1 deletion demos/vue/src/components/Example55.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { SlickgridVue, type Column, type GridOption, type SlickgridVueInstance } from 'slickgrid-vue';
import { onBeforeMount, ref, type Ref } from 'vue';

Expand Down Expand Up @@ -44,12 +45,15 @@ function defineGrid() {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
gridHeight: 560,
gridWidth: 1080,
Expand Down
6 changes: 5 additions & 1 deletion demos/vue/src/components/Example56.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { SlickgridVue, type Column, type GridOption, type SlickgridVueInstance } from 'slickgrid-vue';
import { onBeforeMount, ref, type Ref } from 'vue';

Expand Down Expand Up @@ -59,12 +60,15 @@ function defineGrid() {
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
rowHeight: 40,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
frozenRow: 2,
gridHeight: 560,
gridWidth: 1080,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, ViewEncapsulation, type OnInit } from '@angular/core';
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { AngularSlickgridComponent, type AngularGridInstance, type Column, type GridOption } from '../../library';

const NB_ITEMS = 200;
Expand Down Expand Up @@ -50,12 +51,15 @@ export class Example55Component implements OnInit {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
gridHeight: 560,
gridWidth: 1080,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, ViewEncapsulation, type OnInit } from '@angular/core';
import { ExcelExportService } from '@slickgrid-universal/excel-export';
import { PdfExportService } from '@slickgrid-universal/pdf-export';
import { AngularSlickgridComponent, type AngularGridInstance, type Column, type GridOption } from '../../library';

const NB_ITEMS = 150;
Expand Down Expand Up @@ -64,12 +65,15 @@ export class Example56Component implements OnInit {
enableCellNavigation: true,
enableTextSelectionOnCells: true,
enableVariableRowHeight: true,
externalResources: [new ExcelExportService()],
externalResources: [new ExcelExportService(), new PdfExportService()],
excelExportOptions: {
// export variable row height will also be reflected in the export
// but it can be disabled by setting `includeVariableRowHeight` to false
// includeVariableRowHeight: false, // export all rows at default height
},
pdfExportOptions: {
pageOrientation: 'landscape',
},
rowHeight: 40,
frozenRow: 2,
gridHeight: 560,
Expand Down
50 changes: 31 additions & 19 deletions packages/excel-export/src/excelExport.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ describe('ExcelExportService', () => {
});

describe('Variable Row Height', () => {
it('exportToExcel should call applyVariableRowHeights when variable row height is enabled', async () => {
it('exportToExcel should call applyVariableRowHeight when variable row height is enabled', async () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValue(40);
Expand All @@ -2655,16 +2655,16 @@ describe('ExcelExportService', () => {
vi.spyOn(dataViewStub, 'getLength').mockReturnValue(1);
vi.spyOn(dataViewStub, 'getItem').mockReturnValueOnce({ id: 1 });

const applyVariableRowHeightsSpy = vi.spyOn(service as any, 'applyVariableRowHeights');
const applyVariableRowHeightSpy = vi.spyOn(service as any, 'applyVariableRowHeight');

service.init(gridStub, container);
const result = await service.exportToExcel({ filename: 'export', useStreamingExport: false, includeVariableRowHeight: true });

expect(result).toBe(true);
expect(applyVariableRowHeightsSpy).toHaveBeenCalledTimes(1);
expect(applyVariableRowHeightSpy).toHaveBeenCalledTimes(1);
});

it('exportToExcel should not call applyVariableRowHeights when includeVariableRowHeight is false', async () => {
it('exportToExcel should not call applyVariableRowHeight when includeVariableRowHeight is false', async () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValue(40);
Expand All @@ -2673,72 +2673,84 @@ describe('ExcelExportService', () => {
vi.spyOn(dataViewStub, 'getLength').mockReturnValue(1);
vi.spyOn(dataViewStub, 'getItem').mockReturnValueOnce({ id: 1 });

const applyVariableRowHeightsSpy = vi.spyOn(service as any, 'applyVariableRowHeights');
const applyVariableRowHeightSpy = vi.spyOn(service as any, 'applyVariableRowHeight');

service.init(gridStub, container);
const result = await service.exportToExcel({ filename: 'export', useStreamingExport: false, includeVariableRowHeight: false });

expect(result).toBe(true);
expect(applyVariableRowHeightsSpy).not.toHaveBeenCalled();
expect(applyVariableRowHeightSpy).not.toHaveBeenCalled();
});

it('applyVariableRowHeights should set row heights when enableVariableRowHeight is true', () => {
it('applyVariableRowHeight should set row heights when enableVariableRowHeight is true', () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValueOnce(40).mockReturnValueOnce(50).mockReturnValueOnce(60);
vi.spyOn(dataViewStub, 'getLength').mockReturnValue(3);

const setRowInstructionsSpy = vi.fn();
(service as any)._sheet = { setRowInstructions: setRowInstructionsSpy };
(service as any)._excelExportOptions = { includeVariableRowHeight: true };
(service as any)._hasColumnTitlePreHeader = false;

service.init(gridStub, container);
(service as any).applyVariableRowHeights();
(service as any).applyVariableRowHeight(0, 2);
(service as any).applyVariableRowHeight(1, 3);
(service as any).applyVariableRowHeight(2, 4);

// Excel row starts at 2 (1 for header, +1 for 0-based index)
// 40px * 0.75 = 30pt, 50px * 0.75 = 37.5pt, 60px * 0.75 = 45pt
expect(setRowInstructionsSpy).toHaveBeenCalledWith(2, { height: 30 });
expect(setRowInstructionsSpy).toHaveBeenCalledWith(3, { height: 37.5 });
expect(setRowInstructionsSpy).toHaveBeenCalledWith(4, { height: 45 });
expect(setRowInstructionsSpy).toHaveBeenCalledTimes(3);
});

it('applyVariableRowHeights should offset row numbers when hasColumnTitlePreHeader is true', () => {
it('applyVariableRowHeight should use the provided Excel row number', () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValue(40);
vi.spyOn(dataViewStub, 'getLength').mockReturnValue(1);

const setRowInstructionsSpy = vi.fn();
(service as any)._sheet = { setRowInstructions: setRowInstructionsSpy };
(service as any)._excelExportOptions = { includeVariableRowHeight: true };
(service as any)._hasColumnTitlePreHeader = true;

service.init(gridStub, container);
(service as any).applyVariableRowHeights();
(service as any).applyVariableRowHeight(0, 3);

// Excel row starts at 3 (1 for pre-header, 1 for header, +1 for 0-based index)
expect(setRowInstructionsSpy).toHaveBeenCalledWith(3, { height: 30 });
});

it('should convert pixel heights to Excel points correctly (72 DPI)', () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValue(40);
vi.spyOn(dataViewStub, 'getLength').mockReturnValue(1);

const setRowInstructionsSpy = vi.fn();
(service as any)._sheet = { setRowInstructions: setRowInstructionsSpy };
(service as any)._excelExportOptions = { includeVariableRowHeight: true };
(service as any)._hasColumnTitlePreHeader = false;

service.init(gridStub, container);
(service as any).applyVariableRowHeights();
(service as any).applyVariableRowHeight(0, 2);

// 40px * 0.75 = 30pt
expect(setRowInstructionsSpy).toHaveBeenCalledWith(2, { height: 30 });
});

it('applyVariableRowHeight should skip rows that use the default grid row height', () => {
const mockGridOptionWithVarHeight = { ...mockGridOptions, enableVariableRowHeight: true, rowHeight: 25 } as GridOption;
vi.spyOn(gridStub, 'getOptions').mockReturnValue(mockGridOptionWithVarHeight);
vi.spyOn(gridStub, 'getRowHeight').mockReturnValueOnce(25).mockReturnValueOnce(40).mockReturnValueOnce(25);

const setRowInstructionsSpy = vi.fn();
(service as any)._sheet = { setRowInstructions: setRowInstructionsSpy };
(service as any)._excelExportOptions = { includeVariableRowHeight: true };

service.init(gridStub, container);
(service as any).applyVariableRowHeight(0, 2);
(service as any).applyVariableRowHeight(1, 3);
(service as any).applyVariableRowHeight(2, 4);

expect(setRowInstructionsSpy).toHaveBeenCalledTimes(1);
expect(setRowInstructionsSpy).toHaveBeenCalledWith(3, { height: 30 });
});
});
});

Expand Down
Loading
Loading