본문으로 건너뛰기Skip to content
예제 첫화면Examples home

컬럼마다 내보내기 방식 정하기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.

활용Intermediate
직접 써 보기Live preview컬럼마다 내보내기 방식 정하기Set the export behavior per column

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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.' });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

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.

index.html
<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>
main.js
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));
example.js
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.');
  },
};