컬럼마다 내보내기 방식 정하기Set the export behavior per column
컬럼의 export로 엑셀 칸 종류와 내보낼 값을 정해요. 코드는 글자 칸(앞자리 0 유지), 금액은 숫자 칸과 서식(format.number에서 만들어요), 날짜는 글자, 상태는 export.value가 만든 글자로 나가요.A column's export sets the Excel cell type and the exported value. The code goes out as a text cell (leading zeros kept), the amount as a number cell with a number format (built from format.number), the date as text, and the status as the text export.value makes.
코드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">
<button type="button" id="preview">CSV 미리보기</button>
<button type="button" id="download">xlsx 내려받기</button>
</div>
<div id="grid" style="height: 230px"></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('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const rows = [
{
id: 1,
code: '00127',
name: '한빛푸드',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: '소나무철물',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: '파란마켓',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// 화면에는 formatValue·format이 정한 모양이 나와요. 내보낼 때만 컬럼의 export가 따로 정해요.
// - code: xlsx.text 글자 칸이라 앞자리 0이 남아요.
// - amount: format.number에서 엑셀 서식(₩ + 천 단위 + 소수 없음)을 만들고 숫자 칸으로 내보내요.
// - paidAt: xlsx.date 'text'라 이 컬럼만 날짜 칸 대신 글자예요.
// - status: export.value가 만든 글자로 CSV·엑셀·PDF에 나가요.
export const options = {
columns: [
{ id: 'code', title: '코드', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '₩' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: '상태',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? '입금 완료' : '미입금') },
},
{ id: 'paidAt', title: '일자', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
export function setup(api, log) {
say = log;
withExport(api);
}
export const actions = {
preview: (api) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api) => {
await withExport(api).downloadXlsx('거래처-입금.xlsx', { sheetName: '입금' });
say({ ko: 'xlsx를 내려받았어요.', en: 'Downloaded the xlsx.' });
},
}; 이 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">
<button type="button" id="preview">CSV 미리보기</button>
<button type="button" id="download">xlsx 내려받기</button>
</div>
<div id="grid" style="height: 230px"></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 { withExport } = MaxGridExport;
const rows = [
{
id: 1,
code: '00127',
name: '한빛푸드',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: '소나무철물',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: '파란마켓',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// 화면에는 formatValue·format이 정한 모양이 나와요. 내보낼 때만 컬럼의 export가 따로 정해요.
// - code: xlsx.text 글자 칸이라 앞자리 0이 남아요.
// - amount: format.number에서 엑셀 서식(₩ + 천 단위 + 소수 없음)을 만들고 숫자 칸으로 내보내요.
// - paidAt: xlsx.date 'text'라 이 컬럼만 날짜 칸 대신 글자예요.
// - status: export.value가 만든 글자로 CSV·엑셀·PDF에 나가요.
const options = {
columns: [
{ id: 'code', title: '코드', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '₩' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: '상태',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? '입금 완료' : '미입금') },
},
{ id: 'paidAt', title: '일자', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
function setup(api, log) {
say = log;
withExport(api);
}
const actions = {
preview: (api) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api) => {
await withExport(api).downloadXlsx('거래처-입금.xlsx', { sheetName: '입금' });
say({ ko: 'xlsx를 내려받았어요.', en: 'Downloaded the xlsx.' });
},
};
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('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.preview(api)}
>CSV 미리보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.download(api)}
>xlsx 내려받기</button>
</div>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: '한빛푸드',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: '소나무철물',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: '파란마켓',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// 화면에는 formatValue·format이 정한 모양이 나와요. 내보낼 때만 컬럼의 export가 따로 정해요.
// - code: xlsx.text 글자 칸이라 앞자리 0이 남아요.
// - amount: format.number에서 엑셀 서식(₩ + 천 단위 + 소수 없음)을 만들고 숫자 칸으로 내보내요.
// - paidAt: xlsx.date 'text'라 이 컬럼만 날짜 칸 대신 글자예요.
// - status: export.value가 만든 글자로 CSV·엑셀·PDF에 나가요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '₩' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: '상태',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? '입금 완료' : '미입금') },
},
{ id: 'paidAt', title: '일자', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('거래처-입금.xlsx', { sheetName: '입금' });
say({ ko: 'xlsx를 내려받았어요.', en: 'Downloaded the xlsx.' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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">
<button type="button" :disabled="!api" @click="api && actions.preview(api)">CSV 미리보기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.download(api)"
>xlsx 내려받기</button>
</div>
<Grid style="height: 230px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: '한빛푸드',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: '소나무철물',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: '파란마켓',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// 화면에는 formatValue·format이 정한 모양이 나와요. 내보낼 때만 컬럼의 export가 따로 정해요.
// - code: xlsx.text 글자 칸이라 앞자리 0이 남아요.
// - amount: format.number에서 엑셀 서식(₩ + 천 단위 + 소수 없음)을 만들고 숫자 칸으로 내보내요.
// - paidAt: xlsx.date 'text'라 이 컬럼만 날짜 칸 대신 글자예요.
// - status: export.value가 만든 글자로 CSV·엑셀·PDF에 나가요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '₩' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: '상태',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? '입금 완료' : '미입금') },
},
{ id: 'paidAt', title: '일자', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('거래처-입금.xlsx', { sheetName: '입금' });
say({ ko: 'xlsx를 내려받았어요.', en: 'Downloaded the xlsx.' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.preview(api)"
>CSV 미리보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.download(api)"
>xlsx 내려받기</button>
</div>
<mx-grid style="height: 230px" [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 { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: '한빛푸드',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: '소나무철물',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: '파란마켓',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// 화면에는 formatValue·format이 정한 모양이 나와요. 내보낼 때만 컬럼의 export가 따로 정해요.
// - code: xlsx.text 글자 칸이라 앞자리 0이 남아요.
// - amount: format.number에서 엑셀 서식(₩ + 천 단위 + 소수 없음)을 만들고 숫자 칸으로 내보내요.
// - paidAt: xlsx.date 'text'라 이 컬럼만 날짜 칸 대신 글자예요.
// - status: export.value가 만든 글자로 CSV·엑셀·PDF에 나가요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: '거래처', width: 120 },
{
id: 'amount',
title: '금액',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '₩' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: '상태',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? '입금 완료' : '미입금') },
},
{ id: 'paidAt', title: '일자', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('거래처-입금.xlsx', { sheetName: '입금' });
say({ ko: 'xlsx를 내려받았어요.', en: 'Downloaded the xlsx.' });
},
}; 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">
<button type="button" id="preview">CSV preview</button>
<button type="button" id="download">Download xlsx</button>
</div>
<div id="grid" style="height: 230px"></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('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const rows = [
{
id: 1,
code: '00127',
name: 'Harbor Foods',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: 'Pine Hardware',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: 'Blue Market',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// The screen shows the look set by formatValue and format. Only on export, the column's export option decides separately.
// - code: xlsx.text makes it a text cell, so leading zeros stay.
// - amount: format.number builds the Excel format ($ + thousands separator + no decimals) and exports a number cell.
// - paidAt: xlsx.date 'text' makes only this column text instead of a date cell.
// - status: export.value produces the text used in CSV, Excel and PDF.
export const options = {
columns: [
{ id: 'code', title: 'Code', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: 'Customer', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '$' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: 'Status',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? 'Paid' : 'Unpaid') },
},
{ id: 'paidAt', title: 'Date', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
export function setup(api, log) {
say = log;
withExport(api);
}
export const actions = {
preview: (api) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api) => {
await withExport(api).downloadXlsx('customer-payments.xlsx', { sheetName: 'Payments' });
say('Downloaded the xlsx.');
},
};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>Set the export behavior per column</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="preview">CSV preview</button>
<button type="button" id="download">Download xlsx</button>
</div>
<div id="grid" style="height: 230px"></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 { withExport } = MaxGridExport;
const rows = [
{
id: 1,
code: '00127',
name: 'Harbor Foods',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: 'Pine Hardware',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: 'Blue Market',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// The screen shows the look set by formatValue and format. Only on export, the column's export option decides separately.
// - code: xlsx.text makes it a text cell, so leading zeros stay.
// - amount: format.number builds the Excel format ($ + thousands separator + no decimals) and exports a number cell.
// - paidAt: xlsx.date 'text' makes only this column text instead of a date cell.
// - status: export.value produces the text used in CSV, Excel and PDF.
const options = {
columns: [
{ id: 'code', title: 'Code', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: 'Customer', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '$' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: 'Status',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? 'Paid' : 'Unpaid') },
},
{ id: 'paidAt', title: 'Date', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say = () => undefined;
function setup(api, log) {
say = log;
withExport(api);
}
const actions = {
preview: (api) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api) => {
await withExport(api).downloadXlsx('customer-payments.xlsx', { sheetName: 'Payments' });
say('Downloaded the xlsx.');
},
};
options.ariaLabel = "Set the export behavior per column";
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('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.preview(api)}
>CSV preview</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.download(api)}
>Download xlsx</button>
</div>
<Grid style={{ height: 230 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: 'Harbor Foods',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: 'Pine Hardware',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: 'Blue Market',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// The screen shows the look set by formatValue and format. Only on export, the column's export option decides separately.
// - code: xlsx.text makes it a text cell, so leading zeros stay.
// - amount: format.number builds the Excel format ($ + thousands separator + no decimals) and exports a number cell.
// - paidAt: xlsx.date 'text' makes only this column text instead of a date cell.
// - status: export.value produces the text used in CSV, Excel and PDF.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: 'Customer', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '$' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: 'Status',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? 'Paid' : 'Unpaid') },
},
{ id: 'paidAt', title: 'Date', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('customer-payments.xlsx', { sheetName: 'Payments' });
say('Downloaded the xlsx.');
},
}; 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">
<button type="button" :disabled="!api" @click="api && actions.preview(api)">CSV preview</button>
<button
type="button"
:disabled="!api"
@click="api && actions.download(api)"
>Download xlsx</button>
</div>
<Grid style="height: 230px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: 'Harbor Foods',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: 'Pine Hardware',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: 'Blue Market',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// The screen shows the look set by formatValue and format. Only on export, the column's export option decides separately.
// - code: xlsx.text makes it a text cell, so leading zeros stay.
// - amount: format.number builds the Excel format ($ + thousands separator + no decimals) and exports a number cell.
// - paidAt: xlsx.date 'text' makes only this column text instead of a date cell.
// - status: export.value produces the text used in CSV, Excel and PDF.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: 'Customer', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '$' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: 'Status',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? 'Paid' : 'Unpaid') },
},
{ id: 'paidAt', title: 'Date', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('customer-payments.xlsx', { sheetName: 'Payments' });
say('Downloaded the xlsx.');
},
}; 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.preview(api)"
>CSV preview</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.download(api)"
>Download xlsx</button>
</div>
<mx-grid style="height: 230px" [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 { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
code: string;
name: string;
amount: number;
status: 'paid' | 'open';
paidAt: Date;
}
const rows: Row[] = [
{
id: 1,
code: '00127',
name: 'Harbor Foods',
amount: 1250000,
status: 'paid',
paidAt: new Date(2026, 9, 2),
},
{
id: 2,
code: '00342',
name: 'Pine Hardware',
amount: 842500,
status: 'open',
paidAt: new Date(2026, 9, 9),
},
{
id: 3,
code: '01008',
name: 'Blue Market',
amount: 56000,
status: 'paid',
paidAt: new Date(2026, 9, 16),
},
];
// The screen shows the look set by formatValue and format. Only on export, the column's export option decides separately.
// - code: xlsx.text makes it a text cell, so leading zeros stay.
// - amount: format.number builds the Excel format ($ + thousands separator + no decimals) and exports a number cell.
// - paidAt: xlsx.date 'text' makes only this column text instead of a date cell.
// - status: export.value produces the text used in CSV, Excel and PDF.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90, export: { xlsx: { text: true } } },
{ id: 'name', title: 'Customer', width: 120 },
{
id: 'amount',
title: 'Amount',
kind: 'number',
width: 120,
align: 'end',
format: { number: { decimals: 0, grouping: true, prefix: '$' } },
export: { xlsx: { numeric: true } },
},
{
id: 'status',
title: 'Status',
width: 90,
formatValue: (v) => (v === 'paid' ? '●' : '○'),
export: { value: (v) => (v === 'paid' ? 'Paid' : 'Unpaid') },
},
{ id: 'paidAt', title: 'Date', kind: 'date', width: 110, export: { xlsx: { date: 'text' } } },
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
preview: (api: GridApi<Row>) => {
const csv = withExport(api).exportCsv({ bom: false, newline: '\n' });
say(csv.split('\n').join(' | '));
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('customer-payments.xlsx', { sheetName: 'Payments' });
say('Downloaded the xlsx.');
},
};