• C# winform 文件管理


    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);
                        }
    
                    }
    
                }
            }
    View Code

    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);
    
                    }
                };
    View Code

  • 相关阅读:
    求第N个素数
    HDU1568
    HDU1003 DP
    POJ 1016 模拟字符串
    POJ 3321 树状数组(+dfs+重新建树)
    UVA12532 线段树(单点更新,区间求乘积的正负)
    POJ2488 dfs
    POJ 1195 二维树状数组
    HDU 4006 优先队列
    优先队列
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/10202155.html
Copyright © 2020-2023  润新知