I used openfiledialog and filter it to get: .xls and .xlsx and .xlsm files. but I don't know what to do next, I build a class of workers with firstName and lastName and I want to take the data from the excel file and put it in the varible.
This is my code of the openfiledialog:
private void ExcelLoad_Click(object sender, EventArgs e)
{
int size = -1;
openFileDialog1.Title = "Browse Excel file";
openFileDialog1.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file size in debugging mode.
Console.WriteLine(result); // <-- For debugging use.
Stream excelOpenFile= openFileDialog1.OpenFile();
}
so how can I read the data from this kind of files.(is succed to open it but i dont know how to use the file and get the data from it).