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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 bReadOnly=false)
tonyqus marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
return OPCPackage.Open(path);
return OPCPackage.Open(path, bReadOnly? PackageAccess.READ: PackageAccess.READ_WRITE);
}
catch (InvalidFormatException e)
{
Expand Down
4 changes: 2 additions & 2 deletions ooxml/Util/PackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace NPOI.Util
public class PackageHelper
{

public static OPCPackage Open(Stream is1)
public static OPCPackage Open(Stream stream, bool bReadonly = false)
{
try
{
return OPCPackage.Open(is1);
return OPCPackage.Open(stream, bReadonly);
}
catch (InvalidFormatException e)
{
Expand Down
10 changes: 5 additions & 5 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 bReadonly=false)
: base(PackageHelper.Open(fileStream, bReadonly))
tonyqus marked this conversation as resolved.
Show resolved Hide resolved
{
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 bReadonly = false)
: this(OPCPackage.Open(file, bReadonly? PackageAccess.READ: PackageAccess.READ_WRITE))
{

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

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 bReadonly)
{
OPCPackage pack = new ZipPackage(in1, bReadonly ? PackageAccess.READ : PackageAccess.READ_WRITE);
OPCPackage pack = new ZipPackage(stream, bReadonly ? PackageAccess.READ : PackageAccess.READ_WRITE);
if (pack.partList == null)
{
pack.GetParts();
Expand Down