How to read a Date column from excel to a string in c#? -


i writing c# console application reads data excel spreadsheet using smartxls library. able read other column data except 'usage date'column. kindly, suggest me way solve problem.

date column in excel:

usage date

oct-15 oct-15 oct-15 

function:

public void getdata()         {              int count = 0;              desktokens = new list<token>();              string directory = path.getdirectoryname(assembly.getexecutingassembly().location);             string path = path.combine(directory, @"c:\projects\product_usage_year.xlsx");              smartxls.workbook wb = new workbook();             wb.readxlsx(path);              datatable dt = wb.exportdatatable();              string currenttype = string.empty;             string currentcategory = string.empty;              datarow dr;             (int = 1; < dt.rows.count; i++)             {                 dr = dt.rows[i];                 var tkn = new token();                  tkn.usagedate = dr[0].tostring(); //error in reading date column                 tkn.product_name = dr[1].tostring();                 tkn.product_version = dr[2].tostring();                 tkn.userid = dr[3].tostring();                 tkn.user_name = dr[4].tostring();                  desktokens.add(tkn);                 count++;                 console.writeline("read : " + count);                  console.writeline("    reading : " + tkn.usagedate + "," + tkn.product_name + "," + tkn.product_version + "," + tkn.userid + "," + tkn.user_name);              }         } 

token class:

 class token  {     public string usagedate { get; set; }     public string product_name { get; set; }     public string product_version { get; set; }     public string userid { get; set; }     public string user_name { get; set; } } 

try use datetime.fromoadate method convert between excel , .net:

datetime.fromoadate(double.parse(dr[0].tostring())); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -