I have the following code which will import my excel file. But for some reason it will not show all of the data from the orginal spread sheet.
Here is the original spreadsheet:
Here is the output:
For some reason some of the columns under the benefit period months get lost or do not show up.
private void btnLoadExcel_Click(object sender, EventArgs e){ string pathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtPath.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";"; OleDbConnection conn = new OleDbConnection(pathConn); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from [" + txtSheet.Text+ "$]",conn); conn.Open(); DataTable dt = new DataTable(); myDataAdapter.Fill(dt); dataGridView1.AutoResizeColumns(); dataGridView1.DataSource = dt; for (int i = 0; i < dataGridView1.Columns.Count - 1; i++) { dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } dataGridView1.Columns[dataGridView1.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; for (int i = 0; i < dataGridView1.Columns.Count; i++) { int colw = dataGridView1.Columns[i].Width; dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; dataGridView1.Columns[i].Width = colw; } } 
