ExcelDataReader: ExcelDataReader - Error: Invalid file signature
So I’m trying to read my excel file that is consist of 8 header titles No. Mchn. EnNo. Name. Mode. IOMd. Date_Time
and a 300+ of data. and the data grid view is not reading all of my data and the error keeps appearing,… what should I do?
` private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()]; dataGridView1.DataSource = dt;
}
DataTableCollection tableCollection;
private void btnBrowse_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "MS Excel 2007 onwards |*xls" })
// "Excel 97-2003 Workbook | *.xls | Excel Workbook | *.xlsx" })
{
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
}
}
}
}`
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
I am really surprised that the project devs waste so much time investigating dead-end requests … you should not be afraid to be a little rude to time-wasters and fantasists “programmers”… Just close and move on. there are so many things you can spend your time on, that can actually be helpful to real world (this is 3rd ticket i am reading and all 3 are just b/s)