导出excel文件
private void ExportToEx(String filename, string ext, BaseView exportView)
{
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
if (ext == "xls") exportView.ExportToXls(filename);
if (ext == "xlsx") exportView.ExportToXlsx(filename);
Cursor.Current = currentCursor;
}
private void OpenFile(string fileName)
{
if (XtraMessageBox.Show("Do you want to open this file?", "Export To...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Verb = "Open";
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.Start();
}
catch
{
DevExpress.XtraEditors.XtraMessageBox.Show(this, "Cannot find an application on your system suitable for openning the file with exported data.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
progressBarControl.Position = 0;//进度条位置
}
ExportToEx(fileName, "xlsx", gridView); //将gridview中的数据导出excel
OpenFile(fileName);
【无标题】c#——将gridview中的数据导出Excel
最新推荐文章于 2024-07-20 16:40:31 发布