C#获取Excel文件路径

//打开文件对话框选择文件
            OpenFileDialog file = new OpenFileDialog();
            file.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls";
            file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            file.Multiselect = false;
            if (file.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text= file.FileName;
               
                //string filePath = file.FileName;
                //string fileSuffix = System.IO.Path.GetExtension(filePath);
                //DataTable dt;
                //if (fileSuffix == ".xls")
                //{
                //    dt = this.ExcelDataTable(file.FileName, 2);
                //}
                //else
                //{
                //    dt = this.ExcelDataTable(file.FileName, 1);
                //}
            }

你可能感兴趣的:(C#获取Excel文件路径)