셀 메모를 시트 메모로 내려받기Download cell notes as Excel notes
화면의 셀 메모를 엑셀 메모(주석)로 담아서 내려받아요.Download the cell notes on screen as Excel notes (comments).
코드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="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>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));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.`,
});
} 이 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="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>
<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 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를 주면 엑셀 메모(주석)로 내려가요.
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 = () => { };
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'})`,
});
},
};
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.`,
});
}
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('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));
</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.notes(api, event.target.value)}
>
<option value="yes">넣기</option>
<option value="no">빼기</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>메모 더하기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.download(api)}
>내려받기</button>
</div>
<Grid style={{ height: 300 }} 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;
name: string;
team: string;
score: number;
}
const names = ['김하늘', '이도윤', '박서연', '최민재', '정유나', '한지우'];
const teams = ['개발', '디자인', '영업', '인사'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// 셀 메모(cellNotes)는 화면에서 보이는 그대로, notes: true를 주면 엑셀 메모(주석)로 내려가요.
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', '새로 단 메모예요.');
say({
ko: `메모를 더했어요. 지금 메모 ${api.getCellNotes().length}개`,
en: `Note added. ${api.getCellNotes().length} notes now`,
});
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
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.`,
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.notes(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>넣기</option>
<option value="no">빼기</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">메모 더하기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.download(api)"
>내려받기</button>
</div>
<Grid style="height: 300px" :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;
name: string;
team: string;
score: number;
}
const names = ['김하늘', '이도윤', '박서연', '최민재', '정유나', '한지우'];
const teams = ['개발', '디자인', '영업', '인사'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// 셀 메모(cellNotes)는 화면에서 보이는 그대로, notes: true를 주면 엑셀 메모(주석)로 내려가요.
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', '새로 단 메모예요.');
say({
ko: `메모를 더했어요. 지금 메모 ${api.getCellNotes().length}개`,
en: `Note added. ${api.getCellNotes().length} notes now`,
});
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
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.`,
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.notes(api, $any($event.target).value)"
>
<option value="yes" selected>넣기</option>
<option value="no">빼기</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>메모 더하기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.download(api)"
>내려받기</button>
</div>
<mx-grid style="height: 300px" [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;
name: string;
team: string;
score: number;
}
const names = ['김하늘', '이도윤', '박서연', '최민재', '정유나', '한지우'];
const teams = ['개발', '디자인', '영업', '인사'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// 셀 메모(cellNotes)는 화면에서 보이는 그대로, notes: true를 주면 엑셀 메모(주석)로 내려가요.
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', '새로 단 메모예요.');
say({
ko: `메모를 더했어요. 지금 메모 ${api.getCellNotes().length}개`,
en: `Note added. ${api.getCellNotes().length} notes now`,
});
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
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.`,
});
} 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="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>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));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.`);
}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>Download cell notes as Excel notes</title>
</head>
<body>
<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>
<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 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).
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 = () => { };
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'})`);
},
};
function setup(api, log) {
say = log;
withExport(api);
log(`There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`);
}
options.ariaLabel = "Download cell notes as Excel notes";
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('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));
</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="Excel notes"
disabled={!api}
onChange={(event) => api && actions.notes(api, event.target.value)}
>
<option value="yes">Include</option>
<option value="no">Exclude</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>Add a note</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.download(api)}
>Download</button>
</div>
<Grid style={{ height: 300 }} 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;
name: string;
team: string;
score: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hart',
'Mason Clark',
'Ava Brooks',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// Cell notes (cellNotes) show on screen; notes: true writes them as Excel notes (comments).
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', 'A newly added note.');
say(`Note added. ${api.getCellNotes().length} notes now`);
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(`There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`);
} 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="Excel notes"
:disabled="!api"
@change="api && actions.notes(api, ($event.target as HTMLSelectElement).value)"
>
<option value="yes" selected>Include</option>
<option value="no">Exclude</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">Add a note</button>
<button
type="button"
:disabled="!api"
@click="api && actions.download(api)"
>Download</button>
</div>
<Grid style="height: 300px" :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;
name: string;
team: string;
score: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hart',
'Mason Clark',
'Ava Brooks',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// Cell notes (cellNotes) show on screen; notes: true writes them as Excel notes (comments).
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', 'A newly added note.');
say(`Note added. ${api.getCellNotes().length} notes now`);
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(`There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`);
} 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="Excel notes"
[disabled]="!api"
(change)="api && actions.notes(api, $any($event.target).value)"
>
<option value="yes" selected>Include</option>
<option value="no">Exclude</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>Add a note</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.download(api)"
>Download</button>
</div>
<mx-grid style="height: 300px" [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;
name: string;
team: string;
score: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hart',
'Mason Clark',
'Ava Brooks',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const rows: Row[] = Array.from({ length: 6 }, (_, i) => ({
id: i + 1,
name: names[i] as string,
team: teams[i % teams.length] as string,
score: 70 + ((i * 9) % 30),
}));
// Cell notes (cellNotes) show on screen; notes: true writes them as Excel notes (comments).
export const options: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export const actions = {
notes: (_api: GridApi<Row>, v?: string) => void (withNotes = v !== 'no'),
add: (api: GridApi<Row>) => {
api.setCellNote(2, 'score', 'A newly added note.');
say(`Note added. ${api.getCellNotes().length} notes now`);
},
download: async (api: GridApi<Row>) => {
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: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(`There are ${api.getCellNotes().length} cell notes. With notes on they become Excel notes.`);
}