병합 그룹 표시를 엑셀 세로 병합으로 내보내기Export merged group display as vertical merges
grouping.merged로 보이는 그룹 컬럼을 mergedGroups: true로 내려받으면 그룹의 줄들에 걸친 세로 병합 셀로 나가요. 값은 첫 칸에 있고 그룹 머리 줄은 없어요.With mergedGroups: true, the group columns shown by grouping.merged are exported as vertically merged cells over the group's rows. The value is in the first cell and there are no group header lines.
코드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="mode">
<option value="on" selected>그룹 칸 세로 병합</option>
<option value="off">병합 없이</option>
</select>
<button type="button" id="preview">시트 미리보기</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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const en = document.documentElement.dataset.lang === 'en';
const rows = [
{
id: 1,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Minjun Kim' : '김민준',
amount: 120,
},
{
id: 2,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Seoyeon Lee' : '이서연',
amount: 90,
},
{
id: 3,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 2' : '영업 2팀',
owner: en ? 'Jiho Park' : '박지호',
amount: 140,
},
{
id: 4,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Haneul Choi' : '최하늘',
amount: 75,
},
{
id: 5,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Daon Jung' : '정다온',
amount: 60,
},
];
// grouping.merged(1.4.0)는 그룹 컬럼을 값별로 세로 병합해 보여 줘요(그룹 머리 줄 없음).
// 엑셀에서도 같은 모양으로 받으려면 exportXlsx의 mergedGroups: true를 줘요.
export const options = {
columns: [
{ id: 'region', title: en ? 'Region' : '지역', width: 100 },
{ id: 'team', title: en ? 'Team' : '팀', width: 110 },
{ id: 'owner', title: en ? 'Owner' : '담당', width: 110 },
{ id: 'amount', title: en ? 'Amount' : '금액', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: en ? 'Merged group export' : '그룹 병합 내보내기',
};
let merged = true;
let say = () => { };
export function setup(api, log) {
say = log;
merged = true;
withExport(api);
log({
ko: '"시트 미리보기"를 누르면 병합 범위가 기록에 나와요(지역은 3줄·2줄, 팀은 2줄·1줄·2줄).',
en: 'Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).',
});
}
export const actions = {
mode: (_api, v) => void (merged = v !== 'off'),
preview: (api) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say({
ko: `병합 범위: ${refs.join(', ') || '없음'} (머리글 1줄 + 데이터 ${api.getRowCount()}줄)`,
en: `Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
});
},
download: async (api) => {
await withExport(api).downloadXlsx('그룹병합.xlsx', { mergedGroups: merged });
say({ ko: '내려받았어요.', en: 'Downloaded.' });
},
}; 이 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="mode">
<option value="on" selected>그룹 칸 세로 병합</option>
<option value="off">병합 없이</option>
</select>
<button type="button" id="preview">시트 미리보기</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 en = document.documentElement.dataset.lang === 'en';
const rows = [
{
id: 1,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Minjun Kim' : '김민준',
amount: 120,
},
{
id: 2,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Seoyeon Lee' : '이서연',
amount: 90,
},
{
id: 3,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 2' : '영업 2팀',
owner: en ? 'Jiho Park' : '박지호',
amount: 140,
},
{
id: 4,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Haneul Choi' : '최하늘',
amount: 75,
},
{
id: 5,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Daon Jung' : '정다온',
amount: 60,
},
];
// grouping.merged(1.4.0)는 그룹 컬럼을 값별로 세로 병합해 보여 줘요(그룹 머리 줄 없음).
// 엑셀에서도 같은 모양으로 받으려면 exportXlsx의 mergedGroups: true를 줘요.
const options = {
columns: [
{ id: 'region', title: en ? 'Region' : '지역', width: 100 },
{ id: 'team', title: en ? 'Team' : '팀', width: 110 },
{ id: 'owner', title: en ? 'Owner' : '담당', width: 110 },
{ id: 'amount', title: en ? 'Amount' : '금액', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: en ? 'Merged group export' : '그룹 병합 내보내기',
};
let merged = true;
let say = () => { };
function setup(api, log) {
say = log;
merged = true;
withExport(api);
log({
ko: '"시트 미리보기"를 누르면 병합 범위가 기록에 나와요(지역은 3줄·2줄, 팀은 2줄·1줄·2줄).',
en: 'Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).',
});
}
const actions = {
mode: (_api, v) => void (merged = v !== 'off'),
preview: (api) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say({
ko: `병합 범위: ${refs.join(', ') || '없음'} (머리글 1줄 + 데이터 ${api.getRowCount()}줄)`,
en: `Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
});
},
download: async (api) => {
await withExport(api).downloadXlsx('그룹병합.xlsx', { mergedGroups: merged });
say({ ko: '내려받았어요.', en: 'Downloaded.' });
},
};
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(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.mode(api, event.target.value)}
>
<option value="on">그룹 칸 세로 병합</option>
<option value="off">병합 없이</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.preview(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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{
id: 1,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Minjun Kim' : '김민준',
amount: 120,
},
{
id: 2,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Seoyeon Lee' : '이서연',
amount: 90,
},
{
id: 3,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 2' : '영업 2팀',
owner: en ? 'Jiho Park' : '박지호',
amount: 140,
},
{
id: 4,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Haneul Choi' : '최하늘',
amount: 75,
},
{
id: 5,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Daon Jung' : '정다온',
amount: 60,
},
];
// grouping.merged(1.4.0)는 그룹 컬럼을 값별로 세로 병합해 보여 줘요(그룹 머리 줄 없음).
// 엑셀에서도 같은 모양으로 받으려면 exportXlsx의 mergedGroups: true를 줘요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: en ? 'Region' : '지역', width: 100 },
{ id: 'team', title: en ? 'Team' : '팀', width: 110 },
{ id: 'owner', title: en ? 'Owner' : '담당', width: 110 },
{ id: 'amount', title: en ? 'Amount' : '금액', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: en ? 'Merged group export' : '그룹 병합 내보내기',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log({
ko: '"시트 미리보기"를 누르면 병합 범위가 기록에 나와요(지역은 3줄·2줄, 팀은 2줄·1줄·2줄).',
en: 'Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).',
});
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say({
ko: `병합 범위: ${refs.join(', ') || '없음'} (머리글 1줄 + 데이터 ${api.getRowCount()}줄)`,
en: `Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
});
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('그룹병합.xlsx', { mergedGroups: merged });
say({ ko: '내려받았어요.', en: 'Downloaded.' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>그룹 칸 세로 병합</option>
<option value="off">병합 없이</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.preview(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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{
id: 1,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Minjun Kim' : '김민준',
amount: 120,
},
{
id: 2,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Seoyeon Lee' : '이서연',
amount: 90,
},
{
id: 3,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 2' : '영업 2팀',
owner: en ? 'Jiho Park' : '박지호',
amount: 140,
},
{
id: 4,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Haneul Choi' : '최하늘',
amount: 75,
},
{
id: 5,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Daon Jung' : '정다온',
amount: 60,
},
];
// grouping.merged(1.4.0)는 그룹 컬럼을 값별로 세로 병합해 보여 줘요(그룹 머리 줄 없음).
// 엑셀에서도 같은 모양으로 받으려면 exportXlsx의 mergedGroups: true를 줘요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: en ? 'Region' : '지역', width: 100 },
{ id: 'team', title: en ? 'Team' : '팀', width: 110 },
{ id: 'owner', title: en ? 'Owner' : '담당', width: 110 },
{ id: 'amount', title: en ? 'Amount' : '금액', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: en ? 'Merged group export' : '그룹 병합 내보내기',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log({
ko: '"시트 미리보기"를 누르면 병합 범위가 기록에 나와요(지역은 3줄·2줄, 팀은 2줄·1줄·2줄).',
en: 'Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).',
});
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say({
ko: `병합 범위: ${refs.join(', ') || '없음'} (머리글 1줄 + 데이터 ${api.getRowCount()}줄)`,
en: `Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
});
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('그룹병합.xlsx', { mergedGroups: merged });
say({ ko: '내려받았어요.', en: 'Downloaded.' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.mode(api, $any($event.target).value)"
>
<option value="on" selected>그룹 칸 세로 병합</option>
<option value="off">병합 없이</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.preview(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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{
id: 1,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Minjun Kim' : '김민준',
amount: 120,
},
{
id: 2,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 1' : '영업 1팀',
owner: en ? 'Seoyeon Lee' : '이서연',
amount: 90,
},
{
id: 3,
region: en ? 'Capital area' : '수도권',
team: en ? 'Sales 2' : '영업 2팀',
owner: en ? 'Jiho Park' : '박지호',
amount: 140,
},
{
id: 4,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Haneul Choi' : '최하늘',
amount: 75,
},
{
id: 5,
region: en ? 'Southeast' : '영남',
team: en ? 'Sales 3' : '영업 3팀',
owner: en ? 'Daon Jung' : '정다온',
amount: 60,
},
];
// grouping.merged(1.4.0)는 그룹 컬럼을 값별로 세로 병합해 보여 줘요(그룹 머리 줄 없음).
// 엑셀에서도 같은 모양으로 받으려면 exportXlsx의 mergedGroups: true를 줘요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: en ? 'Region' : '지역', width: 100 },
{ id: 'team', title: en ? 'Team' : '팀', width: 110 },
{ id: 'owner', title: en ? 'Owner' : '담당', width: 110 },
{ id: 'amount', title: en ? 'Amount' : '금액', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: en ? 'Merged group export' : '그룹 병합 내보내기',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log({
ko: '"시트 미리보기"를 누르면 병합 범위가 기록에 나와요(지역은 3줄·2줄, 팀은 2줄·1줄·2줄).',
en: 'Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).',
});
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say({
ko: `병합 범위: ${refs.join(', ') || '없음'} (머리글 1줄 + 데이터 ${api.getRowCount()}줄)`,
en: `Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
});
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('그룹병합.xlsx', { mergedGroups: merged });
say({ ko: '내려받았어요.', en: 'Downloaded.' });
},
}; 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="Export shape" id="mode">
<option value="on" selected>Merge group cells</option>
<option value="off">Without merging</option>
</select>
<button type="button" id="preview">Preview sheet</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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));import { withExport } from '@maxgrid/export';
const rows = [
{ id: 1, region: 'Capital area', team: 'Sales 1', owner: 'Liam Carter', amount: 120 },
{ id: 2, region: 'Capital area', team: 'Sales 1', owner: 'Emma Stone', amount: 90 },
{ id: 3, region: 'Capital area', team: 'Sales 2', owner: 'Noah Kim', amount: 140 },
{ id: 4, region: 'Southeast', team: 'Sales 3', owner: 'Olivia Reed', amount: 75 },
{ id: 5, region: 'Southeast', team: 'Sales 3', owner: 'Ava Brooks', amount: 60 },
];
// grouping.merged (1.4.0) shows the group columns merged vertically by value (no group header row).
// To download the same shape in Excel, pass mergedGroups: true to exportXlsx.
export const options = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'owner', title: 'Owner', width: 110 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: 'Merged group export',
};
let merged = true;
let say = () => { };
export function setup(api, log) {
say = log;
merged = true;
withExport(api);
log('Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).');
}
export const actions = {
mode: (_api, v) => void (merged = v !== 'off'),
preview: (api) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say(`Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`);
},
download: async (api) => {
await withExport(api).downloadXlsx('merged-groups.xlsx', { mergedGroups: merged });
say('Downloaded.');
},
};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>Export merged group display as vertical merges</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Export shape" id="mode">
<option value="on" selected>Merge group cells</option>
<option value="off">Without merging</option>
</select>
<button type="button" id="preview">Preview sheet</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 rows = [
{ id: 1, region: 'Capital area', team: 'Sales 1', owner: 'Liam Carter', amount: 120 },
{ id: 2, region: 'Capital area', team: 'Sales 1', owner: 'Emma Stone', amount: 90 },
{ id: 3, region: 'Capital area', team: 'Sales 2', owner: 'Noah Kim', amount: 140 },
{ id: 4, region: 'Southeast', team: 'Sales 3', owner: 'Olivia Reed', amount: 75 },
{ id: 5, region: 'Southeast', team: 'Sales 3', owner: 'Ava Brooks', amount: 60 },
];
// grouping.merged (1.4.0) shows the group columns merged vertically by value (no group header row).
// To download the same shape in Excel, pass mergedGroups: true to exportXlsx.
const options = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'owner', title: 'Owner', width: 110 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: 'Merged group export',
};
let merged = true;
let say = () => { };
function setup(api, log) {
say = log;
merged = true;
withExport(api);
log('Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).');
}
const actions = {
mode: (_api, v) => void (merged = v !== 'off'),
preview: (api) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say(`Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`);
},
download: async (api) => {
await withExport(api).downloadXlsx('merged-groups.xlsx', { mergedGroups: merged });
say('Downloaded.');
},
};
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(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="Export shape"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="on">Merge group cells</option>
<option value="off">Without merging</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.preview(api)}
>Preview sheet</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;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, region: 'Capital area', team: 'Sales 1', owner: 'Liam Carter', amount: 120 },
{ id: 2, region: 'Capital area', team: 'Sales 1', owner: 'Emma Stone', amount: 90 },
{ id: 3, region: 'Capital area', team: 'Sales 2', owner: 'Noah Kim', amount: 140 },
{ id: 4, region: 'Southeast', team: 'Sales 3', owner: 'Olivia Reed', amount: 75 },
{ id: 5, region: 'Southeast', team: 'Sales 3', owner: 'Ava Brooks', amount: 60 },
];
// grouping.merged (1.4.0) shows the group columns merged vertically by value (no group header row).
// To download the same shape in Excel, pass mergedGroups: true to exportXlsx.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'owner', title: 'Owner', width: 110 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: 'Merged group export',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log('Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).');
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say(
`Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
);
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('merged-groups.xlsx', { mergedGroups: merged });
say('Downloaded.');
},
}; 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="Export shape"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>Merge group cells</option>
<option value="off">Without merging</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.preview(api)">Preview sheet</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;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, region: 'Capital area', team: 'Sales 1', owner: 'Liam Carter', amount: 120 },
{ id: 2, region: 'Capital area', team: 'Sales 1', owner: 'Emma Stone', amount: 90 },
{ id: 3, region: 'Capital area', team: 'Sales 2', owner: 'Noah Kim', amount: 140 },
{ id: 4, region: 'Southeast', team: 'Sales 3', owner: 'Olivia Reed', amount: 75 },
{ id: 5, region: 'Southeast', team: 'Sales 3', owner: 'Ava Brooks', amount: 60 },
];
// grouping.merged (1.4.0) shows the group columns merged vertically by value (no group header row).
// To download the same shape in Excel, pass mergedGroups: true to exportXlsx.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'owner', title: 'Owner', width: 110 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: 'Merged group export',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log('Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).');
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say(
`Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
);
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('merged-groups.xlsx', { mergedGroups: merged });
say('Downloaded.');
},
}; 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="Export shape"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="on" selected>Merge group cells</option>
<option value="off">Without merging</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.preview(api)"
>Preview sheet</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;
region: string;
team: string;
owner: string;
amount: number;
}
const rows: Row[] = [
{ id: 1, region: 'Capital area', team: 'Sales 1', owner: 'Liam Carter', amount: 120 },
{ id: 2, region: 'Capital area', team: 'Sales 1', owner: 'Emma Stone', amount: 90 },
{ id: 3, region: 'Capital area', team: 'Sales 2', owner: 'Noah Kim', amount: 140 },
{ id: 4, region: 'Southeast', team: 'Sales 3', owner: 'Olivia Reed', amount: 75 },
{ id: 5, region: 'Southeast', team: 'Sales 3', owner: 'Ava Brooks', amount: 60 },
];
// grouping.merged (1.4.0) shows the group columns merged vertically by value (no group header row).
// To download the same shape in Excel, pass mergedGroups: true to exportXlsx.
export const options: GridOptions<Row> = {
columns: [
{ id: 'region', title: 'Region', width: 110 },
{ id: 'team', title: 'Team', width: 110 },
{ id: 'owner', title: 'Owner', width: 110 },
{ id: 'amount', title: 'Amount', kind: 'number', width: 90, align: 'end' },
],
grouping: { by: ['region', 'team'], merged: true },
rows,
rowKey: 'id',
ariaLabel: 'Merged group export',
};
let merged = true;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
merged = true;
withExport(api);
log('Press "Preview sheet" to log the merge ranges (region 3 and 2 rows; team 2, 1 and 2 rows).');
}
export const actions = {
mode: (_api: GridApi<Row>, v?: string) => void (merged = v !== 'off'),
preview: (api: GridApi<Row>) => {
const bytes = withExport(api).exportXlsx({ mergedGroups: merged });
const text = new TextDecoder('utf-8').decode(bytes);
const xml = text.slice(text.search(/xl\/worksheets\/sheet1\.xml<\?xml/));
const refs = [...xml.matchAll(/<mergeCell ref="([^"]+)"/g)].map((m) => m[1]);
say(
`Merge ranges: ${refs.join(', ') || 'none'} (1 header row + ${api.getRowCount()} data rows)`,
);
},
download: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('merged-groups.xlsx', { mergedGroups: merged });
say('Downloaded.');
},
};