使用 interop.excel 将 Excel 文件保存在 C:\ 中会引发错误
我有一个 wpf 应用程序,我正在使用以下代码保存 Excel 文件。如果我选择文件路径为“C:\”,则会引发错误。其他文件路径没有此问题。
请帮忙。
excelWorkbook.SaveAs(saveAsPath, XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
编辑
文件名:C:\2347_H4141001_axm2312_20110627_042821.xls
错误是:
无法访问该文件。尝试以下方法之一:
• 确保指定的文件夹存在。
• 确保包含该文件的文件夹不是只读的。
• 确保文件名不包含以下任何字符:
> ? [ ] : |或*
• 确保文件/路径名不超过 218 个字符。
I have a wpf application and I am saving an Excel file using following code. If I select the file path as "C:\" it throws an error. No other file path has this issue.
Please help.
excelWorkbook.SaveAs(saveAsPath, XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
EDIT
File name: C:\2347_H4141001_axm2312_20110627_042821.xls
The error is:
The file could not be accessed. Try one of the following:
• Make sure the specified folder exists.
• Make sure the folder that contains the file is not read-only.
• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *
• Make sure the file/path name doesn't contain more than 218 characters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您检查过权限吗?默认情况下,Windows 会阻止写入
C:
等驱动器的 ROOT。字符“:”和“\”可能是原因,尝试在前面使用
@
,如下所示:@"C:\nameOfFile
Do you have checked permissions? Windows blocks writes to ROOT of drives like
C:
by default.The characters ":" and "\" may be the cause, try to use
@
before, like this:@"C:\nameOfFile