我试图编辑一个打开的excel文件(由共享网络中的另一个用户),以便对其进行一些更改并将其保存回来。但是,当我试图打开我得到以下错误文件:当Excel文件被其他用户打开时写入
Message=The process cannot access the file
'Y:\COMMON\SharedFolders\Export.xlsx', because it is being used by another process.
Source=mscorlib
StackTrace:
à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
à System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
à System.IO.File.ReadAllBytes(String path)
à OfficeOpenXml.ExcelPackage.ReadFile()
à OfficeOpenXml.ExcelPackage.ConstructNewFile(Stream stream, String password)
à OfficeOpenXml.ExcelPackage..ctor(FileInfo newFile)
顺便说一句,我使用的EPPLUS库。
那么你显然不能使用被另一个进程锁定的文件......你可能会尝试复制一个文件,对其进行更改并等待原始文件不再被锁定。 – walther 2014-08-27 14:36:18
是否有可能杀死用户进程? – 2014-08-27 14:37:33
理论上可以肯定的是,如果您有权访问他的机器并且拥有正确的权限,但我想这在网络上会有点棘手。 – walther 2014-08-27 14:39:23