lu
6 天以前 017fa4bf278a1e14bd82146d411fe34049d92795
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using CefSharp;
using DevExpress.Spreadsheet;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.QC
{
    public partial class Xls : DevExpress.XtraEditors.XtraForm
    {
        private string filePath;
        public Xls(string _filePath)
        {
            InitializeComponent();
            this.filePath = _filePath;
            this.spreadsheetControl1.DocumentLoaded += new EventHandler(spreadsheetControl1_DocumentLoaded);
            if (!string.IsNullOrEmpty(filePath))
            {
                IWorkbook workbook = spreadsheetControl1.Document;
                workbook.LoadDocument(filePath);
            }
        }
 
        /// <summary>
        /// 文档变化后,实现对新文件名称的显示
        /// </summary>
        void spreadsheetControl1_DocumentLoaded(object sender, EventArgs e)
        {
            string fileName = Path.GetFileName(this.spreadsheetControl1.Document.Path);
            if (String.IsNullOrEmpty(fileName))
            {
                Text = "请选择文件";
            }
            else
            {
                Text = fileName;
            }
        }
 
        /// <summary>
        /// 保存Excel文件
        /// </summary>
        private void btnSaveFile_Click(object sender, EventArgs e)
        {
            spreadsheetControl1.SaveDocument();
        }
        /// <summary>
        /// 打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(filePath))
            {
                IWorkbook workbook = spreadsheetControl1.Document;
                workbook.LoadDocument(filePath);
            }
        }
        /// <summary>
        /// 另存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveAs_Click(object sender, EventArgs e)
        {
            string dir = System.Environment.CurrentDirectory;
            using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
            {
                folderBrowserDialog.Description = "选择导出文件的保存路径";
                DialogResult dialogResult = folderBrowserDialog.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    string filePath = folderBrowserDialog.SelectedPath + "\\" + "123456.xls";
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        try
                        {
                            IWorkbook workbook = spreadsheetControl1.Document;
                            workbook.SaveDocument(filePath);
                            Gs.DevApp.ToolBox.MsgHelper.ShowInformation("保存成功");
                        }
                        catch (Exception ex)
                        {
                            Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
           // this.spreadsheetControl1.ShowPrintPreview();
            this.spreadsheetControl1.ShowPrintDialog();
        }
    }
}