lixiaojun
2025-01-15 49978d050924f1552435ef93e5e5fe332d699281
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
 
namespace HStation.WinFrmUI
{
    public class ExcelSaveFilePathHelper
    {
        public static string SaveFilePathName(string fileName = null, string title = null, string filter = null)
        {
            string path = "";
            System.Windows.Forms.SaveFileDialog fbd = new System.Windows.Forms.SaveFileDialog();
            if (!string.IsNullOrEmpty(title))
            {
                fbd.Title = title;
            }
            fbd.FileName = fbd.Title + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");//设置文件保存名称
            if (!string.IsNullOrEmpty(fileName))
            {
                fbd.FileName = fileName;
            }
 
            fbd.Filter = "Excel 文件(*.xls)|*.xls|Excel 文件(*.xlsx)|*.xlsx"; ;// "Excel|*.xls;*.xlsx;";
            if (!string.IsNullOrEmpty(title))
            {
                fbd.Title = title;// "保存为";
            }
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                path = fbd.FileName;
            }
            return path;
        }
    }
}