I am trying to read my excel file using the windows application that I am currently developing now.
It consist of 8 headers and contains of almost 300 data value.
If you know the solution please help me ;(
And additional question, what nuget can I use to manipulate each header to expand on its own, so that the data can be readable.
My Copy of Code:
private void btnBrowse_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "MS Excel 2007 onwards |*xls" })
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
txtFilename.Text = openFileDialog.FileName;
using (var stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader= ExcelReaderFactory.CreateReader(stream))
{
DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true }
});
tableCollection = result.Tables;
cboSheet.Items.Clear();
foreach (DataTable table in tableCollection)
cboSheet.Items.Add(table.TableName); //add sheet to combobox
}
}
}