1

I am working on an ASP.NET 4.0 website. I want to export data from database to excel (2013 Xlsx file) from the website.

I do not want to use Microsoft Interop excel dlls since it requires excel on the webserver.

I want to export the data to excel (2013 Xlsx file) and format the excel cells dynamically. (Font, Color coding, Merging cells and calculation)

How to format the excel cells dynamically based on the values in the cells without Interop dlls? Any suggestions or links to excel formatting would be helpful.

Thanks Ashok

2 Answers 2

1

EPPLUS does what you need and it is free and relatively painless to configure. There are samples included that help you get started.

Sign up to request clarification or add additional context in comments.

Comments

1

You can also use EasyXLS.

Check this sample for starting. It will guide you step by step how to export to xlsx, format and merge cells:

http://www.easyxls.com/manual/FAQ/export-to-excel-in-dot-net.html

In order to calculate formulas use a similar code:

//Create the Excel file and one sheet
ExcelDocument workbook = new ExcelDocument(); 
ExcelWorksheet xlsWorksheet = new ExcelWorksheet("Sheet1"); 
workbook.easy_addWorksheet(xlsWorksheet); 

// Adding some data to sheet 
ExcelTable xlsTable = xlsWorksheet.easy_getExcelTable(); 
xlsTable.easy_getCell(0,0).setValue("1"); 
xlsTable.easy_getCell(1,0).setValue("2"); 
xlsTable.easy_getCell(2,0).setValue("3"); 

//Set a formula on a cell
xlsTable.easy_getCell(3,0).setValue("=SUM(A1:A3)");

//Call the method used to compute the formulas 
String sError = xlsWorksheet.easy_computeFormulas(xls, true);

//Display the formula
Console.WriteLine("The result of the formula entered at position A4 is: " + 
           xlsTable.easy_getCell(3,0).getFormulaResultValue());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.