水晶报表中自带的导出和打印功能用起来确实很方便,只不过有时候需要导出的文件并不需要那么多种类型,在网上找到一些朋友的代码总结了一下,可以通过代码实现自定义导出文件类型
首先需要定义一个枚举:
public enum AllowedExportFormat { /// <summary> /// PDF. /// </summary> PDF = 1, /// <summary> /// Excel(97-2003) /// </summary> Excel2003 = 2, /// <summary> /// Word (97-2003) /// </summary> Word2003 = 4, /// <summary> /// RTF /// </summary> RTF = 8, /// <summary> /// Crystal Report /// </summary> CrystalReport = 16, /// <summary> /// Excel(97-2003) (仅限数据) /// </summary> Excel2003DataOnly = 32, /// <summary> /// Word (97-2003) - 可编辑 /// </summary> Word2003EditAble = 64, /// <summary> /// XML /// </summary> XML = 128, /// <summary> /// Excel (仅限数据) /// </summary> ExcelDataOnly = 512, /// <summary> /// CSV /// </summary> CSV = 1024 }
然后就可以设置水晶报表导出格式,根据自己需要导出的格式选择对应的枚举值
crystalReportViewer1.AllowedExportFormats = (int)(AllowedExportFormat.Word2003 | AllowedExportFormat.PDF | AllowedExportFormat.XML);
至于水晶报表默认导出格式的先后顺序,我随便测试了一下,没有成功就放弃了
时间: 2024-11-07 19:12:55