시트 보호하기Protect the Excel sheet
잠글 컬럼과 암호를 정해서 실수로 고치는 것을 막는 시트로 내려받아요.Choose the locked columns and a password to download a sheet that guards against accidental edits.
코드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="locked">
<option value="codes" selected>코드·품목</option>
<option value="none">코드만</option>
<option value="all">모두</option>
</select>
<input
type="text"
aria-label="암호"
placeholder="암호 (비우면 없음)"
id="password"
/>
<select aria-label="정렬 허용" id="sort">
<option value="no" selected>안 함</option>
<option value="yes">허용</option>
</select>
<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('locked').addEventListener('change', (event) => actions.locked(api, event.target.value));
document.getElementById('password').addEventListener('input', (event) => actions.password(api, event.target.value));
document.getElementById('sort').addEventListener('change', (event) => actions.sort(api, event.target.value));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const names = ['A4 용지', '토너', '마우스', '키보드', '모니터 받침대', '멀티탭'];
const rows = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// 시트 보호(protect)는 실수로 고치는 것을 막을 뿐 보안이 아니에요. 암호는 엑셀의 옛 해시라서 누구나 쉽게 풀 수 있어요.
export const options = {
columns: [
{ id: 'code', title: '코드', width: 90 },
{ id: 'name', title: '품목', width: 140 },
{ id: 'qty', title: '재고', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: '메모', width: 160 },
],
rows,
rowKey: 'id',
};
const locks = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say = () => { };
export const actions = {
locked: (_api, v) => void (locked = v ?? 'codes'),
password: (_api, v) => void (password = (v ?? '').trim()),
sort: (_api, v) => void (sort = v === 'yes'),
download: async (api) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(없음)';
await ex.downloadXlsx('재고-보호.xlsx', { protect });
say({
ko: `내려받았어요. 잠금 컬럼 ${protect.lockedColumns?.join(', ') ?? '전체'} · 암호 ${password ? '있음' : '없음'} · 보호 태그 ${tag}`,
en: `Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
});
},
};
export function setup(api, log) {
say = log;
withExport(api);
log({
ko: '코드·품목만 잠그고 재고·메모는 고칠 수 있게 내려받아요. 보안이 아니라 실수 방지예요.',
en: 'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
});
} 이 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="locked">
<option value="codes" selected>코드·품목</option>
<option value="none">코드만</option>
<option value="all">모두</option>
</select>
<input
type="text"
aria-label="암호"
placeholder="암호 (비우면 없음)"
id="password"
/>
<select aria-label="정렬 허용" id="sort">
<option value="no" selected>안 함</option>
<option value="yes">허용</option>
</select>
<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 = ['A4 용지', '토너', '마우스', '키보드', '모니터 받침대', '멀티탭'];
const rows = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// 시트 보호(protect)는 실수로 고치는 것을 막을 뿐 보안이 아니에요. 암호는 엑셀의 옛 해시라서 누구나 쉽게 풀 수 있어요.
const options = {
columns: [
{ id: 'code', title: '코드', width: 90 },
{ id: 'name', title: '품목', width: 140 },
{ id: 'qty', title: '재고', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: '메모', width: 160 },
],
rows,
rowKey: 'id',
};
const locks = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say = () => { };
const actions = {
locked: (_api, v) => void (locked = v ?? 'codes'),
password: (_api, v) => void (password = (v ?? '').trim()),
sort: (_api, v) => void (sort = v === 'yes'),
download: async (api) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(없음)';
await ex.downloadXlsx('재고-보호.xlsx', { protect });
say({
ko: `내려받았어요. 잠금 컬럼 ${protect.lockedColumns?.join(', ') ?? '전체'} · 암호 ${password ? '있음' : '없음'} · 보호 태그 ${tag}`,
en: `Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
});
},
};
function setup(api, log) {
say = log;
withExport(api);
log({
ko: '코드·품목만 잠그고 재고·메모는 고칠 수 있게 내려받아요. 보안이 아니라 실수 방지예요.',
en: 'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
});
}
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('locked').addEventListener('change', (event) => actions.locked(api, event.target.value));
document.getElementById('password').addEventListener('input', (event) => actions.password(api, event.target.value));
document.getElementById('sort').addEventListener('change', (event) => actions.sort(api, event.target.value));
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.locked(api, event.target.value)}
>
<option value="codes">코드·품목</option>
<option value="none">코드만</option>
<option value="all">모두</option>
</select>
<input
type="text"
aria-label="암호"
placeholder="암호 (비우면 없음)"
disabled={!api}
onChange={(event) => api && actions.password(api, event.target.value)}
/>
<select defaultValue="codes"
aria-label="정렬 허용"
disabled={!api}
onChange={(event) => api && actions.sort(api, event.target.value)}
>
<option value="no">안 함</option>
<option value="yes">허용</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 용지', '토너', '마우스', '키보드', '모니터 받침대', '멀티탭'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// 시트 보호(protect)는 실수로 고치는 것을 막을 뿐 보안이 아니에요. 암호는 엑셀의 옛 해시라서 누구나 쉽게 풀 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90 },
{ id: 'name', title: '품목', width: 140 },
{ id: 'qty', title: '재고', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: '메모', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(없음)';
await ex.downloadXlsx('재고-보호.xlsx', { protect });
say({
ko: `내려받았어요. 잠금 컬럼 ${protect.lockedColumns?.join(', ') ?? '전체'} · 암호 ${password ? '있음' : '없음'} · 보호 태그 ${tag}`,
en: `Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
});
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log({
ko: '코드·품목만 잠그고 재고·메모는 고칠 수 있게 내려받아요. 보안이 아니라 실수 방지예요.',
en: 'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.locked(api, ($event.target as HTMLSelectElement).value)"
>
<option value="codes" selected>코드·품목</option>
<option value="none">코드만</option>
<option value="all">모두</option>
</select>
<input
type="text"
aria-label="암호"
placeholder="암호 (비우면 없음)"
:disabled="!api"
@input="api && actions.password(api, ($event.target as HTMLInputElement).value)"
/>
<select
aria-label="정렬 허용"
:disabled="!api"
@change="api && actions.sort(api, ($event.target as HTMLSelectElement).value)"
>
<option value="no" selected>안 함</option>
<option value="yes">허용</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 용지', '토너', '마우스', '키보드', '모니터 받침대', '멀티탭'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// 시트 보호(protect)는 실수로 고치는 것을 막을 뿐 보안이 아니에요. 암호는 엑셀의 옛 해시라서 누구나 쉽게 풀 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90 },
{ id: 'name', title: '품목', width: 140 },
{ id: 'qty', title: '재고', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: '메모', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(없음)';
await ex.downloadXlsx('재고-보호.xlsx', { protect });
say({
ko: `내려받았어요. 잠금 컬럼 ${protect.lockedColumns?.join(', ') ?? '전체'} · 암호 ${password ? '있음' : '없음'} · 보호 태그 ${tag}`,
en: `Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
});
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log({
ko: '코드·품목만 잠그고 재고·메모는 고칠 수 있게 내려받아요. 보안이 아니라 실수 방지예요.',
en: 'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.locked(api, $any($event.target).value)"
>
<option value="codes" selected>코드·품목</option>
<option value="none">코드만</option>
<option value="all">모두</option>
</select>
<input
type="text"
aria-label="암호"
placeholder="암호 (비우면 없음)"
[disabled]="!api"
(input)="api && actions.password(api, $any($event.target).value)"
/>
<select
aria-label="정렬 허용"
[disabled]="!api"
(change)="api && actions.sort(api, $any($event.target).value)"
>
<option value="no" selected>안 함</option>
<option value="yes">허용</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 용지', '토너', '마우스', '키보드', '모니터 받침대', '멀티탭'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// 시트 보호(protect)는 실수로 고치는 것을 막을 뿐 보안이 아니에요. 암호는 엑셀의 옛 해시라서 누구나 쉽게 풀 수 있어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: '코드', width: 90 },
{ id: 'name', title: '품목', width: 140 },
{ id: 'qty', title: '재고', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: '메모', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(없음)';
await ex.downloadXlsx('재고-보호.xlsx', { protect });
say({
ko: `내려받았어요. 잠금 컬럼 ${protect.lockedColumns?.join(', ') ?? '전체'} · 암호 ${password ? '있음' : '없음'} · 보호 태그 ${tag}`,
en: `Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
});
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log({
ko: '코드·품목만 잠그고 재고·메모는 고칠 수 있게 내려받아요. 보안이 아니라 실수 방지예요.',
en: 'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
});
} 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="Locked columns" id="locked">
<option value="codes" selected>Code and item</option>
<option value="none">Code only</option>
<option value="all">All</option>
</select>
<input
type="text"
aria-label="Password"
placeholder="Password (blank = none)"
id="password"
/>
<select aria-label="Allow sort" id="sort">
<option value="no" selected>No</option>
<option value="yes">Yes</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>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('locked').addEventListener('change', (event) => actions.locked(api, event.target.value));
document.getElementById('password').addEventListener('input', (event) => actions.password(api, event.target.value));
document.getElementById('sort').addEventListener('change', (event) => actions.sort(api, event.target.value));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const names = ['A4 paper', 'Toner', 'Mouse', 'Keyboard', 'Monitor stand', 'Power strip'];
const rows = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// Sheet protection (protect) only prevents slips; it is not security. The password uses Excel's old hash, so anyone can remove it.
export const options = {
columns: [
{ id: 'code', title: 'Code', width: 90 },
{ id: 'name', title: 'Item', width: 140 },
{ id: 'qty', title: 'Stock', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: 'Memo', width: 160 },
],
rows,
rowKey: 'id',
};
const locks = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say = () => { };
export const actions = {
locked: (_api, v) => void (locked = v ?? 'codes'),
password: (_api, v) => void (password = (v ?? '').trim()),
sort: (_api, v) => void (sort = v === 'yes'),
download: async (api) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(none)';
await ex.downloadXlsx('stock-protected.xlsx', { protect });
say(`Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`);
},
};
export function setup(api, log) {
say = log;
withExport(api);
log('Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.');
}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>Protect the Excel sheet</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Locked columns" id="locked">
<option value="codes" selected>Code and item</option>
<option value="none">Code only</option>
<option value="all">All</option>
</select>
<input
type="text"
aria-label="Password"
placeholder="Password (blank = none)"
id="password"
/>
<select aria-label="Allow sort" id="sort">
<option value="no" selected>No</option>
<option value="yes">Yes</option>
</select>
<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 = ['A4 paper', 'Toner', 'Mouse', 'Keyboard', 'Monitor stand', 'Power strip'];
const rows = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// Sheet protection (protect) only prevents slips; it is not security. The password uses Excel's old hash, so anyone can remove it.
const options = {
columns: [
{ id: 'code', title: 'Code', width: 90 },
{ id: 'name', title: 'Item', width: 140 },
{ id: 'qty', title: 'Stock', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: 'Memo', width: 160 },
],
rows,
rowKey: 'id',
};
const locks = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say = () => { };
const actions = {
locked: (_api, v) => void (locked = v ?? 'codes'),
password: (_api, v) => void (password = (v ?? '').trim()),
sort: (_api, v) => void (sort = v === 'yes'),
download: async (api) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(none)';
await ex.downloadXlsx('stock-protected.xlsx', { protect });
say(`Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`);
},
};
function setup(api, log) {
say = log;
withExport(api);
log('Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.');
}
options.ariaLabel = "Protect the Excel sheet";
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('locked').addEventListener('change', (event) => actions.locked(api, event.target.value));
document.getElementById('password').addEventListener('input', (event) => actions.password(api, event.target.value));
document.getElementById('sort').addEventListener('change', (event) => actions.sort(api, event.target.value));
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="Locked columns"
disabled={!api}
onChange={(event) => api && actions.locked(api, event.target.value)}
>
<option value="codes">Code and item</option>
<option value="none">Code only</option>
<option value="all">All</option>
</select>
<input
type="text"
aria-label="Password"
placeholder="Password (blank = none)"
disabled={!api}
onChange={(event) => api && actions.password(api, event.target.value)}
/>
<select defaultValue="codes"
aria-label="Allow sort"
disabled={!api}
onChange={(event) => api && actions.sort(api, event.target.value)}
>
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 paper', 'Toner', 'Mouse', 'Keyboard', 'Monitor stand', 'Power strip'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// Sheet protection (protect) only prevents slips; it is not security. The password uses Excel's old hash, so anyone can remove it.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90 },
{ id: 'name', title: 'Item', width: 140 },
{ id: 'qty', title: 'Stock', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: 'Memo', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(none)';
await ex.downloadXlsx('stock-protected.xlsx', { protect });
say(
`Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
);
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(
'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
);
} 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="Locked columns"
:disabled="!api"
@change="api && actions.locked(api, ($event.target as HTMLSelectElement).value)"
>
<option value="codes" selected>Code and item</option>
<option value="none">Code only</option>
<option value="all">All</option>
</select>
<input
type="text"
aria-label="Password"
placeholder="Password (blank = none)"
:disabled="!api"
@input="api && actions.password(api, ($event.target as HTMLInputElement).value)"
/>
<select
aria-label="Allow sort"
:disabled="!api"
@change="api && actions.sort(api, ($event.target as HTMLSelectElement).value)"
>
<option value="no" selected>No</option>
<option value="yes">Yes</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 paper', 'Toner', 'Mouse', 'Keyboard', 'Monitor stand', 'Power strip'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// Sheet protection (protect) only prevents slips; it is not security. The password uses Excel's old hash, so anyone can remove it.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90 },
{ id: 'name', title: 'Item', width: 140 },
{ id: 'qty', title: 'Stock', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: 'Memo', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(none)';
await ex.downloadXlsx('stock-protected.xlsx', { protect });
say(
`Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
);
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(
'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
);
} 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="Locked columns"
[disabled]="!api"
(change)="api && actions.locked(api, $any($event.target).value)"
>
<option value="codes" selected>Code and item</option>
<option value="none">Code only</option>
<option value="all">All</option>
</select>
<input
type="text"
aria-label="Password"
placeholder="Password (blank = none)"
[disabled]="!api"
(input)="api && actions.password(api, $any($event.target).value)"
/>
<select
aria-label="Allow sort"
[disabled]="!api"
(change)="api && actions.sort(api, $any($event.target).value)"
>
<option value="no" selected>No</option>
<option value="yes">Yes</option>
</select>
<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;
code: string;
name: string;
qty: number;
memo: string;
}
const names = ['A4 paper', 'Toner', 'Mouse', 'Keyboard', 'Monitor stand', 'Power strip'];
const rows: Row[] = names.map((name, i) => ({
id: i + 1,
code: `ST-${100 + i}`,
name,
qty: 10 + i * 6,
memo: '',
}));
// Sheet protection (protect) only prevents slips; it is not security. The password uses Excel's old hash, so anyone can remove it.
export const options: GridOptions<Row> = {
columns: [
{ id: 'code', title: 'Code', width: 90 },
{ id: 'name', title: 'Item', width: 140 },
{ id: 'qty', title: 'Stock', kind: 'number', width: 80, align: 'end' },
{ id: 'memo', title: 'Memo', width: 160 },
],
rows,
rowKey: 'id',
};
const locks: Record<string, string[] | undefined> = {
all: undefined,
codes: ['code', 'name'],
none: ['code'],
};
let locked = 'codes';
let password = '';
let sort = false;
let say: (message: LogText) => void = () => {};
export const actions = {
locked: (_api: GridApi<Row>, v?: string) => void (locked = v ?? 'codes'),
password: (_api: GridApi<Row>, v?: string) => void (password = (v ?? '').trim()),
sort: (_api: GridApi<Row>, v?: string) => void (sort = v === 'yes'),
download: async (api: GridApi<Row>) => {
const ex = withExport(api);
const protect = {
...(password ? { password } : {}),
...(locks[locked] ? { lockedColumns: locks[locked] } : {}),
allowSort: sort,
};
const text = new TextDecoder('utf-8').decode(ex.exportXlsx({ protect }));
const tag = /<sheetProtection[^>]*>/.exec(text)?.[0] ?? '(none)';
await ex.downloadXlsx('stock-protected.xlsx', { protect });
say(
`Downloaded. Locked columns ${protect.lockedColumns?.join(', ') ?? 'all'} · password ${password ? 'set' : 'none'} · tag ${tag}`,
);
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
log(
'Downloads with only code and item locked; stock and memo stay editable. This prevents slips, it is not security.',
);
}