1

Excel ファイルを開き、その背後にあるクエリを更新してから、C# でファイルを保存して閉じようとしています。

私は次のものを持っていますが、最初に次の行でエラーが発生しています:

        object _missingValue = System.Reflection.Missing.Value;
        Application excel = new Application();
        Workbook theWorkbook = excelFile.Workbooks._Open(txtLocation.Text, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue);
        Sheets sheets = (Sheets)theWorkbook.Worksheets;
        theWorkbook.RefreshAll();
        theWorkbook.Save();
        excel.Quit();

Microsoft.Office.Interop.Excel リファレンスを追加しましたが、まだ問題があります。何が欠けていますか?

4

1 に答える 1

1

次の方法で解決しました。

object _missingValue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
            Workbook theWorkbook = excel.Workbooks.Open(txtLocation.Text, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue);
Sheets sheets = (Sheets)theWorkbook.Worksheets;
theWorkbook.Save();
excel.Quit();
return true;

ありがとう!

于 2012-10-03T15:49:13.523 に答える