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

표 위에 제목 줄 넣기Add a title above the table

표 밖 칸에 제목과 작성일을 쓰고 표를 몇 줄 아래에서 시작해 내려받아요.Write a title and date outside the table and start the table a few rows lower.

활용Intermediate
직접 써 보기Live preview표 위에 제목 줄 넣기Add a title above the table

코드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">
    <input type="text" aria-label="제목" placeholder="제목 (비우면 기본)" id="title" />
    <select aria-label="표 시작 줄" id="start">
      <option value="r1">1줄 (겹침 오류)</option>
      <option value="r3" selected>3줄</option>
      <option value="r5">5줄</option>
    </select>
    <button type="button" id="download">내려받기</button>
  </div>
  <div id="grid" style="height: 300px"></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('title').addEventListener('input', (event) => actions.title(api, event.target.value));
document.getElementById('start').addEventListener('change', (event) => actions.start(api, event.target.value));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
import { withExport } from '@maxgrid/export';
const regions = ['서울', '부산', '대전', '광주', '인천'];
const rows = regions.map((region, i) => ({
  id: i + 1,
  region,
  sales: 8200 + i * 1350,
  target: 9000 + i * 900,
}));
export const options = {
  columns: [
    { id: 'region', title: '지역', width: 100 },
    { id: 'sales', title: '매출(만원)', kind: 'number', width: 110, align: 'end' },
    { id: 'target', title: '목표(만원)', kind: 'number', width: 110, align: 'end' },
  ],
  rows,
  rowKey: 'id',
};
let title = '지역별 매출 보고';
let startRow = 3;
let say = () => { };
export const actions = {
  title: (_api, v) => void (title = (v ?? '').trim() || '지역별 매출 보고'),
  start: (_api, v) => void (startRow = Number((v ?? 'r3').slice(1))),
  download: async (api) => {
    const ex = withExport(api);
    // 제목·작성일은 표 밖 칸이에요. startRow가 3보다 작으면 표와 겹쳐서 오류가 나요.
    const o = {
      startRow,
      extraCells: [
        { ref: 'A1', value: title, style: { bold: true, color: '#1F4E79', fill: '#DDEBF7' } },
        { ref: 'A2', value: new Date(2026, 10, 25), style: { numFmt: 'yyyy-mm-dd' } },
      ],
    };
    try {
      await ex.downloadXlsx('매출-제목.xlsx', o);
      say({
        ko: `내려받았어요. 제목 A1 · 작성일 A2 · 표는 ${startRow}줄부터`,
        en: `Downloaded. Title A1 · date A2 · table starts at row ${startRow}`,
      });
    }
    catch (e) {
      say({
        ko: `내려받지 못했어요: ${e.message}`,
        en: `Could not download: ${e.message}`,
      });
    }
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log({
    ko: '표 위 1·2줄에 제목과 작성일을 쓰고 표는 3줄부터 시작해요. 시작 줄을 1로 바꾸면 겹침 오류를 볼 수 있어요.',
    en: 'A title and date go in rows 1 and 2 and the table starts at row 3. Set the start row to 1 to see the overlap error.',
  });
}

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">
    <input
      type="text"
      aria-label="Title"
      placeholder="Title (blank = default)"
      id="title"
    />
    <select aria-label="Table start row" id="start">
      <option value="r1">Row 1 (overlap error)</option>
      <option value="r3" selected>Row 3</option>
      <option value="r5">Row 5</option>
    </select>
    <button type="button" id="download">Download</button>
  </div>
  <div id="grid" style="height: 300px"></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('title').addEventListener('input', (event) => actions.title(api, event.target.value));
document.getElementById('start').addEventListener('change', (event) => actions.start(api, event.target.value));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
import { withExport } from '@maxgrid/export';
const regions = ['New York', 'Chicago', 'Dallas', 'Denver', 'Seattle'];
const rows = regions.map((region, i) => ({
  id: i + 1,
  region,
  sales: (8200 + i * 1350) / 1000,
  target: (9000 + i * 900) / 1000,
}));
export const options = {
  columns: [
    { id: 'region', title: 'Region', width: 100 },
    { id: 'sales', title: 'Sales ($K)', kind: 'number', width: 110, align: 'end' },
    { id: 'target', title: 'Target ($K)', kind: 'number', width: 110, align: 'end' },
  ],
  rows,
  rowKey: 'id',
};
let title = 'Sales by region';
let startRow = 3;
let say = () => { };
export const actions = {
  title: (_api, v) => void (title = (v ?? '').trim() || 'Sales by region'),
  start: (_api, v) => void (startRow = Number((v ?? 'r3').slice(1))),
  download: async (api) => {
    const ex = withExport(api);
    // The title and date are cells outside the table. A startRow below 3 overlaps the table and throws.
    const o = {
      startRow,
      extraCells: [
        { ref: 'A1', value: title, style: { bold: true, color: '#1F4E79', fill: '#DDEBF7' } },
        { ref: 'A2', value: new Date(2026, 10, 25), style: { numFmt: 'yyyy-mm-dd' } },
      ],
    };
    try {
      await ex.downloadXlsx('sales-title.xlsx', o);
      say(`Downloaded. Title A1 · date A2 · table starts at row ${startRow}`);
    }
    catch (e) {
      say(`Could not download: ${e.message}`);
    }
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log('A title and date go in rows 1 and 2 and the table starts at row 3. Set the start row to 1 to see the overlap error.');
}