Search code examples
c#excelexcellibrary

C# modifiing Excel files, keeping the style


I have an excel - file that works as a template for data to be generated. I need to modify this Excel-Sheet, duplicate it a few times and add data to it.

I tried using excellibrary from nuget the following way:

Workbook tmpl = Workbook.Load("template.xlt");
tmpl.Save("newFile.xls");

As you can see I do nothing at all: Just opening the Excel File and saving it under a different name. The Problem is: All the content is inside the target xls, but all Styles are gone (Font sizes, Colors, etc.)

Using an XLS file instead of a xlt when loading does not change a thing.

Is there a way to solve this or another library that works better?


Solution

  • I would recommend using the OpenXML SDK from Microsoft. It allows you to do about anything with the newer xlsx files (Excel 2007 and up) using C#.

    OpenXML SDK for Office