如何从datagridview中获得excel列名

您好家伙我有一个表格应用程序重命名文件,从Excel中获取数据,我想获得excel列名与datagridview我该怎么办?

编辑:评论的Excel图像

path = dataGridView1.Rows[i].Cells["K1"].Value.ToString(); path2 = dataGridView1.Rows[i].Cells["K2"].Value.ToString(); 

那些K1和K2是其中一个excel列名称的名称,但我希望它可以在所有excel列上工作。

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; using System.IO; namespace WindowsFormsApplication7 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\STAJ\\AppData\\Roaming\\Skype\\My Skype Received Files\\ETKB-Aktarim-Test(1).xlsx ; Extended Properties='Excel 12.0 xml;HDR=YES;'"); baglan.Open(); string sorgu = "select * from [Sheet1$] "; OleDbDataAdapter data_adaptor = new OleDbDataAdapter(sorgu, baglan); baglan.Close(); DataTable dt = new DataTable(); data_adaptor.Fill(dt); dataGridView1.DataSource = dt; string path=""; string path2 = ""; string newFileName = ""; string oldFileName = ""; int i = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { try { path = dataGridView1.Rows[i].Cells["K1"].Value.ToString(); path2 = dataGridView1.Rows[i].Cells["K2"].Value.ToString(); oldFileName = path ; newFileName = path2; if (File.Exists(oldFileName)) { File.Move(oldFileName, newFileName); } i++; } catch (Exception ex) { MessageBox.Show("DOSYA ADI DEGISTIRILDI"); } } } } }