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();
|
}
|
}
|
}
|