如何在Excel文件名包含空格?使用C#在连接字符串 [英] how to specify the connection string if the excel file name contains white space?using c#

查看:740
本文介绍了如何在Excel文件名包含空格?使用C#在连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\data\\[Proj_Resource Details 20110118.xlsx];Extended Properties=Excel 12.0";



我提到的[]它仍然是扔exception.how我可以解决这个问题。
PLZ提的正确路径。

i mentioned [ ] still it is throwing exception.how can i solve this problem. plz mention the correct path

推荐答案

用引号括整个文件名,但因为这是一个字符串使用\\ \\逃脱他们:

Wrap the whole filename in quotes, but because this is a literal string use \" to escape them:

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"D:\\data\\Proj_Resource Details 20110118.xlsx\";Extended Properties=Excel 12.0";

这篇关于如何在Excel文件名包含空格?使用C#在连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆