我正在使用 SpreadsheetLight 3.5.0 创建一个包含图像的 Excel 文件。保存 Excel 会导致异常。
这段代码
If OpenDialog.ShowDialog() = DialogResult.OK Then
Using pDoc = New SLDocument()
Dim pSLPic = New SLPicture(OpenDialog.FileName)
pSLPic.SetPosition(1, 1)
pDoc.InsertPicture(pSLPic)
pDoc.SaveAs("test.xlsx")
End Using
End If
调用 pDoc.SaveAs 时会导致以下异常。我可以在 PictureBox 中显示相同的图像,或者通过在资源管理器中双击将其打开。所以Windows访问权限应该不会有任何问题。
System.UnauthorizedAccessException: Access to the path '\\pomari.local\Pomarfin\ParYhteiset\Tuotekuvat\12006.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at SpreadsheetLight.SLDocument.WriteImageParts(DrawingsPart dp) at SpreadsheetLight.SLDocument.WriteSelectedWorksheet() at SpreadsheetLight.SLDocument.CloseAndCleanUp() at SpreadsheetLight.SLDocument.SaveAs(String FileName)
该错误并非在所有环境中都会发生。文件路径是否使用映射驱动器或 UNC 路径并不重要。
您对接下来要尝试什么有什么建议吗?
授予包含图像的文件夹写入权限解决了问题。所以保存Excel时读取权限似乎不够。