@nx-ddd/excel 0.0.1
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/README.md +123 -0
- package/package.json +32 -0
- package/src/index.js +5 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @nx-ddd/excel
|
|
2
|
+
|
|
3
|
+
Excel操作のためのDDDベースのライブラリ
|
|
4
|
+
|
|
5
|
+
## ディレクトリ構成
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
src/lib/
|
|
9
|
+
├── domain/ # ドメイン層(インターフェース定義)
|
|
10
|
+
│ └── index.ts
|
|
11
|
+
├── infra/ # インフラストラクチャ層(実装)
|
|
12
|
+
│ ├── excel.repository.impl.ts
|
|
13
|
+
│ └── excel.repository.impl.spec.ts
|
|
14
|
+
├── impl/ # サービス実装
|
|
15
|
+
│ ├── excel.service.impl.ts
|
|
16
|
+
│ └── excel.service.impl.spec.ts
|
|
17
|
+
├── providers/ # DI設定
|
|
18
|
+
│ └── excel.providers.ts
|
|
19
|
+
├── tokens/ # InjectionToken定義
|
|
20
|
+
│ └── excel.token.ts
|
|
21
|
+
├── __mocks__/ # テスト用モック
|
|
22
|
+
│ ├── fs.ts
|
|
23
|
+
│ ├── path.ts
|
|
24
|
+
│ └── xlsx.ts
|
|
25
|
+
├── excel.converter.ts # データ変換ユーティリティ
|
|
26
|
+
├── excel.decorators.ts # デコレーター
|
|
27
|
+
├── excel.repository.ts # リポジトリの再エクスポート
|
|
28
|
+
└── excel.service.ts # サービスインターフェース
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 使用方法
|
|
32
|
+
|
|
33
|
+
### 1. DIの設定
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { provideExcelService } from '@nx-ddd/excel/providers';
|
|
37
|
+
|
|
38
|
+
// Angularアプリケーション
|
|
39
|
+
@NgModule({
|
|
40
|
+
providers: [
|
|
41
|
+
...provideExcelService()
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
export class AppModule {}
|
|
45
|
+
|
|
46
|
+
// スタンドアロンアプリケーション
|
|
47
|
+
bootstrapApplication(AppComponent, {
|
|
48
|
+
providers: [
|
|
49
|
+
...provideExcelService()
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. サービスの使用
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { inject } from '@angular/core';
|
|
58
|
+
import { EXCEL_SERVICE } from '@nx-ddd/excel/tokens';
|
|
59
|
+
|
|
60
|
+
@Injectable()
|
|
61
|
+
export class MyService {
|
|
62
|
+
private readonly excelService = inject(EXCEL_SERVICE);
|
|
63
|
+
|
|
64
|
+
async exportData() {
|
|
65
|
+
await this.excelService.writeSheet(
|
|
66
|
+
'output.xlsx',
|
|
67
|
+
'Sheet1',
|
|
68
|
+
data,
|
|
69
|
+
['Column1', 'Column2']
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async importData() {
|
|
74
|
+
const data = await this.excelService.readSheet('input.xlsx', 'Sheet1');
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. リポジトリの使用
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { getExcelRepository } from '@nx-ddd/excel';
|
|
84
|
+
|
|
85
|
+
// エンティティクラス
|
|
86
|
+
@Excel.Sheet('Users')
|
|
87
|
+
class User {
|
|
88
|
+
@Excel.Column('名前')
|
|
89
|
+
name: string;
|
|
90
|
+
|
|
91
|
+
@Excel.Column('メール')
|
|
92
|
+
email: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// リポジトリの取得
|
|
96
|
+
const userRepo = getExcelRepository(User, {
|
|
97
|
+
path: 'users.xlsx',
|
|
98
|
+
sheetName: 'Users'
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// データの保存
|
|
102
|
+
await userRepo.saveMany(users);
|
|
103
|
+
|
|
104
|
+
// データの読み込み
|
|
105
|
+
const users = await userRepo.list();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## テスト
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
nx test @nx-ddd/excel
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## エクスポート構成
|
|
115
|
+
|
|
116
|
+
- `@nx-ddd/excel` - メインエクスポート
|
|
117
|
+
- `@nx-ddd/excel/providers` - DI設定
|
|
118
|
+
- `@nx-ddd/excel/tokens` - InjectionToken
|
|
119
|
+
- `@nx-ddd/excel/impl` - 実装詳細(通常は直接使用しない)
|
|
120
|
+
|
|
121
|
+
## Building
|
|
122
|
+
|
|
123
|
+
Run `nx build @nx-ddd/excel` to build the library.
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nx-ddd/excel",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.d.ts",
|
|
10
|
+
"default": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./providers": {
|
|
13
|
+
"types": "./src/lib/providers/index.d.ts",
|
|
14
|
+
"default": "./src/lib/providers/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./tokens": {
|
|
17
|
+
"types": "./src/lib/tokens/index.d.ts",
|
|
18
|
+
"default": "./src/lib/tokens/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./impl": {
|
|
21
|
+
"types": "./src/lib/impl/index.d.ts",
|
|
22
|
+
"default": "./src/lib/impl/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"!**/*.tsbuildinfo"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"tslib": "^2.3.0"
|
|
31
|
+
}
|
|
32
|
+
}
|