i need retrieve excel column of date. first column 'a' values formatted this6/20/2016 10:44
. have no problem of retrieving column 'a' format using
using documentformat.openxml; double d = double.parse(thecell.innertext); datetime conv = datetime.fromoadate(d).date;
my second column 'b' formatted 6/20/2016.
no time, date. problem when tried code below:
using documentformat.openxml; double d = double.parse(thecell.innertext); datetime conv = datetime.fromoadate(d).date;
thecell.innertext value 1455
i having different value. value changes 12/25/1903 12:00:00 am
how can retrieve excel values kind of date format 6/30/2016
?
i located code here , modified it: open xml reading excel file
i thinking same thing hambone thinking, namely excel cell has else in it, or not reading cell think are.
here code using, , works me:
using system; using system.linq; using documentformat.openxml.packaging; using documentformat.openxml.spreadsheet; namespace consoleapplication1 { class program { private static void main(string[] args) { var filepath = @"c:\xyz\stack_c_sharp.xlsx"; using (var document = spreadsheetdocument.open(filepath, false)) { var workbookpart = document.workbookpart; var workbook = workbookpart.workbook; var sheets = workbook.descendants<sheet>(); foreach (var sheet in sheets) { var worksheetpart = (worksheetpart)workbookpart.getpartbyid(sheet.id); var sharedstringpart = workbookpart.sharedstringtablepart; string text; var rows = worksheetpart.worksheet.descendants<row>(); foreach (var row in rows) { console.writeline(); int count = row.elements<cell>().count(); foreach (cell thecell in row.elements<cell>()) { text = thecell.cellvalue.innertext; double d = double.parse(thecell.innertext); datetime conv = datetime.fromoadate(d).date; console.write(text + " "); console.write(conv + " "); } } } console.readline(); } } } }
Comments
Post a Comment