Dev表格导出工具类[代码]
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;
}
}
}
}
收藏备用,谢谢分享。 本论坛资源真是太好了,需要什么来什么! xtragird 很好很强大。
页:
[1]