我想尝试获取字符串并将其写入文件Excel
,但是当我尝试运行它时它会抛出异常。
代码是这样的:
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
string workbookPath = "c:/Libro1.xlsx";
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet); //en esta instruccion me sale la excepcion
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");
根据您得到的异常:
似乎在excelSheets中没有名为Sheet1的工作表。可能它被称为Sheet1并且你有西班牙语的 excel。