JFToolkit.EncryptedExcel
1.5.1
dotnet add package JFToolkit.EncryptedExcel --version 1.5.1
NuGet\Install-Package JFToolkit.EncryptedExcel -Version 1.5.1
<PackageReference Include="JFToolkit.EncryptedExcel" Version="1.5.1" />
<PackageVersion Include="JFToolkit.EncryptedExcel" Version="1.5.1" />
<PackageReference Include="JFToolkit.EncryptedExcel" />
paket add JFToolkit.EncryptedExcel --version 1.5.1
#r "nuget: JFToolkit.EncryptedExcel, 1.5.1"
#:package JFToolkit.EncryptedExcel@1.5.1
#addin nuget:?package=JFToolkit.EncryptedExcel&version=1.5.1
#tool nuget:?package=JFToolkit.EncryptedExcel&version=1.5.1
JFToolkit.EncryptedExcel
A clean, focused .NET library for working with password-encrypted Excel files (.xlsx and .xls). Features the SecureExcelWorkbook API for simple encrypted Excel workflows: open → modify → save. Built on NPOI with Excel automation for encryption.
⚠️ Important: Microsoft Excel must be installed on the machine for encryption features (SaveAs with encryption). Reading and modifying encrypted files works without Excel. Macro-enabled .xlsm encryption is NOT supported in this release (1.5.0).
🚀 Key Features
- ✅ SecureExcelWorkbook API - Simple workflow for encrypted Excel files
- ✅ Read encrypted .xlsx / .xls files - Works on any platform (no Excel required)
- ✅ Modify data - Full editing capabilities with type safety
- ⚠️ Save with encryption (.xlsx / .xls) - Requires Microsoft Excel (Windows)
- ⚠️ .xlsm note - Macro-enabled files can be opened if already decrypted, but encrypted .xlsm save is not supported
- ✅ Save to separate files - Modify and save without overwriting originals
🎯 Platform Compatibility
Feature | Windows + Excel | Windows Only | Any Platform |
---|---|---|---|
Read encrypted files | ✅ | ✅ | ✅ |
Modify data | ✅ | ✅ | ✅ |
Save with encryption | ✅ | ❌ | ❌ |
Save without encryption | ✅ | ✅ | ✅ |
Framework Support
Framework | Support |
---|---|
.NET Standard 2.0 | ✅ (.NET Framework 4.6.1+, .NET Core 2.0+) |
.NET 6.0 (LTS) | ✅ |
.NET 8.0 (LTS) | ✅ |
.NET 9.0 | ✅ |
📦 Installation
# Package Manager Console
Install-Package JFToolkit.EncryptedExcel
# .NET CLI
dotnet add package JFToolkit.EncryptedExcel
# PackageReference
<PackageReference Include="JFToolkit.EncryptedExcel" Version="1.5.0" />
🔧 Quick Start with SecureExcelWorkbook
Simple Workflow: Open → Modify → Save
using JFToolkit.EncryptedExcel;
// Open encrypted Excel file
using var workbook = SecureExcelWorkbook.Open(@"C:\path\to\encrypted.xlsx", "password123");
// Read current values
var currentValue = workbook.GetCellValue(0, 0, 2); // Sheet 0, Row 0, Column C
Console.WriteLine($"Current value: {currentValue}");
// Modify content
workbook.SetCellValue(0, 0, 2, "New Value");
workbook.SetCellValue(0, 1, 2, "Another Value");
workbook.SetCellValue(0, 2, 2, DateTime.Now);
// Save to a separate file (keeps original unchanged)
bool saved = workbook.SaveAs(@"C:\path\to\modified.xlsx");
if (saved)
{
Console.WriteLine("✅ File saved with encryption (.xlsx)!");
// When you open this file in Excel: SINGLE password prompt only!
}
else
{
Console.WriteLine("❌ Encryption failed - Excel not available");
// File operations will still work, but without encryption
}
💡 Note: The
SaveAs()
method requires Microsoft Excel to be installed for encryption. If Excel is not available, the save operation will returnfalse
and you'll need to save without encryption or install Excel.
Advanced Usage with Direct NPOI Access
using JFToolkit.EncryptedExcel;
// For advanced scenarios, you can access the underlying NPOI workbook
using var workbook = SecureExcelWorkbook.Open(@"C:\data\encrypted.xlsx", "password123");
// Direct NPOI access for complex operations
var npoiWorkbook = workbook.Workbook;
var sheet = npoiWorkbook.GetSheetAt(0);
// Use full NPOI functionality
var row = sheet.CreateRow(10);
var cell = row.CreateCell(0);
cell.SetCellValue("Advanced modification");
Legacy API (Still Supported)
// The original EncryptedExcelReader is still available for backward compatibility
using var reader = EncryptedExcelReader.OpenFile(@"C:\data\encrypted.xlsx", "password123");
var workbook = reader.Workbook!;
var sheet = workbook.GetSheetAt(0);
// Use extension methods for easier data access
string name = sheet.GetStringValue(1, 0); // Row 1, Column A
int age = sheet.GetCellValue<int>(1, 1); // Row 1, Column B
double salary = sheet.GetCellValue<double>(1, 2); // Row 1, Column C
// Or save without encryption workbook.SaveToFile(@"C:\data\output_unencrypted.xlsx");
## 💼 Real-World Example
Perfect for applications that need to process encrypted Excel files while maintaining security:
```csharp
public async Task ProcessEmployeeData(string filePath, string password)
{
// 1. Open encrypted employee file
using var reader = EncryptedExcelReader.OpenFile(filePath, password);
var workbook = reader.Workbook!;
var sheet = workbook.GetSheetAt(0);
// 2. Apply business logic (e.g., salary increases)
for (int i = 1; i <= sheet.LastRowNum; i++)
{
var row = sheet.GetRow(i);
if (row?.GetCell(2) != null) // Salary column
{
var salaryCell = row.GetCell(2);
if (double.TryParse(salaryCell.ToString(), out double salary))
{
salaryCell.SetCellValue(salary * 1.05); // 5% increase
}
}
}
// 3. Add processing timestamp
var timestampRow = sheet.CreateRow(sheet.LastRowNum + 1);
timestampRow.CreateCell(0).SetCellValue($"Processed: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
// 4. Save with same encryption
string outputPath = filePath.Replace(".xlsx", "_processed.xlsx");
EncryptedExcelWriter.SaveEncryptedToFile(workbook, outputPath, password);
Console.WriteLine($"✅ Processed: {Path.GetFileName(outputPath)}");
}
🛠️ Extension Methods
The library includes helpful extension methods for common operations:
// Type-safe cell reading
string value = sheet.GetStringValue(row, col);
int number = sheet.GetCellValue<int>(row, col);
DateTime date = sheet.GetCellValue<DateTime>(row, col);
bool flag = sheet.GetCellValue<bool>(row, col);
// Easy cell writing
sheet.SetCellValue(row, col, "Hello World");
sheet.SetCellValue(row, col, 42);
sheet.SetCellValue(row, col, DateTime.Now);
// Quick row creation
sheet.AddRow("Name", 25, 50000.0, DateTime.Now, true);
// Simple file saving
workbook.SaveToFile(@"C:\output\file.xlsx");
🔐 Encryption Support
Automatic Encryption (Recommended)
The library automatically handles encryption using Excel automation:
// This will use Excel automation to maintain encryption
EncryptedExcelWriter.SaveEncryptedToFile(workbook, "output.xlsx", "password");
Requirements for Encryption
- Microsoft Excel installed on the machine
- Windows environment (for COM automation)
Fallback Options
If Excel automation is unavailable, the library:
- Saves as unencrypted file
- Provides clear instructions for manual encryption
- Ensures your workflow never breaks
📋 Supported Formats
- ✅ Excel 2007+ (.xlsx) - Full support (encrypted read/write)
- ✅ Excel 97-2003 (.xls) - Full support (encrypted read/write)
- ⚠️ Macro-enabled (.xlsm) - Not supported for encrypted workflows in 1.5.0
- ✅ Password-protected files - .xlsx / .xls
- ✅ Multiple worksheets - Complete access
🧪 Tested & Reliable
- ✅ Tested with real-world encrypted Excel files
- ✅ Handles various data types and formats
- ✅ Robust error handling and recovery
- ✅ Memory-efficient with proper disposal
- ✅ Thread-safe operations
🔧 System Requirements
✅ For Reading & Modifying Encrypted Files
- Any .NET-compatible platform
- No additional software required
⚠️ For Saving WITH Encryption
- Windows operating system
- Microsoft Excel installed (any recent version)
- .NET Framework or .NET Core/.NET 5+
Alternative: Save Without Encryption
// Works on any platform - no Excel required
using var workbook = SecureExcelWorkbook.Open("encrypted.xlsx", "password");
workbook.SetCellValue(0, 0, 2, "Modified");
// Save without encryption (works everywhere)
workbook.Workbook.SaveToFile("output.xlsx");
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Development Setup
- Clone the repository
- Open in Visual Studio or VS Code
- Run tests:
dotnet test
- Build:
dotnet build
📝 Issues & Support
- Bug Reports: GitHub Issues
- Feature Requests: GitHub Issues
- Documentation: Wiki
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🏷️ Version History
v1.1.0
- Added support for .NET Standard 2.0 (broader compatibility)
- Added support for .NET 6.0, .NET 8.0, and .NET 9.0
- Compatible with .NET Framework 4.6.1+ via .NET Standard 2.0
- Compatible with .NET Core 2.0+ via .NET Standard 2.0
- Improved cross-platform compatibility
v1.0.0
- Initial release
- Read password-encrypted Excel files
- Modify data with type safety
- Save with encryption using Excel automation
- Comprehensive documentation and examples
Made with ❤️ for developers who work with encrypted Excel files
⭐ Star this repo if you find it useful!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- NPOI (>= 2.7.4)
- System.Diagnostics.Process (>= 4.3.0)
- System.IO.FileSystem (>= 4.3.0)
-
net6.0
- NPOI (>= 2.7.4)
-
net8.0
- NPOI (>= 2.7.4)
-
net9.0
- NPOI (>= 2.7.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.5.1 - PACKAGE METADATA IMPROVEMENT:
- Added embedded README.md for NuGet gallery display.
- No functional code changes.
v1.5.0 - REMOVE XLSM CLAIMS:
- REMOVED: Macro-enabled (.xlsm) support claims due to unreliable encryption
- UPDATED: Documentation and tags to reflect support for .xlsx and .xls only
- NOTE: Use Excel manually for .xlsm scenarios; library focuses on stable formats
v1.4.0 - MAJOR CLEANUP AND RENAME:
- BREAKING: Renamed EncryptedXlsmManager to SecureExcelWorkbook (more descriptive)
- DOCUMENTATION: Clarified Excel installation requirement for encryption features
- Repository cleanup: Removed test files, examples, and alternative implementations from main library
- Streamlined to core functionality: SecureExcelWorkbook for simple workflow
- Fixed single password prompt issue (no more double password prompts in Excel)
- Supports separate file saving with SaveAs() method
- Cleaner API focused on the most common use case: open, modify, save encrypted Excel
- Simplified project structure for easier maintenance and understanding
v1.3.0:
- ENHANCED: Improved encryption fallback system with better error messages
- Added framework for future cross-platform encryption (OpenXML placeholder)
- Better detection and handling when Excel automation is unavailable
- Clearer guidance for users in environments without Excel
- Simplified approach focusing on reliable Excel automation when available
- Maintains excellent reading capabilities for encrypted files on all platforms
- Preparation for future true cross-platform encryption implementation
v1.2.5:
- SIMPLIFIED FIX: Removed complex two-stage save process that was causing Excel content errors
- Direct .xlsm save with explicit format parameters and VBA automation security settings
- Added explicit false parameters for Excel SaveAs to prevent format confusion
- Improved PowerShell automation with .xlsm-specific handling
- Should completely resolve "We found a problem with some content" errors
v1.2.4:
- CRITICAL FIX: Completely resolved "We found a problem with some content" error for .xlsm files
- Implemented two-stage save process: .xlsx first, then convert to .xlsm in Excel
- This eliminates content format inconsistencies that caused Excel errors
- Files now open cleanly in Excel without any error prompts or recovery dialogs
- Improved Excel automation reliability for macro-enabled files
v1.2.3:
- CRITICAL FIX: Resolved "We found a problem with some content" error when opening encrypted .xlsm files in Excel
- Fixed file format specification in Excel automation (COM and PowerShell)
- Properly handle .xlsm file format (52 - xlOpenXMLWorkbookMacroEnabled) during encryption
- Fixed temporary file handling to prevent corruption during .xlsm encryption
- Excel will no longer prompt for content recovery when opening encrypted .xlsm files
v1.2.2:
- FIXED: Package author metadata corrected from "Haral" to "JyslaFancy"
- Ensures proper attribution in NuGet Package Manager displays
v1.2.1:
- FIXED: "File format not valid" error when creating .xlsm files
- Improved .xlsm handling to avoid Excel compatibility issues
- Added clear documentation about NPOI .xlsm limitations
- Files with .xlsm extension are now saved as .xlsx to prevent errors
- Added helper methods for proper macro-enabled file workflow
v1.2.0:
- Added explicit support for macro-enabled Excel files (.xlsm)
- Enhanced documentation to clearly indicate .xlsm support
- Added macro-enabled file example in Examples.cs
- Updated package tags to include 'xlsm' and 'macro'
- Macros are preserved when reading and saving .xlsm files
v1.1.1:
- Fixed GitHub repository links in NuGet package metadata
- Package now correctly links to https://github.com/JyslaFancy/JFToolkit.EncryptedExcel
v1.1.0:
- Added support for .NET Standard 2.0 (broader compatibility)
- Added support for .NET 6.0, .NET 8.0, and .NET 9.0
- Compatible with .NET Framework 4.6.1+ via .NET Standard 2.0
- Compatible with .NET Core 2.0+ via .NET Standard 2.0
- Improved cross-platform compatibility
v1.0.0:
- Read password-encrypted Excel files (.xlsx, .xls)
- Modify cell data with type safety
- Add new rows and columns
- Save with encryption using Excel automation
- Comprehensive error handling and fallback options
- Extension methods for easy Excel manipulation