gpt4 book ai didi

c# - Excel InterOp : How to WorkBook. SaveAs 在不允许 ":"时使用绝对路径?

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:27 33 4
gpt4 key购买 nike

我正在尝试使用以下代码从内存中保存工作簿:

 this.Target.WorkBook.SaveAs(this.Target.WorkBookPath, Interop.XlFileFormat.xlWorkbookNormal,
Type.Missing, Type.Missing,
Type.Missing, Type.Missing,
Interop.XlSaveAsAccessMode.xlNoChange,
Type.Missing,Type.Missing,Type.Missing,Type.Missing);

从配置文件中读取 this.Target.WorkBookPath 的位置为:

D:\Devzone\rpt_SalesMargins2

但我收到此错误消息:

The file could not be accessed. Try one of the following:\n\n• Make sure the specified folder exists. \n• Make sure the folder that contains the file is not read-only.\n• Make sure the file name does not contain any of the following characters: < > ? [ ] : | or *\n• Make sure the file/path name doesn't contain more than 218 characters.

因此,如果我不能使用“:”,那么我该如何指定 D:\呢?

更新/健全性检查

config

SANITY

在这张图片中,文件名为 rego,我尝试了几个随机名称,并且都作为相对路径工作,但在绝对化时失败。

最佳答案

我认为问题不在于 : 作为驱动器分隔符。来自 Microsoft 支持:

For example, the path for a file might resemple the following: 'c:\excel\personal...[my workbook.xls]up_to_31_char_sheetname'!$A$1

Note This behavior will also occur if there is a square bracket in the path. (emphasis mine)

http://support.microsoft.com/kb/213983

他们举了一个包含驱动器盘符的错误路径的例子,并说错误的东西是路径中的[

您尝试使用的完整路径是什么?

关于c# - Excel InterOp : How to WorkBook. SaveAs 在不允许 ":"时使用绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11661390/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com