-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
39 lines (35 loc) · 1.27 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Data;
using System.IO;
using ExcelDataReader;
namespace WinFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// Excel dosyasýnýn yolunu belirtin
string filePath = @"C:\Users\Sonerr\Desktop\aaa.xlsm";
// Excel dosyasýný yükleyin
using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
// Excel dosyasýndaki verileri bir DataTable nesnesine yükleyin
var result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
{
UseHeaderRow = true
}
});
// DataGridView nesnesindeki verileri DataTable nesnesinden yükleyin
dataGridView1.DataSource = result.Tables[0];
}
}
}
}
}