点击按钮,导入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;

posted @ 2014-07-28 15:38  小河叮咚  阅读(560)  评论(0编辑  收藏  举报