-4
ExcelDriver xl = new ExcelDriver();
xl.OpenWorkbook("C:\ExcelWorkbooks\MyWorkbook.xlsm");
 Object[,] obj = (Object[,])xl.GetCellValue("A2:B4");
  for(int i = 1; i <= obj.GetLength(0); i++)
 {
  for(int j = 1; j <= obj.GetLength(1); j++)
  {
     Console.WriteLine(obj[i,j].ToString());
  }

Error at the filepath saying illegal characters.

1 Answers1

5

Because you need to mask the back slashes in that string

"C:\ExcelWorkbooks\MyWorkbook.xlsm"

\ is used as escaping character, so you have to escape them, too. Either escape them with another \:

"C:\\ExcelWorkbooks\\MyWorkbook.xlsm"

or use @ to declare that string as verbatim:

@"C:\ExcelWorkbooks\MyWorkbook.xlsm"
René Vogt
  • 43,056
  • 14
  • 77
  • 99
  • @MohammedFaisal so you probably have some other invalid character in that string (for example some undisplayed unicode character). Try retyping the path. – René Vogt Jun 07 '16 at 09:04
  • i retried as u said..still the same error. The weird thing is there seems to be no error when I write the code, but when I build it, the error appears. – Mohammed Faisal Jun 07 '16 at 09:37