Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Commented Unassigned: Exception opening a file in read-only mode [13397]

$
0
0
If I open an xlsx file with
```
workBook = new XSSFWorkbook(OPCPackage.Open(path,PackageAccess.READ));
```
it later throws an exception
```
NPOI.POIXMLException
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook.OnDocumentRead()
en NPOI.POIXMLDocument.Load(POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook..ctor(OPCPackage pkg)
```
containing
```
System.InvalidOperationException "Operation not allowed, document open in read only mode!"
en NPOI.OpenXml4Net.OPC.OPCPackage.ThrowExceptionIfReadOnly()
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType, Boolean loadRelationships)
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
```
It works if I use read&write PackageAccess.
Doesn't NPOI allow to simply read the file?
Comments: ** Comment from web user: tonyqus **

PackageAccess.READ and FileAccess.Read are different. Please read the Excel file using FileStream with readonly mode and then pass the filestream to XSSFWorkbook. It should work.


Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>