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

셀 메모를 시트 메모로 내려받기Download cell notes as Excel notes

화면의 셀 메모를 엑셀 메모(주석)로 담아서 내려받아요.Download the cell notes on screen as Excel notes (comments).

활용Intermediate
직접 써 보기Live preview셀 메모를 시트 메모로 내려받기Download cell notes as Excel notes

코드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">
    <select aria-label="엑셀 메모" id="notes">
      <option value="yes" selected>넣기</option>
      <option value="no">빼기</option>
    </select>
    <button type="button" id="add">메모 더하기</button>
    <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('notes').addEventListener('change', (event) => actions.notes(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
import { withExport } from '@maxgrid/export';
const names = ['김하늘', '이도윤', '박서연', '최민재', '정유나', '한지우'];
const teams = ['개발', '디자인', '영업', '인사'];
const rows = Array.from({ length: 6 }, (_, i) => ({
  id: i + 1,
  name: names[i],
  team: teams[i % teams.length],
  score: 70 + ((i * 9) % 30),
}));
// 셀 메모(cellNotes)는 화면에서 보이는 그대로, notes: true를 주면 엑셀 메모(주석)로 내려가요.
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 110 },
    { id: 'team', title: '팀', width: 90 },
    { id: 'score', title: '점수', kind: 'number', width: 80, align: 'end' },
  ],
  rows,
  rowKey: 'id',
  cellNotes: [
    { rowKey: 1, columnId: 'score', text: '재평가 후 5점 올랐어요.' },
    { rowKey: 3, columnId: 'name', text: '휴직 예정: 12월 복귀' },
    { rowKey: 5, columnId: 'team', text: '영업팀에서 옮겨 왔어요.' },
  ],
};
let withNotes = true;
let say = () => { };
export const actions = {
  notes: (_api, v) => void (withNotes = v !== 'no'),
  add: (api) => {
    api.setCellNote(2, 'score', '새로 단 메모예요.');
    say({
      ko: `메모를 더했어요. 지금 메모 ${api.getCellNotes().length}개`,
      en: `Note added. ${api.getCellNotes().length} notes now`,
    });
  },
  download: async (api) => {
    const ex = withExport(api);
    const o = { notes: withNotes };
    const text = new TextDecoder('utf-8').decode(ex.exportXlsx(o));
    const count = (text.match(/<comment /g) ?? []).length;
    await ex.downloadXlsx('평가-메모.xlsx', o);
    say({
      ko: `내려받았어요. 엑셀 메모 ${count}개 (notes ${withNotes ? '켬' : '끔'})`,
      en: `Downloaded. ${count} Excel notes (notes ${withNotes ? 'on' : 'off'})`,
    });
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log({
    ko: `셀 메모 ${api.getCellNotes().length}개가 있어요. notes를 켜면 엑셀 메모로 내려가요.`,
    en: `There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`,
  });
}

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">
    <select aria-label="Excel notes" id="notes">
      <option value="yes" selected>Include</option>
      <option value="no">Exclude</option>
    </select>
    <button type="button" id="add">Add a note</button>
    <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('notes').addEventListener('change', (event) => actions.notes(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
import { withExport } from '@maxgrid/export';
const names = [
  'Liam Carter',
  'Emma Stone',
  'Noah Reed',
  'Olivia Hart',
  'Mason Clark',
  'Ava Brooks',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const rows = Array.from({ length: 6 }, (_, i) => ({
  id: i + 1,
  name: names[i],
  team: teams[i % teams.length],
  score: 70 + ((i * 9) % 30),
}));
// Cell notes (cellNotes) show on screen; notes: true writes them as Excel notes (comments).
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 110 },
    { id: 'team', title: 'Team', width: 90 },
    { id: 'score', title: 'Score', kind: 'number', width: 80, align: 'end' },
  ],
  rows,
  rowKey: 'id',
  cellNotes: [
    { rowKey: 1, columnId: 'score', text: 'Raised by 5 points after the re-review.' },
    { rowKey: 3, columnId: 'name', text: 'On leave, back in December.' },
    { rowKey: 5, columnId: 'team', text: 'Moved over from Sales.' },
  ],
};
let withNotes = true;
let say = () => { };
export const actions = {
  notes: (_api, v) => void (withNotes = v !== 'no'),
  add: (api) => {
    api.setCellNote(2, 'score', 'A newly added note.');
    say(`Note added. ${api.getCellNotes().length} notes now`);
  },
  download: async (api) => {
    const ex = withExport(api);
    const o = { notes: withNotes };
    const text = new TextDecoder('utf-8').decode(ex.exportXlsx(o));
    const count = (text.match(/<comment /g) ?? []).length;
    await ex.downloadXlsx('review-notes.xlsx', o);
    say(`Downloaded. ${count} Excel notes (notes ${withNotes ? 'on' : 'off'})`);
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log(`There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`);
}