質問編集履歴
4
【該当のソースコード】修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -328,7 +328,7 @@
|
|
328
328
|
|
329
329
|
sheets = GetSheets(book);
|
330
330
|
|
331
|
-
sheet = GetSheet(sheets,
|
331
|
+
sheet = GetSheet(sheets, 1);
|
332
332
|
|
333
333
|
int lastRow = 65537;
|
334
334
|
|
@@ -442,34 +442,20 @@
|
|
442
442
|
|
443
443
|
}
|
444
444
|
|
445
|
-
// シート
|
445
|
+
// シートインデックスからSheetを取得
|
446
|
-
|
446
|
+
|
447
|
-
public object GetSheet(object sheets,
|
447
|
+
public object GetSheet(object sheets, int index)
|
448
448
|
|
449
449
|
{
|
450
450
|
|
451
451
|
object[] parameters = new object[1];
|
452
452
|
|
453
|
-
parameters[0] =
|
453
|
+
parameters[0] = index;
|
454
454
|
|
455
455
|
return sheets.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, sheets, parameters);
|
456
456
|
|
457
457
|
}
|
458
458
|
|
459
|
-
// シートインデックスからSheetを取得
|
460
|
-
|
461
|
-
public object GetSheet(object sheets, int index)
|
462
|
-
|
463
|
-
{
|
464
|
-
|
465
|
-
object[] parameters = new object[1];
|
466
|
-
|
467
|
-
parameters[0] = index;
|
468
|
-
|
469
|
-
return sheets.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, sheets, parameters);
|
470
|
-
|
471
|
-
}
|
472
|
-
|
473
459
|
// Cellsを取得
|
474
460
|
|
475
461
|
public object GetCells(object sheet)
|
3
【発生している問題・エラーメッセージ】にファイルサイズ追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,8 @@
|
|
16
16
|
|
17
17
|
1~6回目は処理が成功するのですが、7回目でエラーが発生します。
|
18
18
|
|
19
|
+
※ファイルのサイズは522KB(65537行,256列)です。
|
20
|
+
|
19
21
|
なお、上記の問題はVisual Studioのビルドのプラットフォームターゲットをx86とし、
|
20
22
|
|
21
23
|
64bitのマシン環境で実行すると発生します。
|
2
ソースコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,9 +14,7 @@
|
|
14
14
|
|
15
15
|
同じファイルを選択して複数回実行したときに、
|
16
16
|
|
17
|
-
1~
|
17
|
+
1~6回目は処理が成功するのですが、7回目でエラーが発生します。
|
18
|
-
|
19
|
-
|
20
18
|
|
21
19
|
なお、上記の問題はVisual Studioのビルドのプラットフォームターゲットをx86とし、
|
22
20
|
|
@@ -30,11 +28,7 @@
|
|
30
28
|
|
31
29
|
【エラー発生箇所】
|
32
30
|
|
33
|
-
DaoExcelFileクラスのReadFileメソッド
|
31
|
+
DaoExcelFileクラスのReadFileメソッド
|
34
|
-
|
35
|
-
エクセルのRangeを配列にセットするステートメント
|
36
|
-
|
37
|
-
|
38
32
|
|
39
33
|
```
|
40
34
|
|
@@ -44,8 +38,6 @@
|
|
44
38
|
|
45
39
|
```
|
46
40
|
|
47
|
-
|
48
|
-
|
49
41
|
###該当のソースコード
|
50
42
|
|
51
43
|
```ここに言語を入力
|
@@ -66,27 +58,19 @@
|
|
66
58
|
|
67
59
|
}
|
68
60
|
|
69
|
-
|
70
|
-
|
71
61
|
//ファイル選択ボタンクリック
|
72
62
|
|
73
63
|
private void button1_Click(object sender, EventArgs e)
|
74
64
|
|
75
65
|
{
|
76
66
|
|
77
|
-
//ファイルの形式をセット
|
78
|
-
|
79
67
|
var selectFileFormat = "Excel";
|
80
68
|
|
81
69
|
//ユーザーファイルを選択してデータを読み込み
|
82
70
|
|
83
71
|
FileReadWriteController.ReadUserInfoFile(selectFileFormat, out userFile);
|
84
72
|
|
85
|
-
|
86
|
-
|
87
|
-
}
|
73
|
+
}
|
88
|
-
|
89
|
-
|
90
74
|
|
91
75
|
//ファイルからデータを読み込み、書込みをコントロールするクラス
|
92
76
|
|
@@ -104,119 +88,133 @@
|
|
104
88
|
|
105
89
|
{
|
106
90
|
|
107
|
-
//ファイルを開くダイアログのインスタンスを作成
|
108
|
-
|
109
91
|
OpenFileDialog ofd = new OpenFileDialog();
|
110
92
|
|
111
|
-
//ダイアログを表示する
|
112
|
-
|
113
93
|
if (ofd.ShowDialog() == DialogResult.OK)
|
114
94
|
|
115
95
|
{
|
116
96
|
|
97
|
+
userInfoFile = new UserInfoFileExcel();
|
98
|
+
|
99
|
+
userInfoFile.FilePath = ofd.FileName;
|
100
|
+
|
101
|
+
userInfoFile.ReadData();
|
102
|
+
|
103
|
+
return true;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
else
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
userInfoFile = null;
|
112
|
+
|
113
|
+
return false;
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
117
|
-
|
121
|
+
//ファイルの抽象クラス
|
122
|
+
|
118
|
-
|
123
|
+
abstract public class MyFile
|
124
|
+
|
125
|
+
{
|
126
|
+
|
119
|
-
|
127
|
+
public string FilePath;
|
128
|
+
|
129
|
+
public DataTable FileData;
|
130
|
+
|
131
|
+
public MyFile()
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
FileData = new DataTable();
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
public abstract void ReadData();
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
//ユーザー情報情報ファイルの抽象クラス
|
144
|
+
|
145
|
+
abstract public class UserInfoFile : MyFile
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
//省略
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
//Excel形式のユーザー情報ファイル
|
154
|
+
|
155
|
+
public class UserInfoFileExcel : UserInfoFile
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
public override void ReadData()
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
using (var excelApp = new DaoExcelFile())
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
excelApp.ReadFile(FilePath, FileData, "Info");
|
168
|
+
|
169
|
+
excelApp.Quit();
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
//Excelクラス
|
178
|
+
|
179
|
+
public class DaoExcelFile : IDisposable
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
private object xlsApplication = null;
|
184
|
+
|
185
|
+
private object xlsBooks = null;
|
186
|
+
|
187
|
+
protected object XlsApplication
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
get
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
// 存在しない場合は作成する
|
196
|
+
|
197
|
+
if (xlsApplication == null)
|
120
198
|
|
121
199
|
{
|
122
200
|
|
123
|
-
case "Excel"
|
201
|
+
Type classType = Type.GetTypeFromProgID("Excel.Application");
|
124
|
-
|
202
|
+
|
125
|
-
|
203
|
+
xlsApplication = Activator.CreateInstance(classType);
|
126
|
-
|
127
|
-
userInfoFile.FilePath = ofd.FileName;
|
128
|
-
|
129
|
-
userInfoFile.ReadData();
|
130
|
-
|
131
|
-
return true;
|
132
|
-
|
133
|
-
default:
|
134
|
-
|
135
|
-
userInfoFile = null;
|
136
|
-
|
137
|
-
return false;
|
138
204
|
|
139
205
|
}
|
140
206
|
|
207
|
+
return xlsApplication;
|
208
|
+
|
141
|
-
}
|
209
|
+
}
|
142
|
-
|
143
|
-
|
210
|
+
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
userInfoFile = null;
|
148
|
-
|
149
|
-
return false;
|
150
|
-
|
151
|
-
|
211
|
+
}
|
152
|
-
|
153
|
-
|
212
|
+
|
154
|
-
|
155
|
-
|
213
|
+
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
//ユーザー情報情報ファイルの抽象クラス
|
160
|
-
|
161
|
-
abstract public class UserInfoFile : MyFile
|
162
|
-
|
163
|
-
{
|
164
|
-
|
165
|
-
//省略
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
//Excel形式のユーザー情報ファイル
|
174
|
-
|
175
|
-
public class UserInfoFileExcel : UserInfoFile
|
176
|
-
|
177
|
-
{
|
178
|
-
|
179
|
-
public override void ReadData()
|
180
|
-
|
181
|
-
{
|
182
|
-
|
183
|
-
//Excelファイルのデータを取得
|
184
|
-
|
185
|
-
using (var excelApp = new DaoExcelFile())
|
186
|
-
|
187
|
-
{
|
188
|
-
|
189
|
-
excelApp.ReadFile(FilePath, FileData, "Info");
|
190
|
-
|
191
|
-
excelApp.Quit();
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//Excelクラス
|
204
|
-
|
205
|
-
public class DaoExcelFile : IDisposable
|
206
|
-
|
207
|
-
{
|
208
|
-
|
209
|
-
// Excelアプリケーションオブジェクト
|
210
|
-
|
211
|
-
private object xlsApplication = null;
|
212
214
|
|
213
215
|
// Workbooksオブジェクト
|
214
216
|
|
215
|
-
private object xlsBooks = null;
|
216
|
-
|
217
|
-
// Excelアプリケーションオブジェクト
|
218
|
-
|
219
|
-
protected object
|
217
|
+
protected object Workbooks
|
220
218
|
|
221
219
|
{
|
222
220
|
|
@@ -224,81 +222,135 @@
|
|
224
222
|
|
225
223
|
{
|
226
224
|
|
227
|
-
// 存在しない場合は作成する
|
228
|
-
|
229
|
-
if (xls
|
225
|
+
if (xlsBooks == null)
|
230
226
|
|
231
227
|
{
|
232
228
|
|
233
|
-
|
229
|
+
xlsBooks = XlsApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, XlsApplication, null);
|
234
|
-
|
235
|
-
xlsApplication = Activator.CreateInstance(classType);
|
236
230
|
|
237
231
|
}
|
238
232
|
|
239
|
-
return xls
|
233
|
+
return xlsBooks;
|
240
|
-
|
234
|
+
|
241
|
-
}
|
235
|
+
}
|
242
|
-
|
236
|
+
|
243
|
-
}
|
237
|
+
}
|
244
|
-
|
245
|
-
|
246
|
-
|
238
|
+
|
247
|
-
//
|
239
|
+
//Dispose
|
248
|
-
|
240
|
+
|
249
|
-
p
|
241
|
+
public void Dispose()
|
250
|
-
|
242
|
+
|
251
|
-
{
|
243
|
+
{
|
244
|
+
|
252
|
-
|
245
|
+
ReleaseComObject(xlsBooks);
|
246
|
+
|
247
|
+
ReleaseComObject(xlsApplication);
|
248
|
+
|
253
|
-
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
|
254
|
-
|
253
|
+
// COMオブジェクトのリリース
|
254
|
+
|
255
|
+
public void ReleaseComObject(object target)
|
256
|
+
|
255
|
-
|
257
|
+
{
|
258
|
+
|
256
|
-
|
259
|
+
try
|
260
|
+
|
261
|
+
{
|
262
|
+
|
257
|
-
if (
|
263
|
+
if ((target != null))
|
258
264
|
|
259
265
|
{
|
260
266
|
|
261
|
-
|
267
|
+
System.Runtime.InteropServices.Marshal.ReleaseComObject(target);
|
262
268
|
|
263
269
|
}
|
264
270
|
|
265
|
-
return xlsBooks;
|
266
|
-
|
267
|
-
}
|
271
|
+
}
|
272
|
+
|
268
|
-
|
273
|
+
finally
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
target = null;
|
278
|
+
|
269
|
-
}
|
279
|
+
}
|
280
|
+
|
270
|
-
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
271
|
-
//
|
285
|
+
// Excel終了
|
272
|
-
|
286
|
+
|
273
|
-
public void
|
287
|
+
public void Quit()
|
274
|
-
|
288
|
+
|
275
|
-
{
|
289
|
+
{
|
276
|
-
|
277
|
-
|
290
|
+
|
278
|
-
|
279
|
-
|
291
|
+
XlsApplication.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, XlsApplication, null);
|
280
|
-
|
292
|
+
|
281
|
-
}
|
293
|
+
}
|
282
|
-
|
283
|
-
|
284
|
-
|
294
|
+
|
295
|
+
|
296
|
+
|
285
|
-
//
|
297
|
+
// 対象ファイルの対象シートのデータをデータテーブルにセットする
|
286
|
-
|
298
|
+
|
287
|
-
public void Rele
|
299
|
+
public void ReadFile(string filePath, DataTable fileData, string sheetName)
|
288
|
-
|
300
|
+
|
289
|
-
{
|
301
|
+
{
|
302
|
+
|
303
|
+
object book = null;
|
304
|
+
|
305
|
+
object sheets = null;
|
306
|
+
|
307
|
+
object sheet = null;
|
308
|
+
|
309
|
+
object cells = null;
|
310
|
+
|
311
|
+
object cella = null;
|
312
|
+
|
313
|
+
object cellb = null;
|
314
|
+
|
315
|
+
object targetRange = null;
|
316
|
+
|
317
|
+
object[,] obj1 = null;
|
318
|
+
|
319
|
+
|
290
320
|
|
291
321
|
try
|
292
322
|
|
293
323
|
{
|
294
324
|
|
325
|
+
book = GetOpenFile(filePath);
|
326
|
+
|
327
|
+
sheets = GetSheets(book);
|
328
|
+
|
329
|
+
sheet = GetSheet(sheets, sheetName);
|
330
|
+
|
295
|
-
i
|
331
|
+
int lastRow = 65537;
|
296
|
-
|
332
|
+
|
297
|
-
|
333
|
+
int lastColumn = 256;
|
334
|
+
|
298
|
-
|
335
|
+
cells = GetCells(sheet);
|
336
|
+
|
337
|
+
cella = GetCell(cells, 1, 1);
|
338
|
+
|
299
|
-
|
339
|
+
cellb = GetCell(cells, lastRow, lastColumn);
|
340
|
+
|
300
|
-
|
341
|
+
targetRange = GetRange(sheet, cella, cellb);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
//*********ここでエラーが発生する
|
346
|
+
|
347
|
+
//*********エラー内容:"プログラムを続行するための十分なメモリがありませんでした"
|
348
|
+
|
301
|
-
|
349
|
+
//オブジェクトの2次元配列へセット
|
350
|
+
|
351
|
+
//以降この配列にアクセスすることで処理を高速化
|
352
|
+
|
353
|
+
obj1 = (System.Object[,])targetRange.GetType().InvokeMember("Value2", BindingFlags.GetProperty, null, targetRange, null);
|
302
354
|
|
303
355
|
}
|
304
356
|
|
@@ -306,118 +358,6 @@
|
|
306
358
|
|
307
359
|
{
|
308
360
|
|
309
|
-
target = null;
|
310
|
-
|
311
|
-
}
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
// Excel終了
|
318
|
-
|
319
|
-
public void Quit()
|
320
|
-
|
321
|
-
{
|
322
|
-
|
323
|
-
XlsApplication.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, XlsApplication, null);
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
// 対象ファイルの対象シートのデータをデータテーブルにセットする
|
330
|
-
|
331
|
-
public void ReadFile(string filePath, DataTable fileData, string sheetName)
|
332
|
-
|
333
|
-
{
|
334
|
-
|
335
|
-
//対象シートは1枚目
|
336
|
-
|
337
|
-
int sheetIndex = 1;
|
338
|
-
|
339
|
-
//非可視に設定
|
340
|
-
|
341
|
-
Visible = false;
|
342
|
-
|
343
|
-
object book = null;
|
344
|
-
|
345
|
-
object sheets = null;
|
346
|
-
|
347
|
-
object sheet = null;
|
348
|
-
|
349
|
-
object cells = null;
|
350
|
-
|
351
|
-
object cella = null;
|
352
|
-
|
353
|
-
object cellb = null;
|
354
|
-
|
355
|
-
object targetRange = null;
|
356
|
-
|
357
|
-
object[,] obj1 = null;
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
try
|
362
|
-
|
363
|
-
{
|
364
|
-
|
365
|
-
//ブックを取得する
|
366
|
-
|
367
|
-
book = GetOpenFile(filePath);
|
368
|
-
|
369
|
-
//ワークシートコレクションを取得する
|
370
|
-
|
371
|
-
sheets = GetSheets(book);
|
372
|
-
|
373
|
-
//シートを取得する
|
374
|
-
|
375
|
-
sheet = GetSheet(sheets, sheetName);
|
376
|
-
|
377
|
-
//シートインデックスの取得
|
378
|
-
|
379
|
-
sheetIndex = (int)sheet.GetType().InvokeMember("Index", BindingFlags.GetProperty, null, sheet, null);
|
380
|
-
|
381
|
-
//シートの最終行を取得する
|
382
|
-
|
383
|
-
int lastRow = 65537;
|
384
|
-
|
385
|
-
//シートの最終列を取得する
|
386
|
-
|
387
|
-
int lastColumn = 256;
|
388
|
-
|
389
|
-
//cellsを取得
|
390
|
-
|
391
|
-
cells = GetCells(sheet);
|
392
|
-
|
393
|
-
//範囲を取得する基準セルを取得
|
394
|
-
|
395
|
-
cella = GetCell(cells, 1, 1);
|
396
|
-
|
397
|
-
cellb = GetCell(cells, lastRow, lastColumn);
|
398
|
-
|
399
|
-
////対象範囲を取得
|
400
|
-
|
401
|
-
targetRange = GetRange(sheet, cella, cellb);
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
//*********3回目の実行でここでエラーが発生する
|
406
|
-
|
407
|
-
//*********エラー内容:"プログラムを続行するための十分なメモリがありませんでした"
|
408
|
-
|
409
|
-
//オブジェクトの2次元配列へセット
|
410
|
-
|
411
|
-
//以降この配列にアクセスすることで処理を高速化
|
412
|
-
|
413
|
-
obj1 = (System.Object[,])targetRange.GetType().InvokeMember("Value2", BindingFlags.GetProperty, null, targetRange, null);
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
finally
|
418
|
-
|
419
|
-
{
|
420
|
-
|
421
361
|
//オブジェクトの解放
|
422
362
|
|
423
363
|
ReleaseComObject(targetRange);
|
@@ -440,6 +380,56 @@
|
|
440
380
|
|
441
381
|
|
442
382
|
|
383
|
+
// Excelファイルを開いてオブジェクトを返す
|
384
|
+
|
385
|
+
public object GetOpenFile(string xlsFilePath)
|
386
|
+
|
387
|
+
{
|
388
|
+
|
389
|
+
object[] parameters = new object[15];
|
390
|
+
|
391
|
+
parameters[0] = xlsFilePath;
|
392
|
+
|
393
|
+
parameters[1] = Type.Missing;
|
394
|
+
|
395
|
+
parameters[2] = Type.Missing;
|
396
|
+
|
397
|
+
parameters[3] = Type.Missing;
|
398
|
+
|
399
|
+
parameters[4] = Type.Missing;
|
400
|
+
|
401
|
+
parameters[5] = Type.Missing;
|
402
|
+
|
403
|
+
parameters[6] = Type.Missing;
|
404
|
+
|
405
|
+
parameters[7] = Type.Missing;
|
406
|
+
|
407
|
+
parameters[8] = Type.Missing;
|
408
|
+
|
409
|
+
parameters[9] = Type.Missing;
|
410
|
+
|
411
|
+
parameters[10] = Type.Missing;
|
412
|
+
|
413
|
+
parameters[11] = Type.Missing;
|
414
|
+
|
415
|
+
parameters[12] = Type.Missing;
|
416
|
+
|
417
|
+
parameters[13] = Type.Missing;
|
418
|
+
|
419
|
+
parameters[14] = Type.Missing;
|
420
|
+
|
421
|
+
object openFile = new object();
|
422
|
+
|
423
|
+
openFile = Workbooks.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, Workbooks, parameters);
|
424
|
+
|
425
|
+
return openFile;
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
|
443
433
|
// Sheetsを取得
|
444
434
|
|
445
435
|
public object GetSheets(object book)
|
@@ -524,8 +514,6 @@
|
|
524
514
|
|
525
515
|
}
|
526
516
|
|
527
|
-
|
528
|
-
|
529
517
|
```
|
530
518
|
|
531
519
|
|
1
【発生している問題・エラーメッセージ】にビルド環境による違いを追記。【該当のソースコート】コード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,17 @@
|
|
14
14
|
|
15
15
|
同じファイルを選択して複数回実行したときに、
|
16
16
|
|
17
|
-
1
|
17
|
+
1~3回目は処理が成功するのですが、4回目でエラーが発生します。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
なお、上記の問題はVisual Studioのビルドのプラットフォームターゲットをx86とし、
|
22
|
+
|
23
|
+
64bitのマシン環境で実行すると発生します。
|
24
|
+
|
25
|
+
※事情によりプラットフォームターゲットをx86にしています。
|
26
|
+
|
27
|
+
プラットフォームターゲットをAny CPU にすると発生しないことまではわかりました。
|
18
28
|
|
19
29
|
|
20
30
|
|
@@ -44,7 +54,7 @@
|
|
44
54
|
|
45
55
|
{
|
46
56
|
|
47
|
-
private UserInfoFile user
|
57
|
+
private UserInfoFile userFile;
|
48
58
|
|
49
59
|
|
50
60
|
|
@@ -56,9 +66,7 @@
|
|
56
66
|
|
57
67
|
}
|
58
68
|
|
59
|
-
|
60
|
-
|
61
|
-
|
69
|
+
|
62
70
|
|
63
71
|
//ファイル選択ボタンクリック
|
64
72
|
|
@@ -72,26 +80,20 @@
|
|
72
80
|
|
73
81
|
//ユーザーファイルを選択してデータを読み込み
|
74
82
|
|
75
|
-
FileReadWriteController.ReadUserInfoFile(selectFileFormat, out user
|
83
|
+
FileReadWriteController.ReadUserInfoFile(selectFileFormat, out userFile);
|
76
84
|
|
77
85
|
|
78
86
|
|
79
87
|
}
|
80
88
|
|
81
|
-
|
82
|
-
|
83
|
-
|
89
|
+
|
84
|
-
|
90
|
+
|
85
|
-
//
|
91
|
+
//ファイルからデータを読み込み、書込みをコントロールするクラス
|
86
|
-
|
87
|
-
/// </summary>
|
88
92
|
|
89
93
|
public static class FileReadWriteController
|
90
94
|
|
91
95
|
{
|
92
96
|
|
93
|
-
|
94
|
-
|
95
97
|
///ユーザー情報ファイルを選択して読み込み、
|
96
98
|
|
97
99
|
///読み込んだデータをユーザー情報ファイルオブジェクトのDataTabaleにセットする
|
@@ -102,14 +104,10 @@
|
|
102
104
|
|
103
105
|
{
|
104
106
|
|
105
|
-
|
106
|
-
|
107
107
|
//ファイルを開くダイアログのインスタンスを作成
|
108
108
|
|
109
109
|
OpenFileDialog ofd = new OpenFileDialog();
|
110
110
|
|
111
|
-
|
112
|
-
|
113
111
|
//ダイアログを表示する
|
114
112
|
|
115
113
|
if (ofd.ShowDialog() == DialogResult.OK)
|
@@ -126,8 +124,6 @@
|
|
126
124
|
|
127
125
|
userInfoFile = new UserInfoFileExcel();
|
128
126
|
|
129
|
-
//ファイルの内容を読み込む
|
130
|
-
|
131
127
|
userInfoFile.FilePath = ofd.FileName;
|
132
128
|
|
133
129
|
userInfoFile.ReadData();
|
@@ -142,8 +138,6 @@
|
|
142
138
|
|
143
139
|
}
|
144
140
|
|
145
|
-
|
146
|
-
|
147
141
|
}
|
148
142
|
|
149
143
|
else
|
@@ -156,49 +150,19 @@
|
|
156
150
|
|
157
151
|
}
|
158
152
|
|
159
|
-
|
160
|
-
|
161
153
|
}
|
162
154
|
|
163
155
|
}
|
164
156
|
|
165
157
|
|
166
158
|
|
167
|
-
|
168
|
-
|
169
|
-
/// <summary>
|
170
|
-
|
171
|
-
//
|
159
|
+
//ユーザー情報情報ファイルの抽象クラス
|
172
|
-
|
173
|
-
|
160
|
+
|
174
|
-
|
175
|
-
abstract public class MyFile
|
161
|
+
abstract public class UserInfoFile : MyFile
|
176
162
|
|
177
163
|
{
|
178
164
|
|
179
|
-
public string FilePath;
|
180
|
-
|
181
|
-
//エクセルから取得したセルデータをセットするDataTable
|
182
|
-
|
183
|
-
public DataTable FileData;
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
//
|
165
|
+
//省略
|
188
|
-
|
189
|
-
public MyFile()
|
190
|
-
|
191
|
-
{
|
192
|
-
|
193
|
-
FileData = new DataTable();
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
//指定したファイルの内容をFileDataメンバーにセットする
|
200
|
-
|
201
|
-
public abstract void ReadData();
|
202
166
|
|
203
167
|
|
204
168
|
|
@@ -206,358 +170,362 @@
|
|
206
170
|
|
207
171
|
|
208
172
|
|
209
|
-
/// <summary>
|
210
|
-
|
211
|
-
//
|
173
|
+
//Excel形式のユーザー情報ファイル
|
212
|
-
|
213
|
-
|
174
|
+
|
214
|
-
|
215
|
-
|
175
|
+
public class UserInfoFileExcel : UserInfoFile
|
216
176
|
|
217
177
|
{
|
218
178
|
|
179
|
+
public override void ReadData()
|
180
|
+
|
181
|
+
{
|
182
|
+
|
219
|
-
//
|
183
|
+
//Excelファイルのデータを取得
|
184
|
+
|
220
|
-
|
185
|
+
using (var excelApp = new DaoExcelFile())
|
186
|
+
|
221
|
-
|
187
|
+
{
|
188
|
+
|
189
|
+
excelApp.ReadFile(FilePath, FileData, "Info");
|
190
|
+
|
191
|
+
excelApp.Quit();
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
}
|
222
198
|
|
223
199
|
}
|
224
200
|
|
225
201
|
|
226
202
|
|
227
|
-
/// <summary>
|
228
|
-
|
229
|
-
//
|
203
|
+
//Excelクラス
|
230
|
-
|
231
|
-
|
204
|
+
|
232
|
-
|
233
|
-
public class
|
205
|
+
public class DaoExcelFile : IDisposable
|
234
206
|
|
235
207
|
{
|
236
208
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
209
|
+
// Excelアプリケーションオブジェクト
|
210
|
+
|
211
|
+
private object xlsApplication = null;
|
212
|
+
|
213
|
+
// Workbooksオブジェクト
|
214
|
+
|
215
|
+
private object xlsBooks = null;
|
216
|
+
|
217
|
+
// Excelアプリケーションオブジェクト
|
218
|
+
|
219
|
+
protected object XlsApplication
|
220
|
+
|
221
|
+
{
|
222
|
+
|
223
|
+
get
|
224
|
+
|
225
|
+
{
|
226
|
+
|
227
|
+
// 存在しない場合は作成する
|
228
|
+
|
229
|
+
if (xlsApplication == null)
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
Type classType = Type.GetTypeFromProgID("Excel.Application");
|
234
|
+
|
235
|
+
xlsApplication = Activator.CreateInstance(classType);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
return xlsApplication;
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
// Workbooksオブジェクト
|
248
|
+
|
249
|
+
protected object Workbooks
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
get
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
if (xlsBooks == null)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
xlsBooks = XlsApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, XlsApplication, null);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
return xlsBooks;
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
//Dispose
|
272
|
+
|
273
|
+
public void Dispose()
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
ReleaseComObject(xlsBooks);
|
278
|
+
|
279
|
+
ReleaseComObject(xlsApplication);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// COMオブジェクトのリリース
|
286
|
+
|
287
|
+
public void ReleaseComObject(object target)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
try
|
292
|
+
|
293
|
+
{
|
294
|
+
|
295
|
+
if ((target != null))
|
296
|
+
|
297
|
+
{
|
298
|
+
|
299
|
+
System.Runtime.InteropServices.Marshal.ReleaseComObject(target);
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
finally
|
306
|
+
|
307
|
+
{
|
308
|
+
|
309
|
+
target = null;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
// Excel終了
|
318
|
+
|
319
|
+
public void Quit()
|
320
|
+
|
321
|
+
{
|
322
|
+
|
323
|
+
XlsApplication.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, XlsApplication, null);
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
// 対象ファイルの対象シートのデータをデータテーブルにセットする
|
330
|
+
|
331
|
+
public void ReadFile(string filePath, DataTable fileData, string sheetName)
|
332
|
+
|
333
|
+
{
|
334
|
+
|
335
|
+
//対象シートは1枚目
|
336
|
+
|
337
|
+
int sheetIndex = 1;
|
338
|
+
|
339
|
+
//非可視に設定
|
340
|
+
|
341
|
+
Visible = false;
|
342
|
+
|
343
|
+
object book = null;
|
344
|
+
|
345
|
+
object sheets = null;
|
346
|
+
|
347
|
+
object sheet = null;
|
348
|
+
|
349
|
+
object cells = null;
|
350
|
+
|
351
|
+
object cella = null;
|
352
|
+
|
353
|
+
object cellb = null;
|
354
|
+
|
355
|
+
object targetRange = null;
|
356
|
+
|
357
|
+
object[,] obj1 = null;
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
try
|
362
|
+
|
363
|
+
{
|
364
|
+
|
365
|
+
//ブックを取得する
|
366
|
+
|
367
|
+
book = GetOpenFile(filePath);
|
368
|
+
|
369
|
+
//ワークシートコレクションを取得する
|
370
|
+
|
371
|
+
sheets = GetSheets(book);
|
372
|
+
|
373
|
+
//シートを取得する
|
374
|
+
|
375
|
+
sheet = GetSheet(sheets, sheetName);
|
376
|
+
|
377
|
+
//シートインデックスの取得
|
378
|
+
|
379
|
+
sheetIndex = (int)sheet.GetType().InvokeMember("Index", BindingFlags.GetProperty, null, sheet, null);
|
380
|
+
|
381
|
+
//シートの最終行を取得する
|
382
|
+
|
383
|
+
int lastRow = 65537;
|
384
|
+
|
385
|
+
//シートの最終列を取得する
|
386
|
+
|
387
|
+
int lastColumn = 256;
|
388
|
+
|
389
|
+
//cellsを取得
|
390
|
+
|
391
|
+
cells = GetCells(sheet);
|
392
|
+
|
393
|
+
//範囲を取得する基準セルを取得
|
394
|
+
|
395
|
+
cella = GetCell(cells, 1, 1);
|
396
|
+
|
397
|
+
cellb = GetCell(cells, lastRow, lastColumn);
|
398
|
+
|
399
|
+
////対象範囲を取得
|
400
|
+
|
401
|
+
targetRange = GetRange(sheet, cella, cellb);
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
//*********3回目の実行でここでエラーが発生する
|
406
|
+
|
407
|
+
//*********エラー内容:"プログラムを続行するための十分なメモリがありませんでした"
|
408
|
+
|
409
|
+
//オブジェクトの2次元配列へセット
|
410
|
+
|
411
|
+
//以降この配列にアクセスすることで処理を高速化
|
412
|
+
|
413
|
+
obj1 = (System.Object[,])targetRange.GetType().InvokeMember("Value2", BindingFlags.GetProperty, null, targetRange, null);
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
finally
|
418
|
+
|
419
|
+
{
|
420
|
+
|
421
|
+
//オブジェクトの解放
|
422
|
+
|
423
|
+
ReleaseComObject(targetRange);
|
424
|
+
|
425
|
+
ReleaseComObject(cellb);
|
426
|
+
|
427
|
+
ReleaseComObject(cella);
|
428
|
+
|
429
|
+
ReleaseComObject(cells);
|
430
|
+
|
431
|
+
ReleaseComObject(sheet);
|
432
|
+
|
433
|
+
ReleaseComObject(sheets);
|
434
|
+
|
435
|
+
ReleaseComObject(book);
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
// Sheetsを取得
|
444
|
+
|
445
|
+
public object GetSheets(object book)
|
446
|
+
|
447
|
+
{
|
448
|
+
|
449
|
+
return book.GetType().InvokeMember("Worksheets", BindingFlags.GetProperty, null, book, null);
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
// シート名からSheetを取得
|
454
|
+
|
455
|
+
public object GetSheet(object sheets, string sheetName)
|
456
|
+
|
457
|
+
{
|
458
|
+
|
459
|
+
object[] parameters = new object[1];
|
460
|
+
|
461
|
+
parameters[0] = sheetName;
|
462
|
+
|
463
|
+
return sheets.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, sheets, parameters);
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
// シートインデックスからSheetを取得
|
468
|
+
|
469
|
+
public object GetSheet(object sheets, int index)
|
470
|
+
|
471
|
+
{
|
472
|
+
|
473
|
+
object[] parameters = new object[1];
|
474
|
+
|
475
|
+
parameters[0] = index;
|
476
|
+
|
477
|
+
return sheets.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, sheets, parameters);
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
// Cellsを取得
|
482
|
+
|
483
|
+
public object GetCells(object sheet)
|
484
|
+
|
485
|
+
{
|
486
|
+
|
487
|
+
return sheet.GetType().InvokeMember("Cells", BindingFlags.GetProperty, null, sheet, null);
|
488
|
+
|
489
|
+
}
|
490
|
+
|
491
|
+
// Cellを取得
|
492
|
+
|
493
|
+
public object GetCell(object cells, int row, int column)
|
494
|
+
|
495
|
+
{
|
496
|
+
|
497
|
+
object[] parameters = new Object[2];
|
498
|
+
|
499
|
+
parameters[0] = row;
|
500
|
+
|
501
|
+
parameters[1] = column;
|
502
|
+
|
503
|
+
return cells.GetType().InvokeMember("Item", BindingFlags.GetProperty, null, cells, parameters);
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
// Rangeを取得
|
508
|
+
|
509
|
+
public object GetRange(object sheet, object cell1, object cell2)
|
510
|
+
|
511
|
+
{
|
512
|
+
|
513
|
+
object[] parameters = new Object[2];
|
514
|
+
|
515
|
+
parameters[0] = cell1;
|
516
|
+
|
517
|
+
parameters[1] = cell2;
|
518
|
+
|
519
|
+
return sheet.GetType().InvokeMember("Range", BindingFlags.GetProperty, null, sheet, parameters);
|
254
520
|
|
255
521
|
}
|
256
522
|
|
257
523
|
}
|
258
524
|
|
259
|
-
|
260
|
-
|
261
|
-
/// <summary>
|
262
|
-
|
263
|
-
/// Excelクラス
|
264
|
-
|
265
|
-
/// </summary>
|
266
|
-
|
267
|
-
public class DaoExcelFile : IDisposable
|
268
|
-
|
269
|
-
{
|
270
|
-
|
271
|
-
// Excelアプリケーションオブジェクト
|
272
|
-
|
273
|
-
private object xlsApplication = null;
|
274
|
-
|
275
|
-
// Workbooksオブジェクト
|
276
|
-
|
277
|
-
private object xlsBooks = null;
|
278
|
-
|
279
|
-
// Excelアプリケーションオブジェクト
|
280
|
-
|
281
|
-
protected object XlsApplication
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
get
|
286
|
-
|
287
|
-
{
|
288
|
-
|
289
|
-
// 存在しない場合は作成する
|
290
|
-
|
291
|
-
if (xlsApplication == null)
|
292
|
-
|
293
|
-
{
|
294
|
-
|
295
|
-
Type classType = Type.GetTypeFromProgID("Excel.Application");
|
296
|
-
|
297
|
-
xlsApplication = Activator.CreateInstance(classType);
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
return xlsApplication;
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
// Workbooksオブジェクト
|
310
|
-
|
311
|
-
protected object Workbooks
|
312
|
-
|
313
|
-
{
|
314
|
-
|
315
|
-
get
|
316
|
-
|
317
|
-
{
|
318
|
-
|
319
|
-
if (xlsBooks == null)
|
320
|
-
|
321
|
-
{
|
322
|
-
|
323
|
-
xlsBooks = XlsApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, XlsApplication, null);
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
return xlsBooks;
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
//Dispose
|
336
|
-
|
337
|
-
public void Dispose()
|
338
|
-
|
339
|
-
{
|
340
|
-
|
341
|
-
Dispose(true);
|
342
|
-
|
343
|
-
GC.SuppressFinalize(this);
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
protected virtual void Dispose(bool disposing)
|
350
|
-
|
351
|
-
{
|
352
|
-
|
353
|
-
if (disposing)
|
354
|
-
|
355
|
-
{
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
ReleaseComObject(xlsBooks);
|
362
|
-
|
363
|
-
ReleaseComObject(xlsApplication);
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
~DaoExcelFile()
|
370
|
-
|
371
|
-
{
|
372
|
-
|
373
|
-
Dispose(false);
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
// COMオブジェクトのリリース
|
380
|
-
|
381
|
-
public void ReleaseComObject(object target)
|
382
|
-
|
383
|
-
{
|
384
|
-
|
385
|
-
try
|
386
|
-
|
387
|
-
{
|
388
|
-
|
389
|
-
if ((target != null))
|
390
|
-
|
391
|
-
{
|
392
|
-
|
393
|
-
System.Runtime.InteropServices.Marshal.ReleaseComObject(target);
|
394
|
-
|
395
|
-
}
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
finally
|
400
|
-
|
401
|
-
{
|
402
|
-
|
403
|
-
target = null;
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
}
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
// Excel終了
|
412
|
-
|
413
|
-
public void Quit()
|
414
|
-
|
415
|
-
{
|
416
|
-
|
417
|
-
XlsApplication.GetType().InvokeMember("Quit", BindingFlags.InvokeMethod, null, XlsApplication, null);
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
/// <summary>
|
424
|
-
|
425
|
-
/// 対象ファイルの対象シートのデータをデータテーブルにセットする
|
426
|
-
|
427
|
-
/// </summary>
|
428
|
-
|
429
|
-
/// <param name="filePath">対象ファイルのパス</param>
|
430
|
-
|
431
|
-
/// <param name="fileData">データのセット先のデータテーブル</param>
|
432
|
-
|
433
|
-
/// <param name="sheetName">対象シート名</param>
|
434
|
-
|
435
|
-
/// <returns></returns>
|
436
|
-
|
437
|
-
public void ReadFile(string filePath, DataTable fileData, string sheetName)
|
438
|
-
|
439
|
-
{
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
object book = null;
|
444
|
-
|
445
|
-
object sheets = null;
|
446
|
-
|
447
|
-
object sheet = null;
|
448
|
-
|
449
|
-
object cells = null;
|
450
|
-
|
451
|
-
object cella = null;
|
452
|
-
|
453
|
-
object cellb = null;
|
454
|
-
|
455
|
-
object targetRange = null;
|
456
|
-
|
457
|
-
object[,] obj1 = null;
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
try
|
462
|
-
|
463
|
-
{
|
464
|
-
|
465
|
-
//Excelファイルを開いてオブジェクトにセットする ※GetOpenFileはDaoExcelFileクラスに実装しているが省略
|
466
|
-
|
467
|
-
book = GetOpenFile(filePath);
|
468
|
-
|
469
|
-
//ワークシートコレクションを取得する ※GetSheetsはDaoExcelFileクラスに実装しているが省略
|
470
|
-
|
471
|
-
sheets = GetSheets(book);
|
472
|
-
|
473
|
-
//シートを取得する ※GetSheetはDaoExcelFileクラスに実装しているが省略
|
474
|
-
|
475
|
-
sheet = GetSheet(sheets, sheetName);
|
476
|
-
|
477
|
-
//シートインデックスの取得
|
478
|
-
|
479
|
-
sheetIndex = (int)sheet.GetType().InvokeMember("Index", BindingFlags.GetProperty, null, sheet, null);
|
480
|
-
|
481
|
-
//シートの最終行を取得する ※GetLastRowIndexはDaoExcelFileクラスに実装しているが省略
|
482
|
-
|
483
|
-
int lastRow = GetLastRowIndex(book, sheetIndex);
|
484
|
-
|
485
|
-
//シートの最終列を取得する ※GetLastColumnIndexはDaoExcelFileクラスに実装しているが省略
|
486
|
-
|
487
|
-
int lastColumn = GetLastColumnIndex(book, sheetIndex);
|
488
|
-
|
489
|
-
//cellsを取得 ※GetCellsはDaoExcelFileクラスに実装しているが省略
|
490
|
-
|
491
|
-
cells = GetCells(sheet);
|
492
|
-
|
493
|
-
//範囲を取得する基準セルを取得 ※GetCellはDaoExcelFileクラスに実装しているが省略
|
494
|
-
|
495
|
-
cella = GetCell(cells, 1, 1);
|
496
|
-
|
497
|
-
cellb = GetCell(cells, lastRow, lastColumn);
|
498
|
-
|
499
|
-
////対象範囲を取得 ※GetRangeはDaoExcelFileクラスに実装しているが省略
|
500
|
-
|
501
|
-
targetRange = GetRange(sheet, cella, cellb);
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
//*********3回目の実行でここでエラーが発生する
|
508
|
-
|
509
|
-
//*********エラー内容:"プログラムを続行するための十分なメモリがありませんでした"
|
510
|
-
|
511
|
-
//オブジェクトの2次元配列へセット
|
512
|
-
|
513
|
-
//以降この配列にアクセスすることで処理を高速化
|
514
|
-
|
515
|
-
obj1 = (System.Object[,])targetRange.GetType().InvokeMember("Value2", BindingFlags.GetProperty, null, targetRange, null);
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
//DataTableに取得した配列の値をセットする ※SetDataToDataTableはDaoExcelFileクラスに実装しているが省略
|
522
|
-
|
523
|
-
SetDataToDataTable(obj1, fileData);
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
}
|
528
|
-
|
529
|
-
finally
|
530
|
-
|
531
|
-
{
|
532
|
-
|
533
|
-
//オブジェクトの解放
|
534
|
-
|
535
|
-
ReleaseComObject(targetRange);
|
536
|
-
|
537
|
-
ReleaseComObject(cellb);
|
538
|
-
|
539
|
-
ReleaseComObject(cella);
|
540
|
-
|
541
|
-
ReleaseComObject(cells);
|
542
|
-
|
543
|
-
ReleaseComObject(sheet);
|
544
|
-
|
545
|
-
ReleaseComObject(sheets);
|
546
|
-
|
547
|
-
ReleaseComObject(book);
|
548
|
-
|
549
|
-
}
|
550
|
-
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
}
|
556
|
-
|
557
|
-
|
558
|
-
|
559
525
|
}
|
560
526
|
|
527
|
+
|
528
|
+
|
561
529
|
```
|
562
530
|
|
563
531
|
|