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文件,请联系管理员!"); } } } /// /// 文档变化后,实现对新文件名称的显示 /// void spreadsheetControl1_DocumentLoaded(object sender, EventArgs e) { string fileName = Path.GetFileName(this.spreadsheetControl1.Document.Path); if (String.IsNullOrEmpty(fileName)) { Text = "请选择文件"; } else { Text = fileName; } } /// /// 保存 /// /// /// private void btnSave_Click(object sender, EventArgs e) { spreadsheetControl1.SaveDocument(); } /// /// 从数据库里读取到Excel /// /// /// 位置格式如A1 B2 /// 值 /// 是否加粗 private void SetCellText(Worksheet workSheet, string coordinates, string coordValue, bool isBold) { workSheet.Cells[coordinates].Value = coordValue; workSheet.Cells[coordinates].Style.Font.Bold = isBold; } } }