-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());
  }

文件路径错误,显示非法字符。

4

1 回答 1

5

因为您需要屏蔽该字符串中的反斜杠

"C:\ExcelWorkbooks\MyWorkbook.xlsm"

\用作转义字符,因此您也必须转义它们。要么用另一个逃避它们\

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

或使用@逐字声明该字符串:

@"C:\ExcelWorkbooks\MyWorkbook.xlsm"
于 2016-06-07T07:40:13.240 回答