Appearance
Function: sortColumns()
ts
function sortColumns(worksheet: Worksheet, compareFn: (a: any, b: any) => number): void;Defined in: src/excel/excel.tsx:567
Sort worksheet columns using a custom compare function.
Parameters
| Parameter | Type | Description |
|---|---|---|
worksheet | Worksheet | The ExcelJS worksheet. |
compareFn | (a: any, b: any) => number | A compare function that receives two header values. |
Returns
void
Example
ts
sortColumns(worksheet, (a, b) => String(a).localeCompare(String(b)));
const priority: Record<string, number> = { Name: 1, Email: 2, Phone: 3 };
sortColumns(worksheet, (a, b) => (priority[a] ?? 999) - (priority[b] ?? 999));