I want to try to get and write a string to a file Excel
, but it throws me an exception when I try to run it.
The code is this:
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");
According to the exception that you get:
It seems that in excelSheets there is no such sheet called Sheet1 . Possibly it is called Sheet1 and you have the excel in Spanish .