点击按钮,导入excel
需为2003版本
private void button1_Click(object sender, EventArgs e)
{
string resultFile = "";
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "D:";
openFileDialog1.Filter = "All files (*.*)|*.*|xls files (*.txt)|*.xls";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
resultFile = openFileDialog1.FileName;
}
if (resultFile == "")
{ }
else
{
dt = FunctionExcel.ExcelToDataTable(resultFile, "Sheet1");
dgv_Data.DataSource = dt;
}
}
DataTable dt_new = new DataTable();
dt_new = dgv_Data.DataSource as DataTable;