Decompiling an Excel template into source - #1 C# Kookerella Ltd. released a .NET 10 file-based app and CLI tool, fsopenxmldsl-mcp, that decompiles Excel templates into C# source code, enabling developers to reproduce spreadsheet styling programmatically. The tool, available as a dotnet global tool, converts an .xlsx file into a runnable .cs file that regenerates the original spreadsheet pixel-for-pixel, including styles and formulas, and the company demonstrated the workflow in a blog post with a sample invoice template. Decompiling an Excel template into source - 1 C You don’t have to hand-write Excel styling code. If someone already built the spreadsheet you need to reproduce — a finance person’s invoice template, a report layout a designer signed off on — you can reverse-engineer it into real source code, then wire in your own data. This is the first of four posts walking through the same demo in C , F , XSLT, and plain JSON. The full project is on GitHub: Kookerella.Demo.DecompileToSource https://github.com/Kookerella-Ltd/Kookerella.Demo.DecompileToSource . What we’re starting from A plain Excel file, built by hand in Excel. It has: - A bold, 16pt “INVOICE” title - A header row styled white-on-navy with a bottom border - Two sample line-item rows, with an Amount column computed as Qty Unit Price Nobody wrote any code to produce this file — it’s just a spreadsheet. Step 1: Install the tool The reverse-engineering happens via a CLI tool, fsopenxmldsl-mcp , published as a dotnet global tool: dotnet tool install -g Kookerella.FsOpenXmlDsl.Mcp Step 2: Reverse-engineer the template fsopenxmldsl-mcp convert templates/InvoiceTemplate.xlsx --lang csharp -o decompiled/InvoiceTemplate.g.cs This reads the real .xlsx file and prints out C code that reproduces it exactly. The top line of the result is: :package Kookerella.CsOpenXmlDsl@0.3.2 That :package line is a .NET 10 file-based app https://learn.microsoft.com/dotnet/core/whatsnew/dotnet-10 file-based-apps directive — this single .cs file is a complete, runnable program with no .csproj needed. You can run it immediately, on any machine with the .NET 10 SDK: cd decompiled dotnet run InvoiceTemplate.g.cs That produces output.xlsx — pixel-for-pixel the same as the original template. Nothing was lost in translation: title, header styling, borders, currency formatting, and the Qty Unit Price formulas are all there, expressed as plain C method calls Cell.Text ... , .WithStyle ... , Cell.Formula ... , and so on . This is the point where “decompiling a spreadsheet” stops being a metaphor. You now have the template as source code you can read, diff, and edit. Step 3: Adding the package to a real project The file-based app above pinned the package inline for convenience. In a normal project you add it the usual way: dotnet add package Kookerella.CsOpenXmlDsl Kookerella.CsOpenXmlDsl is a C wrapper around a separate F core library, Kookerella.FsOpenXmlDsl , which does the actual OOXML reading/writing. Step 4: Turning the decompiled snippet into real code The decompiled file is disposable — it’s the starting point, not the deliverable. Nobody wants to hardcode “Widgets” and “Gadgets” forever. The diff from the decompiled file to a maintained version is deliberately small: Wrap the top-level statements in a class and a Build method that takes real data IEnumerable