如何修复var chartObject = charts.Add(60,10,600,300)中的exception为Microsoft.Office.Interop.Excel.ChartObject?

我尝试使用Excel中的值创build图表,当我运行代码时:

private void DesignChartInExcel(int nbLigne) { line 1 string fileName = @"C:\Users\LUNA\Documents\lili.xlsx"; line 2 object missing = Type.Missing; line 3 object misValue = System.Reflection.Missing.Value; //create excel line 4 Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //add excel workbook line 5 Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(fileName); // Add chart. Line 6 var sheet = (Worksheet)excel.ActiveSheet; Line 7 var charts = sheet.ChartObjects() as Microsoft.Office.Interop.Excel.ChartObjects; Line 8 var chartObject = charts.Add(60, 10, 600, 300) as Microsoft.Office.Interop.Excel.ChartObject; var chart = chartObject.Chart; // Set chart range. var range = (Range)sheet.get_Range("A1", "b101"); // range.NumberFormat = "0"; chart.SetSourceData(range,Missing.Value); // Set chart properties. chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine; chart.ChartWizard(Source: range, Title: "Complexity Chart - AFDC is satisfied", CategoryTitle: "X", ValueTitle: "Y"); //wb.Save(); wb.Close(true, misValue, misValue); excel.Quit(); releaseObject(sheet); releaseObject(wb); releaseObject(excel); } 

我不得不以下exception:服务器抛出一个exception。 (从HRESULTexception:0x80010105(RPC_E_SERVERFAULT))exception是在第8行产生。如何解决?