c# - DateTimePicker value from Excel -
i wondering if possible set value of datetimepicker queried row in excel. have tried different ways of doing have never came close , help?
also displayed on windows form
public void readandwritetoexcel() { string mypath = @"c:\excel.xls"; fileinfo fi = new fileinfo(mypath); if (!fi.exists) { console.out.writeline("file doesn't exists!"); } else { var excelapp = new microsoft.office.interop.excel.application(); var workbook = excelapp.workbooks.open(mypath); worksheet worksheet = workbook.activesheet worksheet; // write excel microsoft.office.interop.excel.range range = worksheet.cells[1, 1] range; datetime dt = datetimepicker1.value; range.numberformat = "dd/mmm/yyyy"; range.value2 = dt; // read, var date = worksheet.cells[1, 1].value; console.out.writeline(date.tostring()); workbook.save(); workbook.close(); } }
you must add "microsoft.office.core" , "microsoft.office.interop.excel" references project , use them.