C# DevExpress GridControl导出表格【转】

DevExpress的GridControl提供方便的数据导出功能,可以方便的导出Exce,PDF,Html页面,world形式,无需写额外的代码,方便、快捷。

/// <summary>
        ///     导出表格
        /// </summary>
        /// <param name="gridControl1"></param>
        public static void DevExpressGridControlExport(GridControl gridControl1)
        {
            using (var saveDialog = new SaveFileDialog())
            {
                saveDialog.Filter = Resources.CommonFunction_DevExpressGridControlExport_Excel_97_2007文件___xls_Excel_2010___xlsx_Excel__2003___xls____xls_Excel__2010____xlsx____xlsx__RichText_File___rtf____rtf__Pdf_File___pdf____pdf__Html_File___html____html;
                if (saveDialog.ShowDialog() == DialogResult.Cancel) return;
                var exportFilePath = saveDialog.FileName;
                var fileExtenstion = new FileInfo(exportFilePath).Extension;
                switch (fileExtenstion)
                {
                    case ".xls":
                        gridControl1.ExportToXls(exportFilePath);
                        break;
                    case ".xlsx":
                        gridControl1.ExportToXlsx(exportFilePath);
                        break;
                    case ".rtf":
                        gridControl1.ExportToRtf(exportFilePath);
                        break;
                    case ".pdf":
                        gridControl1.ExportToPdf(exportFilePath);
                        break;
                    case ".html":
                        gridControl1.ExportToHtml(exportFilePath);
                        break;
                    case ".mht":
                        gridControl1.ExportToMht(exportFilePath);
                        break;
                }

                if (File.Exists(exportFilePath))
                {
                    try
                    {
                        if (DialogResult.Yes == MessageBox.Show(Resources.CommonFunction_DevExpressGridControlExport_, Resources.CommonFunction_DevExpressGridControlExport_提示, MessageBoxButtons.YesNo))
                        {
                            Process.Start(exportFilePath);
                        }
                    }
                    catch
                    {
                        var msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                        MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    var msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                    MessageBox.Show(msg, Resources.CommonFunction_DevExpressGridControlExport_Error_, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

原文网址: https://blog.csdn.net/Gary_888/article/details/70212796

原文地址:https://www.cnblogs.com/mazhenyu/p/9123187.html

时间: 2024-11-08 23:05:34

C# DevExpress GridControl导出表格【转】的相关文章

devexpress 数据导入(gridcontrol 导出 csv)

// 1.gridcontrol 导出 csv: DataTable dtbNew = new DataTable(); dtbNew.Columns.Add("Checkbox", Convert.ToDecimal(1).GetType()); dtbNew.Columns.Add("Seq"); dtbNew.Columns.Add("Test"); dtbNew.Columns.Add("Test2"); dtbNew

DevExpress GridControl如何取消默认的显示方式

DevExpress GridControl如何取消默认的显示方式,就是表格中好像还嵌套了一个表格,下面有个折叠‘+’按钮,我需要显示的是就是单表格的样式效果. 默认的样式如图: 我需要显示的效果图: 在后面加上一句代码就行了. this.gridDeptInfo.PopulateColumns();

DevExpress GridControl 使用方法技巧 总结 收录整理

一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddNewRow() (2).实现gridView_InitNewRow事件 三.如何解决GridControl记录能获取而没有显示出来的问题 gridView.populateColumns(); 四.如何让行只能选择而不能编辑(或编辑某一单元格) (1).View->OptionsBehavior->

[DevExpress]GridControl 根据RowIndex和VisibleColumnsIndex来获取单元格值

关键代码: /// <summary> /// 根据rowIndex和visibleColumnsIndex来获取单元格可见值 /// </summary> /// <param name="view">GridView</param> /// <param name="rowIndex">rowIndex</param> /// <param name="visibleColu

实现DevExpress GridControl 只有鼠标双击后才进行修改数据

1. 实现DevExpress GridControl 只有鼠标双击后才进行修改数据:修改GridView.OptionsBehavior.EditorShowMode属性为Click 2. 实现DevExpress GridControl 只有鼠标双击后才进行修改数据:修改GridView.OptionsBehavior.EditorShowMode属性为MouseDownFocused 然后实现下面代码: private void gridView1_MouseDown(object sen

[Devexpress]GridControl 绑定DataSource时GridView列不变化

Devexpress  GridControl 绑定DataSource时GridView列不变化 1.使用VS自带的DataGridView替代 2.数据绑定以后调用 gridView.PopulateColumns()  函数 重新创建列 gcSummary.DataSource = _dtData; gvSummary.PopulateColumns();

[DevExpress]GridControl 删除所有行

关键代码: /// <summary> /// 删除全部行 /// </summary> /// <param name="gridView">GridView</param> public static void ClearRows(this GridView gridView) { bool _mutilSelected = gridView.OptionsSelection.MultiSelect;//获取当前是否可以多选 if (

DevExpress GridControl功能总结

原文:DevExpress GridControl功能总结 写在前面,Dev控件已经很久了,功能也很强大,截止到现在我编写文档出来的Dev的版本已经到了14.1了,看了Demo真的很强大,效果也很好,结合自己这一个月开发,分享一下自己研究过后的经验,不让大家走更多的弯路 DevExpress安装顺序 GridControl基本样式设置 GridControl常用事件和描述 GridControl右键菜单 GridControl全选和反选 GridControl添加小计功能 GridControl

[Irving] Wpf DevexPress GridControl 获取选中行

WPF前台绑定事件代码: <RelayAction TargetControl="{Binding ElementName=GCInstoragePart}" MethodName="GridClick" MethodParameter="{XParamBinding me}" TriggerEvent="Click" /> 后台事件代码: public void GridClick(RelayAction r,