VB.Net and C# Handle it differently.
Excel 2013
Sub Sample()
MsgBox Sheet1.Range("A1").Value
End Sub
VB.Net 2013
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'~~> Opens an existing Workbook. Change path and filename as applicable
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Siddharth\Desktop\Delete Later\Sample.xlsx")
'~~> Display Excel
xlApp.Visible = True
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
MessageBox.Show(xlWorkSheet.Range("A1").Value)
'
'~~> Rest of the code
'
End Sub
C# 2013
C# Unfortunately handles it like you mentioned.
You can do this to get the desired result
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xlexcel;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlexcel = new Excel.Application();
xlexcel.Visible=true ;
xlWorkBook = xlexcel.Workbooks.Open(
"C:\\Users\\Siddharth\\Desktop\\Delete Later\\Sample.xlsx",
0, true, 5, "", "", true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
"\t", false, false, 0, true, 1, 0);
// Set Sheet 1 as the sheet you want to work with
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
String cellvalue = xlWorkSheet.Cells[1, 1].Value.ToString("MM/dd/yyyy",
CultureInfo.InvariantCulture);
MessageBox.Show(cellvalue);
//
//~~> Rest of the code
//
}
Format(cdate("5/13/1988"),"M.DD.YYYY HH:MM:SS")
will return the same5.13.1988 00:00:00
result, so there is no inconsistency – Vasily Ivoyzha