Skip to content

JyslaFancy/JFToolkit.EncryptedExcel

Repository files navigation

JFToolkit.EncryptedExcel

Zero-dependency .NET library for opening encrypted and unencrypted Excel files, modifying cell content programmatically, and saving with the same password — via late-bound COM interop. Works with Excel 2007 through Office 365.

License Target

The problem

You have password-protected Excel files that need programmatic updates — budget sheets, inventory lists, report templates. Every month someone opens each file, types in the password, updates a few cells, saves.

This library makes it one line of code per operation.

Install

dotnet add package JFToolkit.EncryptedExcel

Zero dependencies. No NPOI, no Excel SDK, no Office PIA. Pure C# COM interop — late-bound, so it works with any Excel version from 2007 to Office 365.

Usage

Your workflow: open → modify → save encrypted

using JFToolkit.EncryptedExcel;

// Open an encrypted file
using var doc = EncryptedExcelDocument.Open(
    @"C:\budget\q3_2026.xlsx",
    password: "secret123");

// Modify cells (1-based row/column)
doc.SetCellValue("Sheet1", 5, 2, 150000);      // B5 = 150 000
doc.SetCellValue("Sheet1", 6, 2, 320000);      // B6 = 320 000
doc.SetCellValue("Sheet1", 7, 1, "Q3 Total");  // A7 = "Q3 Total"

// Save as new file with same password
doc.SaveAs(@"C:\budget\q3_2026_updated.xlsx");

Open unencrypted files too

// No password? No problem — works the same way
using var doc = EncryptedExcelDocument.Open(@"C:\templates\report.xlsx");
doc.SetCellValue("Data", 2, 3, "Filled by automation");
doc.Save(); // overwrites original

Change password on save

using var doc = EncryptedExcelDocument.Open(@"C:\old\file.xlsx", "oldpass");
doc.SetCellValue(3, 1, "Updated");
doc.SaveAs(@"C:\new\file.xlsx", "newpass456");

Read cells

using var doc = EncryptedExcelDocument.Open(@"C:\data\sheet.xlsx", "pw");

// By sheet name
var value = doc.GetCellValue("Ark1", 3, 2);  // B3 on Ark1

// First sheet shorthand
var firstCell = doc.GetCellValue(1, 1);       // A1

// List all sheets
foreach (var name in doc.GetSheetNames())
    Console.WriteLine(name);

Supported features

Feature Notes
Open encrypted .xlsx / .xls File-open password (standard Excel encryption)
Open unencrypted files Works identically
Read/write cell values 1-based row/column, any sheet by name or index
Save encrypted Same password, or new password
Save unencrypted Omit password
Sheet enumeration Names and count

What it does NOT do (by design)

  • No formula creation (reads/writes cell values only)
  • No chart, pivot table, or formatting manipulation
  • No .xlsm (macro-enabled) encryption
  • No cross-platform — requires Microsoft Excel on Windows (COM)
  • No streaming/byte-array I/O — works with file paths

Requirements

  • .NET 8, .NET 9, or .NET 10
  • Microsoft Excel 2007 or later (Windows only — COM interop)

How it works

Late-bound COM interop. The library creates an invisible Excel instance via Excel.Application ProgID, opens the workbook with Workbooks.Open(Password:=...), reads/writes cells via the Excel object model, and saves with Workbook.SaveAs(Password:=...).

No compile-time dependency on any Excel interop assembly — it uses dynamic and Type.GetTypeFromProgID. The COM lifecycle is fully managed: IDisposable on the document ensures Excel is always closed and cleaned up, even on exceptions.

License

MIT — use it anywhere, commercial or personal.

About

A .NET library for reading and writing password-encrypted Excel files with multi-framework support"

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages