//选取

try
{
string strexcelPath;
openFileDialog1.Filter = "Excel2003 *xls|*xls|Excel2007 *xlsx|*xlsx";
openFileDialog1.FileName = "";
//1、读取数据
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
else
{
strexcelPath = openFileDialog1.FileName;
}
txt_Path.Text = strexcelPath;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}

 

//读取

 

try
{
DataTable dataExcel;
string strexcelPath = txt_Path.Text;
OpExcel opexcel = OpExcelFactory.CreateInstance(strexcelPath);
dataExcel = opexcel.GetData();
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = dataExcel;
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}

相关文章:

  • 2022-12-23
  • 2021-08-26
  • 2021-12-05
  • 2021-07-24
  • 2022-12-23
  • 2021-11-30
  • 2021-05-21
  • 2021-11-12
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案