次のコードがあります。私はそれを行う必要がありますが、私は行をExcelのコメントを外していない正常に閉じる行をコメントアウトする場合。C#Application.Excel.Quit 1行のコードのために機能しません
私は次に何を試すべきか分かりません。私は2ドットの問題から離れて滞在し、1ドットを貼り付けようとしました。しかし、今私は今何をすべきか不明です。
コード内のdtは、私が設定しているDataTableです。
Excel.Application app = null;
Excel.Workbooks books = null;
Excel.Workbook book = null;
Excel.Sheets sheets = null;
Excel.Worksheet sheet = null;
Excel.Range range = null;
try
{
app = new Excel.Application();
books = app.Workbooks;
book = books.Open(FilePath);
sheets = book.Sheets;
sheet = book.ActiveSheet;
int rcount = 45;
UpdateProgressBarMaxMethod(pbAssets, rcount);
int i = 0;
for (; i < rcount; i++)
{
//Comment out the below line and it works fine
dt.Rows.Add(sheet.Cells[i + 1, 1].Value,
sheet.Cells[i + 1, 2].Value,
sheet.Cells[i + 1, 3].Value,
sheet.Cells[i + 1, 4].Value,
sheet.Cells[i + 1, 5].Value,
sheet.Cells[i + 1, 6].Value,
sheet.Cells[i + 1, 7].Value,
sheet.Cells[i + 1, 8].Value,
sheet.Cells[i + 1, 9].Value);
UpdateProgressBarMethod(pbAssets, i);
}
UpdateProgressBarMethod(pbAssets, 0);
book.Close();
app.Quit();
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
finally
{
if (range != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
if (sheet != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
if (sheets != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);
if (book != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
if (books != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(books);
if (app != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
}
「dt」とは –
申し訳ありませんもっと詳しく説明します。 DTはDataTableです –
データテーブルを正しく初期化したと仮定します。次に、少なくとも1つのセルの内容が、データ型の列型の型と一致しません。 – alsaleem