在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.FolderBrowserDialog 打开文件夹中默认路径下的excl文件 private void button7_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.SelectedPath = "D:";//默认打开d盘 if (fbd.ShowDialog() == DialogResult.OK) { textBox1.Text = fbd.SelectedPath; DirectoryInfo dif = new DirectoryInfo(textBox1.Text); FileInfo[] fis = dif.GetFiles();//取所有文件信息 foreach (FileInfo fi in fis) { if (fi.Name.ToLower().Contains(".xls") || fi.Name.ToLower().Contains(".xlsx")) { listView1.Items.Add(fi.Name); } } } } 2.OpenFileDialog 打开excel 且可多选 OpenFileDialog fd = new OpenFileDialog(); fd.Multiselect = true; fd.Filter = "所有的excel文件|*.xls;*.xlsx"; if (fd.ShowDialog() == DialogResult.OK) { //只显示名称+扩展名 foreach (string s in fd.SafeFileNames) { listView1.Items.Add(s); } //显示全路径 foreach (string s in fd.FileNames) { listView1.Items.Add(s); } };
|
请发表评论