Ranjith Balan

Ranjith Balan

  • 2k
  • 26
  • 480

How to set date Column Format to Text in C# interoperability?

Sep 2 2021 3:47 AM

Hi, i have to bind mm/dd/yyyy format date in to text format in excel. i used below code.But its still in Custom format how can change this to Text in excel

ie: Any format coming from excel i need to  bind mm/dd/yyyy format and i have to change the excel Date coloumn format(any format from excel) to Text.Attached a screen shot

 string effdate = xlWorksheet.Cells[i, datecolm].Value.ToString();
                        var words1 = effdate.Split(' ');
                        var white1 = words1.FirstOrDefault();

                        DateTime dt = DateTime.Parse(white1);
                        xlWorksheet.Cells[i, datecolm] = dt.ToString("MM/dd/yyyy");
                        xlWorksheet.Cells[i, datecolm].NumberFormat  = "MM/DD/YYYY";

Answers (13)