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

Exposing read-only mode when creating XSSFWorkbook #1196

Closed
1 of 5 tasks
lahma opened this issue Oct 12, 2023 · 1 comment · Fixed by #1336
Closed
1 of 5 tasks

Exposing read-only mode when creating XSSFWorkbook #1196

lahma opened this issue Oct 12, 2023 · 1 comment · Fixed by #1336

Comments

@lahma
Copy link
Collaborator

lahma commented Oct 12, 2023

NPOI Version Used

Latest master.

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Use Case

Faster loading of XLSX files when only reading is required.

Description

When checking load performance for document I realized that that disposing a file caused write operation to it. This is because the default operating mode is Read/Write.

public void Close()
{
if (pkg != null)
{
if (pkg.GetPackageAccess() == PackageAccess.READ)
{
pkg.Revert();
}
else
{
pkg.Close();
}
pkg = null;
}
}

It's not intuitive to find how to open file in read-only mode as requires call to OPCPackage.Open. Testing against large file in benchmark project:

var sw = Stopwatch.StartNew();
var package = OPCPackage.Open(_filePath, PackageAccess.READ);
var workbook = new XSSFWorkbook(package);
workbook.Dispose();
sw.Stop();
Console.WriteLine($"Opening as read: {sw.Elapsed}");

sw = Stopwatch.StartNew();
workbook = new XSSFWorkbook(_filePath);
workbook.Dispose();
sw.Stop();
Console.WriteLine($"Opening as read-write: {sw.Elapsed}");
Opening as read: 00:00:12.4033364
Opening as read-write: 00:00:18.3022784
Opening as read: 00:00:12.7855461
Opening as read-write: 00:00:17.7144075

Would it make sense to expose constructor parameter or options to create XSSFWorkbook in faster read-only mode?

@tonyqus tonyqus added this to the NPOI 2.7.0 milestone Oct 12, 2023
@tonyqus
Copy link
Member

tonyqus commented Oct 12, 2023

This looks promising. I'll dig into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants