Ole Albers
Ole Albers

Reputation: 9305

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?

Upvotes: 1

Views: 468

Answers (3)

dave823
dave823

Reputation: 1211

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

Upvotes: 1

Chris Warnes
Chris Warnes

Reputation: 728

Another Library you can Try is ClosedXML, in my experience it makes it very easy to manipulate Excel documents.

Upvotes: 0

Avinash patil
Avinash patil

Reputation: 1819

I suggest you to try NPOI this one gives you the ability to serve the Temple structure. i was having problem with the template editing i solved by sing this. this might help you.

for more help about this you can view Create excel file

Upvotes: 2

Related Questions