I want to show in C # Message Fill that it is exported from Excel. I select the excel file from the Internet via FileDialog. and I want to show the data in the message box in the first column in Excel.
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog()
{
Filter = "Excel Dosyası |*.xlsx| Excel Dosyası|*.xls",
Title = "Excel Dosyası Seçiniz..",
RestoreDirectory = true,
};
if (OFD.ShowDialog() == DialogResult.OK)
{
string DosyaYolu = OFD.FileName;
string DosyaAdi = OFD.SafeFileName;
OleDbConnection baglanti = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DosyaYolu + "; Extended Properties='Excel 12.0 xml;HDR=YES;'");
baglanti.Open();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Sayfa1$]", baglanti);
DataTable DTexcel = new DataTable();
da.Fill(DTexcel);
MessageBox.Show(da.ToString());
baglanti.Close();
}
}
Screenshots of the application and of the desired output: