lixiaojun
2024-07-11 8d8cd298ab46aee191baf53ff320fd3290d1ec9a
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
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.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;
        }
    }
}