I've successfully exported data from excel to datagrid through the following code:
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using SmartXLS;
namespace Calibration_Trial
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
WorkBook m_book = new WorkBook();
m_book.readXLSX("trial.xlsx");
//Read data from spreadsheet.
DataTable mbooktable = m_book.ExportDataTable(9, 0, 4, 4, false, true);
simpleDataGrid.ItemsSource = mbooktable.AsDataView();
}
}
}
The ExportDataTable
has 6 parameters, as you can see. The last parameter is true
which means it should check if the column is of datetime type. So I don't get why I'm still getting the wrong output. Am I missing something?
Here's a screenshot (The Column4 should be of DateTime format :():
I figured the DateTime
format only works if each value in the column (in the excel file itself) is in date format. I guess there's no other way but to delete everything that is not in date format. ☹