从 C# 应用程序执行 excel
我想使用一个进程从 C# 中的类中打开一个文件,该文件位于我询问用户的目录中。
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXCEL.EXE";
startInfo.Arguments = Here goes the directory I asked
Process.Start(startInfo);
问题是,当用户指示的文件位置有空格“”时,Excel 认为我正在发送两个单独的位置。 例如,对于 C:\Users\dj\Desktop\da ba,excel 尝试将“C:\Users\dj\Desktop\da”作为一个文件打开,同时将“ba”作为另一个文件打开。 如何将包含空格的位置发送到 Excel,而不会出现此错误? 地址如 C:\Users\dj\Desktop\daba 没有空格,它可以完美地工作。
I want to open a file from a Class in C# using a Process, located in a directoy I asked the user.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXCEL.EXE";
startInfo.Arguments = Here goes the directory I asked
Process.Start(startInfo);
The problem, is that when the location of the file indicated by the user has an space," ", excel thinks that I'm sending two sepparate locations. For example with C:\Users\dj\Desktop\da ba excel tries to open " C:\Users\dj\Desktop\da" as one file, and at the same time "ba" as another file. How can I send a location to excel which has an space, without having this error? with an addres like C:\Users\dj\Desktop\daba without an space it works perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试引用你的路径:
蒂姆
Try quoting your path:
Tim
尝试使用字符串文字
Try using a string literal
这种方法有效
This way works