-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for encrypting XLSX files with a password #1642
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
base: master
Are you sure you want to change the base?
Conversation
|
Reference: https://poi.apache.org/encryption.html XML-based formats - Encryptionhttps://github.com/nissl-lab/npoi/blob/master/ooxml/POIFS/Crypt/Agile/AgileEncryptionInfoBuilder.cs |
|
Although the code is working (as you mentioned), it's not the expected coding style of NPOI. One way is to add IWorkbook.Write(stream, password) as a new interface for OOXML Excel files |
|
thanks for review. I check your comment tommorow. I've write a "can not pass test" code? |
…x_pr_review # Conflicts: # main/POIFS/Crypt/EncryptionInfo.cs
|
windows-latest test always fails. Please ignore the error. |
- remove japanese comment
|
Thank you for your review! I've updated the implementation to follow the NPOI coding style as you suggested. Changes
Usage ExamplesEasy Way (New NPOI-style API)XSSFWorkbook wb = new();
ISheet sheet = wb.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue("Hello");
using(FileStream fs = File.Create(outputPath))
{
wb.Write(fs, password);
}POI-Compatible WaycsharpXSSFWorkbook wb = new();
ISheet sheet = wb.CreateSheet("Sheet1");
sheet.CreateRow(0).CreateCell(0).SetCellValue("Hello");
using(POIFSFileSystem fs = new())
{
EncryptionInfo info = new(EncryptionMode.AgileXlsx);
Encryptor enc = info.Encryptor;
enc.ConfirmPassword(password);
using(OutputStream os = enc.GetDataStream(fs))
{
wb.Write(os);
}
using(FileStream fos = File.Create(outputPath))
{
fs.WriteFileSystem(fos);
}
}Please let me know if there are any other changes needed. Thank you! |
add encrypt options
|
Add support for encrypting XLSX files with a password
I've implemented this feature by studying Apache POI’s code base.
With this PR, NPOI can now create password-protected .xlsx files.
Basic usage
Tests
Includes byte-level comparison with a file encrypted by Apache POI.
See: TestCases.POIFS.FileSystem.TestPasswordXlsxOutputStream.TestEncryptor
Notes
I’m relatively new to C#, POI and NPOI.
Please review the code and give feedback on design, naming, and integration with the existing NPOI style.
ref: #1641
Thank you!