質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,16 +78,40 @@
|
|
78
78
|
|
79
79
|
// ** EXCEL 開始処理 ************************************************************
|
80
80
|
|
81
|
-
// ~~ //
|
82
|
-
|
83
|
-
// Excel 接続処理//
|
84
|
-
|
85
|
-
|
86
|
-
|
87
81
|
try
|
88
82
|
|
89
83
|
{
|
90
84
|
|
85
|
+
objExcel = new Excel.Application();
|
86
|
+
|
87
|
+
objExcel.DisplayAlerts = false;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
catch
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
throw new Exception("Microsoft Office Excelがインストールされていません。");
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
if (System.IO.File.Exists(path) == false)
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
throw new Exception("エクセルファイルが見つかりませんでした。\n" + path);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
try
|
112
|
+
|
113
|
+
{
|
114
|
+
|
91
115
|
objWorkBook = (Excel.Workbook)(objExcel.Workbooks.Open(path));
|
92
116
|
|
93
117
|
xlSheets = objWorkBook.Sheets;
|
@@ -138,11 +162,35 @@
|
|
138
162
|
|
139
163
|
|
140
164
|
|
141
|
-
|
165
|
+
objWorkBook.Close();
|
166
|
+
|
142
|
-
|
167
|
+
objExcel.Quit();
|
168
|
+
|
169
|
+
|
170
|
+
|
143
|
-
|
171
|
+
Marshal.FinalReleaseComObject(ws);
|
172
|
+
|
144
|
-
|
173
|
+
ws = null;
|
174
|
+
|
145
|
-
|
175
|
+
Marshal.FinalReleaseComObject(xlSheets);
|
176
|
+
|
177
|
+
xlSheets = null;
|
178
|
+
|
179
|
+
Marshal.FinalReleaseComObject(objWorkBook);
|
180
|
+
|
181
|
+
objWorkBook = null;
|
182
|
+
|
183
|
+
Marshal.FinalReleaseComObject(objExcel);
|
184
|
+
|
185
|
+
objExcel = null;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
GC.Collect();
|
190
|
+
|
191
|
+
GC.WaitForPendingFinalizers();
|
192
|
+
|
193
|
+
GC.Collect();
|
146
194
|
|
147
195
|
}
|
148
196
|
|