我使用openfiledialog并过滤它以获取:.xls,.xlsx和.xlsm文件。但是我不知道接下来该怎么做,我建立了一个拥有firstName和lastName的工人类,并且我想从Excel文件中取出数据并将其放入变量中。
这是我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();
}
那么我如何读取这种类型的文件数据呢?(我已经成功打开了它,但不知道如何使用该文件并从中获取数据。)