OleDbConnection 从索引 166 处开始,初始化字符串的格式不符合规范。

连接Excel 提示   从索引 166 处开始,初始化字符串的格式不符合规范。

原来机器只安装的wps测试没问题 连接字符串是 String.Format(@"Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;Data Source={0};Extended Properties=\Excel 12.0;HDR=YES;IMEX=1;\", FilePath);

出错原因是 Extended Properties里面的内容没有加引号

String.Format(@"Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;Data Source={0};Extended Properties=""Excel 12.0;HDR=YES;IMEX=1;""", FilePath);

原文地址:https://www.cnblogs.com/freexiaoyu/p/2718050.html