엑셀 머리글을 컬럼에 이어 읽기Map Excel headers to grid columns
파일의 머리글이 그리드 컬럼과 달라도 columns 옵션으로 이어 읽고, 시트와 범위(range)를 골라요.Link file headers that differ from the grid columns with the columns option, and choose the sheet and the range.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="시트" id="sheet">
<option value="orders" selected>주문</option>
<option value="notes">메모</option>
</select>
<select aria-label="머리글 이어 주기" id="map">
<option value="yes" selected>함</option>
<option value="no">안 함</option>
</select>
<input
type="text"
aria-label="범위"
placeholder="범위 (비우면 전체, 예: A1:C3)"
id="range"
/>
<button type="button" id="run">읽기</button>
</div>
<div id="grid" style="height: 320px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('sheet').addEventListener('change', (event) => actions.sheet(api, event.target.value));
document.getElementById('map').addEventListener('change', (event) => actions.map(api, event.target.value));
document.getElementById('range').addEventListener('input', (event) => actions.range(api, event.target.value));
document.getElementById('run').addEventListener('click', () => actions.run(api));import { exportXlsx, withExport, xlsxSheet } from '@maxgrid/export';
// 파일의 머리글("주문번호", "거래처"…)이 그리드 컬럼과 달라도, columns 옵션으로 머리글 → 컬럼 id를 이어 줄 수 있어요.
export const options = {
columns: [
{ id: 'order', title: '주문', width: 100 },
{ id: 'customer', title: '거래처', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 80 },
{ id: 'ordered', title: '주문일', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(예전 행)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = { 주문번호: 'order', 거래처명: 'customer', 주문수량: 'qty', 주문일자: 'ordered' };
// 두 시트짜리 파일을 그 자리에서 만들어요: "주문" 시트(데이터)와 "메모" 시트.
function sample() {
return exportXlsx({
columns: [
{ id: 'order', title: '주문번호' },
{ id: 'customer', title: '거래처명' },
{ id: 'qty', title: '주문수량', kind: 'number' },
{ id: 'ordered', title: '주문일자', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: '한빛푸드', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: '파란마켓', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: '단풍상회', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: '바다유통', qty: 7, ordered: '2026-10-08' },
],
}, {
sheetName: '주문',
sheets: [
xlsxSheet('메모', {
columns: [{ id: 'note', title: '메모' }],
rows: [{ note: '분기 마감 전 확인' }],
}),
],
});
}
let sheet = '주문';
let mapped = true;
let range = '';
let say = () => { };
let ex;
export function setup(api, log) {
say = log;
ex = withExport(api);
log({
ko: '파일의 머리글은 "주문번호" 같은 이름이라 그리드 컬럼 id와 달라요. columns 옵션으로 이어 주거나 범위(range)·시트(sheet)를 골라 읽어요.',
en: 'The file headers are names like "주문번호", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
});
}
export const actions = {
sheet: (_api, v) => void (sheet = v === 'notes' ? '메모' : '주문'),
map: (_api, v) => void (mapped = v !== 'no'),
range: (_api, v) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say({
ko: `${r.count}행을 읽었어요. 머리글: ${r.columns.join(', ')}`,
en: `Read ${r.count} rows. Headers: ${r.columns.join(', ')}`,
});
}
catch (error) {
// 메모 시트에는 주문 키 열이 없어요: 엔진 문구 대신 무엇을 고칠지 말해 줘요.
say({
ko: sheet === '메모'
? '이 시트에는 주문번호 열이 없어요. "주문" 시트를 고르세요.'
: `읽지 못했어요: ${error.message}`,
en: sheet === '메모'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${error.message}`,
});
}
},
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>엑셀 머리글을 컬럼에 이어 읽기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="시트" id="sheet">
<option value="orders" selected>주문</option>
<option value="notes">메모</option>
</select>
<select aria-label="머리글 이어 주기" id="map">
<option value="yes" selected>함</option>
<option value="no">안 함</option>
</select>
<input
type="text"
aria-label="범위"
placeholder="범위 (비우면 전체, 예: A1:C3)"
id="range"
/>
<button type="button" id="run">읽기</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { exportXlsx, withExport, xlsxSheet } = MaxGridExport;
// 파일의 머리글("주문번호", "거래처"…)이 그리드 컬럼과 달라도, columns 옵션으로 머리글 → 컬럼 id를 이어 줄 수 있어요.
const options = {
columns: [
{ id: 'order', title: '주문', width: 100 },
{ id: 'customer', title: '거래처', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 80 },
{ id: 'ordered', title: '주문일', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(예전 행)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = { 주문번호: 'order', 거래처명: 'customer', 주문수량: 'qty', 주문일자: 'ordered' };
// 두 시트짜리 파일을 그 자리에서 만들어요: "주문" 시트(데이터)와 "메모" 시트.
function sample() {
return exportXlsx({
columns: [
{ id: 'order', title: '주문번호' },
{ id: 'customer', title: '거래처명' },
{ id: 'qty', title: '주문수량', kind: 'number' },
{ id: 'ordered', title: '주문일자', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: '한빛푸드', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: '파란마켓', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: '단풍상회', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: '바다유통', qty: 7, ordered: '2026-10-08' },
],
}, {
sheetName: '주문',
sheets: [
xlsxSheet('메모', {
columns: [{ id: 'note', title: '메모' }],
rows: [{ note: '분기 마감 전 확인' }],
}),
],
});
}
let sheet = '주문';
let mapped = true;
let range = '';
let say = () => { };
let ex;
function setup(api, log) {
say = log;
ex = withExport(api);
log({
ko: '파일의 머리글은 "주문번호" 같은 이름이라 그리드 컬럼 id와 달라요. columns 옵션으로 이어 주거나 범위(range)·시트(sheet)를 골라 읽어요.',
en: 'The file headers are names like "주문번호", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
});
}
const actions = {
sheet: (_api, v) => void (sheet = v === 'notes' ? '메모' : '주문'),
map: (_api, v) => void (mapped = v !== 'no'),
range: (_api, v) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say({
ko: `${r.count}행을 읽었어요. 머리글: ${r.columns.join(', ')}`,
en: `Read ${r.count} rows. Headers: ${r.columns.join(', ')}`,
});
}
catch (error) {
// 메모 시트에는 주문 키 열이 없어요: 엔진 문구 대신 무엇을 고칠지 말해 줘요.
say({
ko: sheet === '메모'
? '이 시트에는 주문번호 열이 없어요. "주문" 시트를 고르세요.'
: `읽지 못했어요: ${error.message}`,
en: sheet === '메모'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${error.message}`,
});
}
},
};
options.ariaLabel = "엑셀 머리글을 컬럼에 이어 읽기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('sheet').addEventListener('change', (event) => actions.sheet(api, event.target.value));
document.getElementById('map').addEventListener('change', (event) => actions.map(api, event.target.value));
document.getElementById('range').addEventListener('input', (event) => actions.range(api, event.target.value));
document.getElementById('run').addEventListener('click', () => actions.run(api));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="시트"
disabled={!api}
onChange={(event) => api && actions.sheet(api, event.target.value)}
>
<option value="orders">주문</option>
<option value="notes">메모</option>
</select>
<select defaultValue="orders"
aria-label="머리글 이어 주기"
disabled={!api}
onChange={(event) => api && actions.map(api, event.target.value)}
>
<option value="yes">함</option>
<option value="no">안 함</option>
</select>
<input
type="text"
aria-label="범위"
placeholder="범위 (비우면 전체, 예: A1:C3)"
disabled={!api}
onChange={(event) => api && actions.range(api, event.target.value)}
/>
<button
type="button"
disabled={!api}
onClick={() => api && actions.run(api)}
>읽기</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// 파일의 머리글("주문번호", "거래처"…)이 그리드 컬럼과 달라도, columns 옵션으로 머리글 → 컬럼 id를 이어 줄 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 100 },
{ id: 'customer', title: '거래처', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 80 },
{ id: 'ordered', title: '주문일', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(예전 행)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = { 주문번호: 'order', 거래처명: 'customer', 주문수량: 'qty', 주문일자: 'ordered' };
// 두 시트짜리 파일을 그 자리에서 만들어요: "주문" 시트(데이터)와 "메모" 시트.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: '주문번호' },
{ id: 'customer', title: '거래처명' },
{ id: 'qty', title: '주문수량', kind: 'number' },
{ id: 'ordered', title: '주문일자', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: '한빛푸드', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: '파란마켓', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: '단풍상회', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: '바다유통', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: '주문',
sheets: [
xlsxSheet('메모', {
columns: [{ id: 'note', title: '메모' }],
rows: [{ note: '분기 마감 전 확인' }],
}),
],
},
);
}
let sheet = '주문';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: '파일의 머리글은 "주문번호" 같은 이름이라 그리드 컬럼 id와 달라요. columns 옵션으로 이어 주거나 범위(range)·시트(sheet)를 골라 읽어요.',
en: 'The file headers are names like "주문번호", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
});
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? '메모' : '주문'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say({
ko: `${r.count}행을 읽었어요. 머리글: ${r.columns.join(', ')}`,
en: `Read ${r.count} rows. Headers: ${r.columns.join(', ')}`,
});
} catch (error) {
// 메모 시트에는 주문 키 열이 없어요: 엔진 문구 대신 무엇을 고칠지 말해 줘요.
say({
ko:
sheet === '메모'
? '이 시트에는 주문번호 열이 없어요. "주문" 시트를 고르세요.'
: `읽지 못했어요: ${(error as Error).message}`,
en:
sheet === '메모'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
});
}
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="시트"
:disabled="!api"
@change="api && actions.sheet(api, ($event.target as HTMLSelectElement).value)"
>
<option value="orders" selected>주문</option>
<option value="notes">메모</option>
</select>
<select
aria-label="머리글 이어 주기"
:disabled="!api"
@change="api && actions.map(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>함</option>
<option value="no">안 함</option>
</select>
<input
type="text"
aria-label="범위"
placeholder="범위 (비우면 전체, 예: A1:C3)"
:disabled="!api"
@input="api && actions.range(api, ($event.target as HTMLInputElement).value)"
/>
<button type="button" :disabled="!api" @click="api && actions.run(api)">읽기</button>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// 파일의 머리글("주문번호", "거래처"…)이 그리드 컬럼과 달라도, columns 옵션으로 머리글 → 컬럼 id를 이어 줄 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 100 },
{ id: 'customer', title: '거래처', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 80 },
{ id: 'ordered', title: '주문일', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(예전 행)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = { 주문번호: 'order', 거래처명: 'customer', 주문수량: 'qty', 주문일자: 'ordered' };
// 두 시트짜리 파일을 그 자리에서 만들어요: "주문" 시트(데이터)와 "메모" 시트.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: '주문번호' },
{ id: 'customer', title: '거래처명' },
{ id: 'qty', title: '주문수량', kind: 'number' },
{ id: 'ordered', title: '주문일자', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: '한빛푸드', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: '파란마켓', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: '단풍상회', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: '바다유통', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: '주문',
sheets: [
xlsxSheet('메모', {
columns: [{ id: 'note', title: '메모' }],
rows: [{ note: '분기 마감 전 확인' }],
}),
],
},
);
}
let sheet = '주문';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: '파일의 머리글은 "주문번호" 같은 이름이라 그리드 컬럼 id와 달라요. columns 옵션으로 이어 주거나 범위(range)·시트(sheet)를 골라 읽어요.',
en: 'The file headers are names like "주문번호", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
});
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? '메모' : '주문'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say({
ko: `${r.count}행을 읽었어요. 머리글: ${r.columns.join(', ')}`,
en: `Read ${r.count} rows. Headers: ${r.columns.join(', ')}`,
});
} catch (error) {
// 메모 시트에는 주문 키 열이 없어요: 엔진 문구 대신 무엇을 고칠지 말해 줘요.
say({
ko:
sheet === '메모'
? '이 시트에는 주문번호 열이 없어요. "주문" 시트를 고르세요.'
: `읽지 못했어요: ${(error as Error).message}`,
en:
sheet === '메모'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
});
}
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="시트"
[disabled]="!api"
(change)="api && actions.sheet(api, $any($event.target).value)"
>
<option value="orders" selected>주문</option>
<option value="notes">메모</option>
</select>
<select
aria-label="머리글 이어 주기"
[disabled]="!api"
(change)="api && actions.map(api, $any($event.target).value)"
>
<option value="yes" selected>함</option>
<option value="no">안 함</option>
</select>
<input
type="text"
aria-label="범위"
placeholder="범위 (비우면 전체, 예: A1:C3)"
[disabled]="!api"
(input)="api && actions.range(api, $any($event.target).value)"
/>
<button
type="button"
[disabled]="!api"
(click)="api && actions.run(api)"
>읽기</button>
</div>
<mx-grid style="height: 320px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// 파일의 머리글("주문번호", "거래처"…)이 그리드 컬럼과 달라도, columns 옵션으로 머리글 → 컬럼 id를 이어 줄 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: '주문', width: 100 },
{ id: 'customer', title: '거래처', width: 130 },
{ id: 'qty', title: '수량', kind: 'number', width: 80 },
{ id: 'ordered', title: '주문일', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(예전 행)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = { 주문번호: 'order', 거래처명: 'customer', 주문수량: 'qty', 주문일자: 'ordered' };
// 두 시트짜리 파일을 그 자리에서 만들어요: "주문" 시트(데이터)와 "메모" 시트.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: '주문번호' },
{ id: 'customer', title: '거래처명' },
{ id: 'qty', title: '주문수량', kind: 'number' },
{ id: 'ordered', title: '주문일자', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: '한빛푸드', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: '파란마켓', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: '단풍상회', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: '바다유통', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: '주문',
sheets: [
xlsxSheet('메모', {
columns: [{ id: 'note', title: '메모' }],
rows: [{ note: '분기 마감 전 확인' }],
}),
],
},
);
}
let sheet = '주문';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: '파일의 머리글은 "주문번호" 같은 이름이라 그리드 컬럼 id와 달라요. columns 옵션으로 이어 주거나 범위(range)·시트(sheet)를 골라 읽어요.',
en: 'The file headers are names like "주문번호", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
});
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? '메모' : '주문'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say({
ko: `${r.count}행을 읽었어요. 머리글: ${r.columns.join(', ')}`,
en: `Read ${r.count} rows. Headers: ${r.columns.join(', ')}`,
});
} catch (error) {
// 메모 시트에는 주문 키 열이 없어요: 엔진 문구 대신 무엇을 고칠지 말해 줘요.
say({
ko:
sheet === '메모'
? '이 시트에는 주문번호 열이 없어요. "주문" 시트를 고르세요.'
: `읽지 못했어요: ${(error as Error).message}`,
en:
sheet === '메모'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
});
}
},
}; This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Sheet" id="sheet">
<option value="orders" selected>Orders</option>
<option value="notes">Notes</option>
</select>
<select aria-label="Header mapping" id="map">
<option value="yes" selected>On</option>
<option value="no">Off</option>
</select>
<input
type="text"
aria-label="Range"
placeholder="Range (blank = all, e.g. A1:C3)"
id="range"
/>
<button type="button" id="run">Read</button>
</div>
<div id="grid" style="height: 320px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('sheet').addEventListener('change', (event) => actions.sheet(api, event.target.value));
document.getElementById('map').addEventListener('change', (event) => actions.map(api, event.target.value));
document.getElementById('range').addEventListener('input', (event) => actions.range(api, event.target.value));
document.getElementById('run').addEventListener('click', () => actions.run(api));import { exportXlsx, withExport, xlsxSheet } from '@maxgrid/export';
// Even when the file headers ("Order No", "Client"...) differ from the grid columns, the columns option links header text to column id.
export const options = {
columns: [
{ id: 'order', title: 'Order', width: 100 },
{ id: 'customer', title: 'Customer', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 80 },
{ id: 'ordered', title: 'Ordered', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(old row)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = {
'Order No': 'order',
Client: 'customer',
Quantity: 'qty',
'Order date': 'ordered',
};
// Builds a two-sheet file on the spot: an "Orders" sheet (the data) and a "Notes" sheet.
function sample() {
return exportXlsx({
columns: [
{ id: 'order', title: 'Order No' },
{ id: 'customer', title: 'Client' },
{ id: 'qty', title: 'Quantity', kind: 'number' },
{ id: 'ordered', title: 'Order date', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: 'Harbor Foods', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: 'Blue Market', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: 'Maple Trading', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: 'Ocean Supply', qty: 7, ordered: '2026-10-08' },
],
}, {
sheetName: 'Orders',
sheets: [
xlsxSheet('Notes', {
columns: [{ id: 'note', title: 'Note' }],
rows: [{ note: 'Check before quarter close' }],
}),
],
});
}
let sheet = 'Orders';
let mapped = true;
let range = '';
let say = () => { };
let ex;
export function setup(api, log) {
say = log;
ex = withExport(api);
log('The file headers are names like "Order No", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.');
}
export const actions = {
sheet: (_api, v) => void (sheet = v === 'notes' ? 'Notes' : 'Orders'),
map: (_api, v) => void (mapped = v !== 'no'),
range: (_api, v) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say(`Read ${r.count} rows. Headers: ${r.columns.join(', ')}`);
}
catch (error) {
// The Notes sheet has no order key column: say what to fix instead of the engine message.
say(sheet === 'Notes'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${error.message}`);
}
},
};This HTML also loads an extra bundle (the extra script tag above) and uses it as a global. No install is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Map Excel headers to grid columns</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Sheet" id="sheet">
<option value="orders" selected>Orders</option>
<option value="notes">Notes</option>
</select>
<select aria-label="Header mapping" id="map">
<option value="yes" selected>On</option>
<option value="no">Off</option>
</select>
<input
type="text"
aria-label="Range"
placeholder="Range (blank = all, e.g. A1:C3)"
id="range"
/>
<button type="button" id="run">Read</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { exportXlsx, withExport, xlsxSheet } = MaxGridExport;
// Even when the file headers ("Order No", "Client"...) differ from the grid columns, the columns option links header text to column id.
const options = {
columns: [
{ id: 'order', title: 'Order', width: 100 },
{ id: 'customer', title: 'Customer', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 80 },
{ id: 'ordered', title: 'Ordered', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(old row)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = {
'Order No': 'order',
Client: 'customer',
Quantity: 'qty',
'Order date': 'ordered',
};
// Builds a two-sheet file on the spot: an "Orders" sheet (the data) and a "Notes" sheet.
function sample() {
return exportXlsx({
columns: [
{ id: 'order', title: 'Order No' },
{ id: 'customer', title: 'Client' },
{ id: 'qty', title: 'Quantity', kind: 'number' },
{ id: 'ordered', title: 'Order date', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: 'Harbor Foods', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: 'Blue Market', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: 'Maple Trading', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: 'Ocean Supply', qty: 7, ordered: '2026-10-08' },
],
}, {
sheetName: 'Orders',
sheets: [
xlsxSheet('Notes', {
columns: [{ id: 'note', title: 'Note' }],
rows: [{ note: 'Check before quarter close' }],
}),
],
});
}
let sheet = 'Orders';
let mapped = true;
let range = '';
let say = () => { };
let ex;
function setup(api, log) {
say = log;
ex = withExport(api);
log('The file headers are names like "Order No", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.');
}
const actions = {
sheet: (_api, v) => void (sheet = v === 'notes' ? 'Notes' : 'Orders'),
map: (_api, v) => void (mapped = v !== 'no'),
range: (_api, v) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r)
say(`Read ${r.count} rows. Headers: ${r.columns.join(', ')}`);
}
catch (error) {
// The Notes sheet has no order key column: say what to fix instead of the engine message.
say(sheet === 'Notes'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${error.message}`);
}
},
};
options.ariaLabel = "Map Excel headers to grid columns";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('sheet').addEventListener('change', (event) => actions.sheet(api, event.target.value));
document.getElementById('map').addEventListener('change', (event) => actions.map(api, event.target.value));
document.getElementById('range').addEventListener('input', (event) => actions.range(api, event.target.value));
document.getElementById('run').addEventListener('click', () => actions.run(api));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Sheet"
disabled={!api}
onChange={(event) => api && actions.sheet(api, event.target.value)}
>
<option value="orders">Orders</option>
<option value="notes">Notes</option>
</select>
<select defaultValue="orders"
aria-label="Header mapping"
disabled={!api}
onChange={(event) => api && actions.map(api, event.target.value)}
>
<option value="yes">On</option>
<option value="no">Off</option>
</select>
<input
type="text"
aria-label="Range"
placeholder="Range (blank = all, e.g. A1:C3)"
disabled={!api}
onChange={(event) => api && actions.range(api, event.target.value)}
/>
<button
type="button"
disabled={!api}
onClick={() => api && actions.run(api)}
>Read</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// Even when the file headers ("Order No", "Client"...) differ from the grid columns, the columns option links header text to column id.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 100 },
{ id: 'customer', title: 'Customer', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 80 },
{ id: 'ordered', title: 'Ordered', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(old row)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = {
'Order No': 'order',
Client: 'customer',
Quantity: 'qty',
'Order date': 'ordered',
};
// Builds a two-sheet file on the spot: an "Orders" sheet (the data) and a "Notes" sheet.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: 'Order No' },
{ id: 'customer', title: 'Client' },
{ id: 'qty', title: 'Quantity', kind: 'number' },
{ id: 'ordered', title: 'Order date', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: 'Harbor Foods', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: 'Blue Market', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: 'Maple Trading', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: 'Ocean Supply', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: 'Orders',
sheets: [
xlsxSheet('Notes', {
columns: [{ id: 'note', title: 'Note' }],
rows: [{ note: 'Check before quarter close' }],
}),
],
},
);
}
let sheet = 'Orders';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'The file headers are names like "Order No", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
);
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? 'Notes' : 'Orders'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r) say(`Read ${r.count} rows. Headers: ${r.columns.join(', ')}`);
} catch (error) {
// The Notes sheet has no order key column: say what to fix instead of the engine message.
say(
sheet === 'Notes'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
);
}
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Sheet"
:disabled="!api"
@change="api && actions.sheet(api, ($event.target as HTMLSelectElement).value)"
>
<option value="orders" selected>Orders</option>
<option value="notes">Notes</option>
</select>
<select
aria-label="Header mapping"
:disabled="!api"
@change="api && actions.map(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>On</option>
<option value="no">Off</option>
</select>
<input
type="text"
aria-label="Range"
placeholder="Range (blank = all, e.g. A1:C3)"
:disabled="!api"
@input="api && actions.range(api, ($event.target as HTMLInputElement).value)"
/>
<button type="button" :disabled="!api" @click="api && actions.run(api)">Read</button>
</div>
<Grid style="height: 320px" :options="options" @ready="onReady" />
</template>import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// Even when the file headers ("Order No", "Client"...) differ from the grid columns, the columns option links header text to column id.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 100 },
{ id: 'customer', title: 'Customer', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 80 },
{ id: 'ordered', title: 'Ordered', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(old row)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = {
'Order No': 'order',
Client: 'customer',
Quantity: 'qty',
'Order date': 'ordered',
};
// Builds a two-sheet file on the spot: an "Orders" sheet (the data) and a "Notes" sheet.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: 'Order No' },
{ id: 'customer', title: 'Client' },
{ id: 'qty', title: 'Quantity', kind: 'number' },
{ id: 'ordered', title: 'Order date', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: 'Harbor Foods', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: 'Blue Market', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: 'Maple Trading', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: 'Ocean Supply', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: 'Orders',
sheets: [
xlsxSheet('Notes', {
columns: [{ id: 'note', title: 'Note' }],
rows: [{ note: 'Check before quarter close' }],
}),
],
},
);
}
let sheet = 'Orders';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'The file headers are names like "Order No", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
);
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? 'Notes' : 'Orders'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r) say(`Read ${r.count} rows. Headers: ${r.columns.join(', ')}`);
} catch (error) {
// The Notes sheet has no order key column: say what to fix instead of the engine message.
say(
sheet === 'Notes'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
);
}
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Sheet"
[disabled]="!api"
(change)="api && actions.sheet(api, $any($event.target).value)"
>
<option value="orders" selected>Orders</option>
<option value="notes">Notes</option>
</select>
<select
aria-label="Header mapping"
[disabled]="!api"
(change)="api && actions.map(api, $any($event.target).value)"
>
<option value="yes" selected>On</option>
<option value="no">Off</option>
</select>
<input
type="text"
aria-label="Range"
placeholder="Range (blank = all, e.g. A1:C3)"
[disabled]="!api"
(input)="api && actions.range(api, $any($event.target).value)"
/>
<button
type="button"
[disabled]="!api"
(click)="api && actions.run(api)"
>Read</button>
</div>
<mx-grid style="height: 320px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { exportXlsx, withExport, xlsxSheet, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
order: string;
customer: string;
qty: number;
ordered: string | null;
}
// Even when the file headers ("Order No", "Client"...) differ from the grid columns, the columns option links header text to column id.
export const options: GridOptions<Row> = {
columns: [
{ id: 'order', title: 'Order', width: 100 },
{ id: 'customer', title: 'Customer', width: 130 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 80 },
{ id: 'ordered', title: 'Ordered', kind: 'date', width: 110 },
],
rows: [{ order: 'SO-0000', customer: '(old row)', qty: 0, ordered: null }],
rowKey: 'order',
};
const MAP = {
'Order No': 'order',
Client: 'customer',
Quantity: 'qty',
'Order date': 'ordered',
};
// Builds a two-sheet file on the spot: an "Orders" sheet (the data) and a "Notes" sheet.
function sample(): Uint8Array {
return exportXlsx(
{
columns: [
{ id: 'order', title: 'Order No' },
{ id: 'customer', title: 'Client' },
{ id: 'qty', title: 'Quantity', kind: 'number' },
{ id: 'ordered', title: 'Order date', kind: 'date' },
],
rows: [
{ order: 'SO-3001', customer: 'Harbor Foods', qty: 12, ordered: '2026-10-01' },
{ order: 'SO-3002', customer: 'Blue Market', qty: 4, ordered: '2026-10-03' },
{ order: 'SO-3003', customer: 'Maple Trading', qty: 30, ordered: '2026-10-05' },
{ order: 'SO-3004', customer: 'Ocean Supply', qty: 7, ordered: '2026-10-08' },
],
},
{
sheetName: 'Orders',
sheets: [
xlsxSheet('Notes', {
columns: [{ id: 'note', title: 'Note' }],
rows: [{ note: 'Check before quarter close' }],
}),
],
},
);
}
let sheet = 'Orders';
let mapped = true;
let range = '';
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'The file headers are names like "Order No", different from the grid column ids. Link them with the columns option, or pick the range and the sheet.',
);
}
export const actions = {
sheet: (_api: GridApi<Row>, v?: string) => void (sheet = v === 'notes' ? 'Notes' : 'Orders'),
map: (_api: GridApi<Row>, v?: string) => void (mapped = v !== 'no'),
range: (_api: GridApi<Row>, v?: string) => void (range = (v ?? '').trim()),
run: async () => {
try {
const r = await ex?.importXlsx(sample(), {
sheet,
...(mapped ? { columns: MAP } : {}),
...(range === '' ? {} : { range }),
});
if (r) say(`Read ${r.count} rows. Headers: ${r.columns.join(', ')}`);
} catch (error) {
// The Notes sheet has no order key column: say what to fix instead of the engine message.
say(
sheet === 'Notes'
? 'This sheet has no order-number column. Pick the Orders sheet.'
: `Could not read: ${(error as Error).message}`,
);
}
},
};