lu
4 天以前 a6f65537fd87ae065fe5cec62863ac4380d2a745
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
using CefSharp.DevTools.Debugger;
using DevExpress.Spreadsheet;
using DevExpress.XtraEditors;
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.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Gs.DevApp.UserControl
{
    public partial class CopyXls : DevExpress.XtraEditors.XtraForm
    {
        private string orderType;
        private string orderGuid;
        private static readonly string filePath = AppContext.BaseDirectory + "xlsCopy.xls";
 
        public CopyXls(string orgId, string _orderGuid, string _orderType)
        {
            InitializeComponent();
            this.Text = "正在复制:" + _orderType;
            this.orderType = _orderType;
            this.orderGuid = _orderGuid;
            this.spreadsheetControl1.DocumentLoaded += new EventHandler(spreadsheetControl1_DocumentLoaded);
            if (!string.IsNullOrEmpty(filePath))
            {
                if (File.Exists(filePath))
                {
                    IWorkbook workbook = spreadsheetControl1.Document;
                    workbook.LoadDocument(filePath);
                   // SetCellText(spreadsheetControl1.ActiveWorksheet, location, item.F_Name, true);
                }
                else
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("找不到xlsCopy.xls文件,请联系管理员!");
                }
            }
        }
 
        /// <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>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            spreadsheetControl1.SaveDocument();
        }
 
        /// <summary>
        /// 从数据库里读取到Excel
        /// </summary>
        /// <param name="workSheet"></param>
        /// <param name="coordinates">位置格式如A1 B2</param>
        /// <param name="coordValue">值</param>
        /// <param name="isBold">是否加粗</param>
        private void SetCellText(Worksheet workSheet, string coordinates, string coordValue, bool isBold)
        {
            workSheet.Cells[coordinates].Value = coordValue;
            workSheet.Cells[coordinates].Style.Font.Bold = isBold;
        }
 
    }
}