- 积分
- 53
- 在线时间
- 62 小时
- 主题
- 8
- 注册时间
- 2013-6-8
- 帖子
- 73
- 最后登录
- 2023-8-16
- 帖子
- 73
- 软币
- 1545
- 在线时间
- 62 小时
- 注册时间
- 2013-6-8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace xSoft.Utility.UI
{
public class ExportUtility
{
public static void ExportGridToFile(DevExpress.XtraGrid.Views.Base.BaseView gridView, string reportName, string fullFileName = null)
{
string fileName = string.Empty;
if (string.IsNullOrEmpty(fullFileName))
{
System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
dlg.DefaultExt = ".xls";
dlg.FileName = reportName;
dlg.AddExtension = true;
dlg.Filter = "Excel2000-2003(*.xls)|*.xls|Excel2007以上(*.xlsx)|*.xlsx|PDF文件(*.pdf)|*.pdf|网页文件(*.html)|*.html|RTF文件(*.rtf)|*.rtf|文本文件(*.txt)|*.txt";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileName = dlg.FileName;
}
else
{
return;
}
}
if (fileName == string.Empty)
{
return;
}
string extFileName = System.IO.Path.GetExtension(fileName).ToUpper();
switch (extFileName)
{
case ".XLSX":
gridView.ExportToXlsx(fileName);
break;
case ".PDF":
gridView.ExportToPdf(fileName);
break;
case ".HTML":
gridView.ExportToHtml(fileName);
break;
case ".RTF":
gridView.ExportToRtf(fileName);
break;
case ".TXT":
gridView.ExportToText(fileName);
break;
default:
gridView.ExportToXls(fileName);
break;
}
}
}
}
|
|