Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel date format using EPPlus

Tags:

c#

epplus

I'm having trouble with format my cells to Date.

FileInfo info = new FileInfo(path); using (ExcelPackage package = new ExcelPackage(info)) {       ExcelWorksheet ws = package.Workbook.Worksheets.Add(sheetName);       ws.Cells[3, 1].Style.Numberformat.Format = "yyyy-mm-dd";       ws.Cells["A3"].Formula = "=DATE(2014,10,5)"; } 

Output from this in Excel: 41 917,00

Why is this not working?

like image 760
MrProgram Avatar asked Apr 03 '14 08:04

MrProgram


People also ask

How do I change the date format on EPPlus?

Format = "yyyy-mm-dd"; ws. Cells[3, 1]. Value = new DateTime(2014,10,5); ws.

Does EPPlus work with XLS?

EPPlus does not work with the XLS format. Only XLSX. You'll need to find a new library.

What is the use of EPPlus?

EPPlus is a very helpful open-source 3rd party DLL for writing data to excel. EPPlus supports multiple properties of spreadsheets like cell ranges, cell styling, charts, pictures, shapes, comments, tables, protection, encryption, pivot tables, data validation, conditional formatting, formula calculation, etc.


Video Answer


1 Answers

I agree with Yosoyke. You're probably targeting the wrong cells. You can try:

ws.Cells["A3"].Style.Numberformat.Format = "yyyy-mm-dd"; ws.Cells["A3"].Formula = "=DATE(2014,10,5)"; 
like image 153
Taraz Avatar answered Oct 17 '22 23:10

Taraz