@mogura/moguchart-plugin-excel 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +126 -0
- package/README.md +121 -0
- package/dist/export.d.ts +10 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/index.d.ts +24 -0
- package/dist/moguchart-plugin-excel.mjs +32993 -0
- package/dist/moguchart-plugin-excel.umd.js +28 -0
- package/dist/types.d.ts +110 -0
- package/dist/utils.d.ts +124 -0
- package/package.json +63 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { GanttRow, GanttTask } from '@mogura/moguchart-core';
|
|
2
|
+
import type { ExcelLocaleDefinition } from './i18n';
|
|
3
|
+
export type { ExcelLocaleDefinition };
|
|
4
|
+
/**
|
|
5
|
+
* Excelエクスポート時のカスタムカラム定義
|
|
6
|
+
*/
|
|
7
|
+
export interface ExcelExportColumn {
|
|
8
|
+
/** カラム識別キー (例: 'wbs', 'taskName', 'start', 'end', 'progress', 'dependencies') */
|
|
9
|
+
key?: string;
|
|
10
|
+
/** Excelシートのヘッダー行に表示するラベル */
|
|
11
|
+
header: string;
|
|
12
|
+
/** 列幅 (文字数ベース。指定しない場合は自動計算) */
|
|
13
|
+
width?: number;
|
|
14
|
+
/** Excelの数値・日付表示フォーマット (例: 'yyyy/mm/dd', '0%', '#,##0') */
|
|
15
|
+
numFmt?: string;
|
|
16
|
+
/** テキストの水平配置 */
|
|
17
|
+
align?: 'left' | 'center' | 'right';
|
|
18
|
+
/** 値を独自取得・整形するためのカスタム関数 */
|
|
19
|
+
getValue?: (task: GanttTask, row: GanttRow, rowIndex: number) => any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* タイムライン列の刻み単位
|
|
23
|
+
*/
|
|
24
|
+
export type ExcelTimelineScale = 'hour' | 'day' | 'week' | 'month';
|
|
25
|
+
/**
|
|
26
|
+
* Excelエクスポートの対応言語・ロケール指定
|
|
27
|
+
* - 文字列: 'ja' | 'en' | 'zh' や登録済みのロケール識別名、任意の言語コード
|
|
28
|
+
* - オブジェクト: 独自の ExcelLocaleDefinition 定義
|
|
29
|
+
*/
|
|
30
|
+
export type ExcelLocale = 'ja' | 'en' | 'zh' | (string & {}) | ExcelLocaleDefinition;
|
|
31
|
+
/**
|
|
32
|
+
* Excelエクスポートの実行オプション
|
|
33
|
+
*/
|
|
34
|
+
export interface ExportExcelOptions {
|
|
35
|
+
/** 言語・ロケール ('ja' | 'en' | 'zh' 等の識別文字列、またはカスタム定義オブジェクト) */
|
|
36
|
+
locale?: ExcelLocale;
|
|
37
|
+
/** 出力ファイル名 (デフォルト: 'gantt-chart.xlsx') */
|
|
38
|
+
filename?: string;
|
|
39
|
+
/** シート名 (デフォルト: '工程表' / 英語時 'Gantt Chart') */
|
|
40
|
+
sheetName?: string;
|
|
41
|
+
/** 日付の表示形式 (デフォルト: 'YYYY/MM/DD') */
|
|
42
|
+
dateFormat?: string;
|
|
43
|
+
/** タイムラインの単位 (デフォルト: 'day') */
|
|
44
|
+
timelineScale?: ExcelTimelineScale;
|
|
45
|
+
/** 1日または1時間あたりの列数・分割数 (デフォルト: 1。スナップ単位が指定されている場合は自動計算) */
|
|
46
|
+
columnsPerUnit?: number;
|
|
47
|
+
/** スナップ単位(分)。日単位(1440, 720, 360, 180等)または時間単位(60, 30, 15等)に応じた分割列数を自動計算 */
|
|
48
|
+
snapDurationMinutes?: number;
|
|
49
|
+
/** タイムライン(カレンダー)列の幅 (文字数ベース。指定しない場合は画面表示幅またはスケール既定値から自動計算) */
|
|
50
|
+
timelineColumnWidth?: number;
|
|
51
|
+
/** タイムラインに土日を含めるか (デフォルト: true。土日列は薄いグレー背景) */
|
|
52
|
+
includeWeekends?: boolean;
|
|
53
|
+
/** 今日の日付列をハイライトするか (デフォルト: true) */
|
|
54
|
+
highlightToday?: boolean;
|
|
55
|
+
/** ヘッダーやアクセントのテーマカラー (CSS HEXカラー。デフォルト: '#3B82F6') */
|
|
56
|
+
themeColor?: string;
|
|
57
|
+
/** 祝祭日判定関数 (trueを返すと祝祭日として扱われます。未指定時はchart.option.calendar.isHolidayを自動参照) */
|
|
58
|
+
isHoliday?: (date: Date) => boolean;
|
|
59
|
+
/** 祝祭日列の背景色 (CSS HEXカラー。デフォルト: '#FEE2E2') */
|
|
60
|
+
holidayColor?: string;
|
|
61
|
+
/** タイムラインの表示開始日 (指定しない場合は全タスクの最小開始日または現在日) */
|
|
62
|
+
startDate?: Date;
|
|
63
|
+
/** タイムラインの表示終了日 (指定しない場合は全タスクの最大終了日または開始日から1ヶ月後) */
|
|
64
|
+
endDate?: Date;
|
|
65
|
+
/** 出力カラムのカスタム定義配列、または標準カラム配列を受け取ってカスタマイズする関数 (指定しない場合は標準カラムが出力されます) */
|
|
66
|
+
columns?: ExcelExportColumn[] | ((defaultColumns: ExcelExportColumn[]) => ExcelExportColumn[]);
|
|
67
|
+
/** 自動ダウンロードを実行するか (デフォルト: true。ブラウザ環境のみ有効) */
|
|
68
|
+
download?: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* プラグイン初期化時の設定オプション
|
|
72
|
+
*/
|
|
73
|
+
export interface ExcelPluginConfig {
|
|
74
|
+
/** デフォルトの言語・ロケール */
|
|
75
|
+
locale?: ExcelLocale;
|
|
76
|
+
/** プラグイン初期化時に追加登録するカスタムロケール辞書 */
|
|
77
|
+
locales?: Record<string, ExcelLocaleDefinition>;
|
|
78
|
+
/** デフォルトのファイル名 */
|
|
79
|
+
defaultFilename?: string;
|
|
80
|
+
/** デフォルトのシート名 */
|
|
81
|
+
defaultSheetName?: string;
|
|
82
|
+
/** デフォルトの出力カラム定義、またはカスタマイズ関数 */
|
|
83
|
+
defaultColumns?: ExcelExportColumn[] | ((defaultColumns: ExcelExportColumn[]) => ExcelExportColumn[]);
|
|
84
|
+
/** デフォルトの日付形式 */
|
|
85
|
+
dateFormat?: string;
|
|
86
|
+
/** デフォルトのタイムライン単位 */
|
|
87
|
+
timelineScale?: ExcelTimelineScale;
|
|
88
|
+
/** デフォルトの1日/1時間あたり列数 */
|
|
89
|
+
columnsPerUnit?: number;
|
|
90
|
+
/** デフォルトのスナップ単位(分) */
|
|
91
|
+
snapDurationMinutes?: number;
|
|
92
|
+
/** デフォルトのタイムライン列幅 */
|
|
93
|
+
timelineColumnWidth?: number;
|
|
94
|
+
/** 土日を含めるか */
|
|
95
|
+
includeWeekends?: boolean;
|
|
96
|
+
/** テーマカラー */
|
|
97
|
+
themeColor?: string;
|
|
98
|
+
/** デフォルトの祝祭日判定関数 */
|
|
99
|
+
isHoliday?: (date: Date) => boolean;
|
|
100
|
+
/** デフォルトの祝祭日背景色 */
|
|
101
|
+
holidayColor?: string;
|
|
102
|
+
}
|
|
103
|
+
declare module '@mogura/moguchart-core' {
|
|
104
|
+
interface GanttChartElement {
|
|
105
|
+
/**
|
|
106
|
+
* ガントチャートのデータをExcel (.xlsx) 形式でエクスポートします
|
|
107
|
+
*/
|
|
108
|
+
exportExcel?: (options?: ExportExcelOptions) => Promise<Blob>;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { GanttChartElement, GanttRow } from '@mogura/moguchart-core';
|
|
2
|
+
import type { ExcelLocale, ExcelTimelineScale, ExportExcelOptions } from './types';
|
|
3
|
+
export declare const EN_MONTH_NAMES: string[];
|
|
4
|
+
/**
|
|
5
|
+
* ガントチャートまたはオプションから言語・ロケールを判定する
|
|
6
|
+
*/
|
|
7
|
+
export declare function detectLocale(chart?: GanttChartElement, explicitLocale?: ExcelLocale): ExcelLocale;
|
|
8
|
+
/**
|
|
9
|
+
* タイムライン用の単一列情報(日、月、週、時間など全スケール共通)
|
|
10
|
+
*/
|
|
11
|
+
export interface TimelineItem {
|
|
12
|
+
key: string;
|
|
13
|
+
startDate: Date;
|
|
14
|
+
endDate: Date;
|
|
15
|
+
groupLabel: string;
|
|
16
|
+
subLabel: string;
|
|
17
|
+
scale?: ExcelTimelineScale;
|
|
18
|
+
isWeekend?: boolean;
|
|
19
|
+
isHoliday?: boolean;
|
|
20
|
+
isToday?: boolean;
|
|
21
|
+
width?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* WBS階層情報が付加された行・タスク情報
|
|
25
|
+
*/
|
|
26
|
+
export interface FlatRowItem {
|
|
27
|
+
row: GanttRow;
|
|
28
|
+
wbsNumber: string;
|
|
29
|
+
depth: number;
|
|
30
|
+
isParent: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Excelのワークシート名として安全な名前にサニタイズする
|
|
34
|
+
* - 使用禁止文字: * ? : \ / [ ]
|
|
35
|
+
* - 最大長: 31文字
|
|
36
|
+
*/
|
|
37
|
+
export declare function sanitizeSheetName(name?: string, fallback?: string, maxLen?: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* CSSカラー文字列(HEX, rgb, rgba, 主要カラー名)をExcelJS用のARGB形式に変換する
|
|
40
|
+
* 例: '#3B82F6' -> 'FF3B82F6', 'rgb(59, 130, 246)' -> 'FF3B82F6'
|
|
41
|
+
*/
|
|
42
|
+
export declare function hexToArgb(color?: string, defaultArgb?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* ARGB形式の色から輝度(Luminance)を計算し、視認性の高いコントラスト文字色(白または黒)を返す
|
|
45
|
+
*/
|
|
46
|
+
export declare function getContrastArgb(argb: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* タスク情報からガントチャート表示色(ARGB形式)を抽出・決定する
|
|
49
|
+
* 優先順位:
|
|
50
|
+
* 1. task.style の background-color / background
|
|
51
|
+
* 2. task.attribute.colorPalette.backgroundColor または task.colorPalette.backgroundColor
|
|
52
|
+
* 3. task.progressColor
|
|
53
|
+
* 4. task.backgroundColor または task.color
|
|
54
|
+
* 5. サマリータスクの場合は 'FF334155'、通常タスクの場合は themeArgb
|
|
55
|
+
*/
|
|
56
|
+
export declare function extractTaskBarColor(task: any, isParent?: boolean, themeArgb?: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* タイムライン列アイテム(祝祭日、土日、平日)に応じた背景色(ARGB)を返す
|
|
59
|
+
* ※ 背景色(土日・祝祭日)の適用は「日単位(scale === 'day')」のみ行います。
|
|
60
|
+
* - 祝祭日・日曜日: holidayArgb (デフォルト: 'FFFEE2E2', 淡い赤/ピンク)
|
|
61
|
+
* - 土曜日: 'FFEFF6FF' (淡いブルー)
|
|
62
|
+
* - 平日(または日単位以外): null (背景色なし / 白)
|
|
63
|
+
*/
|
|
64
|
+
export declare function getTimelineCellBgColor(item: TimelineItem, holidayArgb?: string, scale?: ExcelTimelineScale): string | null;
|
|
65
|
+
/**
|
|
66
|
+
* チャートの設定やオプションから適切なタイムラインスケールを判定する
|
|
67
|
+
*/
|
|
68
|
+
export declare function detectTimelineScale(chart?: GanttChartElement, explicitScale?: ExcelTimelineScale): ExcelTimelineScale;
|
|
69
|
+
/**
|
|
70
|
+
* ExcelJS に渡す Date オブジェクトを、ローカル時刻の見た目通りの日付シリアル値になるよう補正する。
|
|
71
|
+
* ExcelJS は内部で date.getTime() (UTC) を使用してシリアル値を計算するため、
|
|
72
|
+
* JST などの正のタイムゾーン下ではローカル日時 (例: 2025-01-01 00:00:00) が前日 (2024-12-31 15:00:00) のシリアル値として
|
|
73
|
+
* 書き込まれてしまい、Excel 上で 1日 (または月単位で 1ヶ月) 過去にずれて表示される。
|
|
74
|
+
* そのため、getTimezoneOffset() 分を差し引くことで、Excel 上のシリアル値がローカル日時と完全に一致するようにする。
|
|
75
|
+
*/
|
|
76
|
+
export declare function toExcelDate(date: Date): Date;
|
|
77
|
+
/**
|
|
78
|
+
* タイムラインの開始日・終了日を計算し、スケール単位にスナップする
|
|
79
|
+
* 優先順位:
|
|
80
|
+
* 1. options の startDate / endDate
|
|
81
|
+
* 2. calendar (画面上のカレンダー表示設定) の start / end
|
|
82
|
+
* 3. 行・タスク全体の最小開始日 / 最大終了日
|
|
83
|
+
*/
|
|
84
|
+
export declare function getTimelineRange(rows: GanttRow[], options?: Pick<ExportExcelOptions, 'startDate' | 'endDate'>, scale?: ExcelTimelineScale, calendar?: {
|
|
85
|
+
start?: Date;
|
|
86
|
+
end?: Date;
|
|
87
|
+
}): {
|
|
88
|
+
startDate: Date;
|
|
89
|
+
endDate: Date;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* 画面上のピクセル幅 (px) を Excel の列幅 (文字幅単位) に変換する
|
|
93
|
+
* 一般的な Excel の標準フォント (11pt) では 1文字幅 ≒ 約7.5px
|
|
94
|
+
*/
|
|
95
|
+
export declare function pxToExcelColumnWidth(px: number, minWidth?: number): number;
|
|
96
|
+
/**
|
|
97
|
+
* オプション、チャート設定、スケールから最適なタイムライン列幅(Excel列幅単位)を判定・算出する
|
|
98
|
+
*/
|
|
99
|
+
export declare function detectTimelineColumnWidth(chart?: GanttChartElement, explicitWidth?: number, scale?: ExcelTimelineScale, columnsPerUnit?: number): number;
|
|
100
|
+
/**
|
|
101
|
+
* 1日または1時間あたりの分割列数を判定・算出する
|
|
102
|
+
* 優先順位:
|
|
103
|
+
* 1. options.columnsPerUnit (明示的指定)
|
|
104
|
+
* 2. options.snapDurationMinutes (スナップ分数から計算)
|
|
105
|
+
* 3. chart.option.snapDuration (チャート設定のスナップ分数から計算)
|
|
106
|
+
* 4. デフォルト: 1
|
|
107
|
+
*/
|
|
108
|
+
export declare function detectColumnsPerUnit(chart?: GanttChartElement, options?: Pick<ExportExcelOptions, 'columnsPerUnit' | 'snapDurationMinutes'>, scale?: ExcelTimelineScale): number;
|
|
109
|
+
/**
|
|
110
|
+
* 各スケール(日・週・月・時間)に応じたタイムライン列リストを生成する
|
|
111
|
+
*/
|
|
112
|
+
export declare function generateTimelineList(startDate: Date, endDate: Date, scale?: ExcelTimelineScale, includeWeekends?: boolean, columnWidth?: number, columnsPerUnit?: number, isHoliday?: (date: Date) => boolean, locale?: ExcelLocale): TimelineItem[];
|
|
113
|
+
/**
|
|
114
|
+
* 行リストからWBSコード(1, 1.1, 1.2 等)と階層深さを計算してフラット化する
|
|
115
|
+
*/
|
|
116
|
+
export declare function calculateWbsHierarchy(rows: GanttRow[]): FlatRowItem[];
|
|
117
|
+
/**
|
|
118
|
+
* 曜日の表記を取得する(登録済みロケールまたはカスタム定義に対応)
|
|
119
|
+
*/
|
|
120
|
+
export declare function getDayOfWeekText(dayOfWeek: number, locale?: ExcelLocale): string;
|
|
121
|
+
/**
|
|
122
|
+
* ブラウザ環境でBlobをファイルとしてダウンロードする
|
|
123
|
+
*/
|
|
124
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mogura/moguchart-plugin-excel",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.3.0",
|
|
5
|
+
"description": "Excel (.xlsx) export plugin for @mogura/moguchart-core",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Murakami Hiroyuki",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/hiro-murakami/moguchart-core.git",
|
|
11
|
+
"directory": "packages/plugin-excel"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/hiro-murakami/moguchart-core",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"gantt",
|
|
19
|
+
"moguchart",
|
|
20
|
+
"excel",
|
|
21
|
+
"xlsx",
|
|
22
|
+
"export",
|
|
23
|
+
"spreadsheet",
|
|
24
|
+
"timeline"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"README.md",
|
|
30
|
+
"README.ja.md"
|
|
31
|
+
],
|
|
32
|
+
"main": "./dist/moguchart-plugin-excel.umd.js",
|
|
33
|
+
"module": "./dist/moguchart-plugin-excel.mjs",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/moguchart-plugin-excel.mjs",
|
|
39
|
+
"require": "./dist/moguchart-plugin-excel.umd.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"lit": "^3.0.0",
|
|
44
|
+
"@mogura/moguchart-core": "1.3.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"exceljs": "^4.4.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^24.12.0",
|
|
51
|
+
"jsdom": "^27.4.0",
|
|
52
|
+
"lit": "^3.3.2",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vite": "^8.0.0",
|
|
55
|
+
"vitest": "^4.0.16",
|
|
56
|
+
"@mogura/moguchart-core": "1.3.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "vite build && pnpm exec tsc -p tsconfig.build.json",
|
|
60
|
+
"test": "vitest",
|
|
61
|
+
"test:run": "vitest run"
|
|
62
|
+
}
|
|
63
|
+
}
|