Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Package Readonly argument for XSSFWorkbook constructor #1336

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ooxml/POIXMLDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private void init(OPCPackage pkg)
* in the event of a problem.
* Works around shortcomings in java's this() constructor calls
*/
public static OPCPackage OpenPackage(String path)
public static OPCPackage OpenPackage(String path, bool readOnly = false)
{
try
{
return OPCPackage.Open(path);
return OPCPackage.Open(path, readOnly ? PackageAccess.READ: PackageAccess.READ_WRITE);
}
catch (InvalidFormatException e)
{
Expand Down
4 changes: 2 additions & 2 deletions ooxml/SS/UserModel/WorkbookFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static IWorkbook Create(OPCPackage pkg)
/// <returns>IWorkbook depending on the input HSSFWorkbook or XSSFWorkbook is returned.</returns>
/// <remarks>Your input stream MUST either support mark/reset, or
/// be wrapped as a {@link PushbackInputStream}!</remarks>
public static IWorkbook Create(Stream inputStream, bool bReadonly)
public static IWorkbook Create(Stream inputStream, bool readOnly)
{
if (inputStream.Length == 0)
throw new EmptyFileException();
Expand All @@ -133,7 +133,7 @@ public static IWorkbook Create(Stream inputStream, bool bReadonly)
inputStream.Position = 0;
if (DocumentFactoryHelper.HasOOXMLHeader(inputStream))
{
return new XSSFWorkbook(OPCPackage.Open(inputStream, bReadonly));
return new XSSFWorkbook(OPCPackage.Open(inputStream, readOnly));
}
throw new InvalidFormatException("Your stream was neither an OLE2 stream, nor an OOXML stream.");
}
Expand Down
5 changes: 2 additions & 3 deletions ooxml/Util/PackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ namespace NPOI.Util
*/
public class PackageHelper
{

public static OPCPackage Open(Stream is1)
public static OPCPackage Open(Stream stream, bool readOnly = false)
{
try
{
return OPCPackage.Open(is1);
return OPCPackage.Open(stream, readOnly);
}
catch (InvalidFormatException e)
{
Expand Down
12 changes: 6 additions & 6 deletions ooxml/XSSF/UserModel/XSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public XSSFWorkbook(OPCPackage pkg)
* pkg.close(); // gracefully closes the underlying zip file
* </code></pre>
*/
public XSSFWorkbook(Stream is1)
: base(PackageHelper.Open(is1))
public XSSFWorkbook(Stream fileStream, bool readOnly = false)
: base(PackageHelper.Open(fileStream, readOnly))
{
BeforeDocumentRead();

Expand Down Expand Up @@ -259,8 +259,8 @@ public XSSFWorkbook(Stream is1)
*
* @param file the file to open
*/
public XSSFWorkbook(FileInfo file)
: this(OPCPackage.Open(file))
public XSSFWorkbook(FileInfo file, bool readOnly = false)
: this(OPCPackage.Open(file, readOnly? PackageAccess.READ: PackageAccess.READ_WRITE))
{

}
Expand Down Expand Up @@ -301,8 +301,8 @@ public XSSFWorkbook(FileInfo file)
*
* @param path the file name.
*/
public XSSFWorkbook(String path)
: this(OpenPackage(path))
public XSSFWorkbook(String path, bool readOnly = false)
: this(OpenPackage(path, readOnly))
{

}
Expand Down
8 changes: 4 additions & 4 deletions openxml4Net/OPC/OPCPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ public static OPCPackage Open(FileInfo file, PackageAccess access)
* The InputStream to read the package from
* @return A PackageBase object
*/
public static OPCPackage Open(Stream in1)
public static OPCPackage Open(Stream stream)
{
OPCPackage pack = new ZipPackage(in1, PackageAccess.READ_WRITE);
OPCPackage pack = new ZipPackage(stream, PackageAccess.READ_WRITE);
try
{
if (pack.partList == null)
Expand All @@ -317,9 +317,9 @@ public static OPCPackage Open(Stream in1)
return pack;
}

public static OPCPackage Open(Stream in1,bool bReadonly)
public static OPCPackage Open(Stream stream,bool readOnly)
{
OPCPackage pack = new ZipPackage(in1, bReadonly ? PackageAccess.READ : PackageAccess.READ_WRITE);
OPCPackage pack = new ZipPackage(stream, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
if (pack.partList == null)
{
pack.GetParts();
Expand Down
Loading