user1658567
user1658567

Reputation: 201

How to create excel in my c# application if msoffice is not installed

Hi I am creating an application through which i need to create an excel. I have added Microsoft Excel 12.Object Library as Reference to application. But my server didnt get Msoffice Installed in it. So how can i create Excel in that server.

Upvotes: 1

Views: 2751

Answers (4)

Tim Schmelter
Tim Schmelter

Reputation: 460128

I can recommend EPPlus because it's simple, powerful and works without having office/excel being installed with Excel 2007 spreadsheets(xlsx-files). It's license model is LGPL.

var excel = new ExcelPackage();
excel.File = new System.IO.FileInfo(@"C:\Temp\AnExcelFile.xlsx");
if (excel.File.Exists)
    excel.Load(excel.File.Open(FileMode.Open));
ExcelWorksheet ws = excel.Workbook.Worksheets.Add("Worksheet-Name");//must be unique and less than 31 characters long
ws.Cells[26, 1].LoadFromDataTable(dt, true); //loading from DataTable, the 2.Parameter is PrintHeaders
ws.Cells[26, 1].LoadFromCollection(query, true); //loading by LINQ-Query also possible
excel.Save();

Upvotes: 4

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

If you need to create new office format documents known as openxml, you can see at http://www.microsoft.com/en-us/download/details.aspx?id=5124

Upvotes: 1

ekolis
ekolis

Reputation: 6786

There are a number of third party libraries - I think ComponentOne makes one, for instance - which are capable of creating Excel files, and I think at least some of them are independent of Excel, so they can make Excel files without having Excel installed on the server.

An alternate solution would be to create some other format that Excel can read, for instance CSV. Using CSV will mean that you don't get the fancy formatting provided by Excel, but at least you don't need to license a third party component or install Excel on the server.

Upvotes: 1

martavoi
martavoi

Reputation: 7092

There is now way to create ms objects, while MS Office is not installed. Added library is nothing more than interfaces wrapper.

Upvotes: 0

Related Questions