Devexpress GridControl.Export

private void mnuExportTable_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    using (SaveFileDialog saveDialog = new SaveFileDialog())
    {
        saveDialog.Filter = "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)
        {
            string exportFilePath = saveDialog.FileName;
            string fileExtenstion = new FileInfo(exportFilePath).Extension;

            switch (fileExtenstion)
            {
                case ".xls":
                    gridControl.ExportToXls(exportFilePath);
                    break;
                case ".xlsx":
                    gridControl.ExportToXlsx(exportFilePath);
                    break;
                case ".rtf":
                    gridControl.ExportToRtf(exportFilePath);
                    break;
                case ".pdf":
                    gridControl.ExportToPdf(exportFilePath);
                    break;
                case ".html":
                    gridControl.ExportToHtml(exportFilePath);
                    break;
                case ".mht":
                    gridControl.ExportToMht(exportFilePath);
                    break;
                default:
                    break;
            }

            if (File.Exists(exportFilePath))
            {
               try
               {
                   //Try to open the file and let windows decide how to open it.
                   System.Diagnostics.Process.Start(exportFilePath);
                }
                catch
                {
                    String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                    MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
             }
             else
             {
                 String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
                 MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
        }
    }
}
时间: 2024-11-03 21:56:45

Devexpress GridControl.Export的相关文章

[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,

[WinForm][DevExpress][GridControl]CustomColumnDisplayText Helper

在实际开发中,有时候需要对GridControl中列值进行转义,譬如1转义成完成等等,一般在诸如CustomColumnDisplayText事件中能够轻松完成,为了提高代码复用性,所以对CustomColumnDisplayText进行包装 关键代码: /// <summary> /// CustomColumnDisplayText Helper /// </summary> /// <param name="girdview">GridView

关于DevExpress GridControl控件中新增复选按钮一事

关于DevExpress GridControl新增复选按钮的事情,查了一下网上的文档,发现都是在查询的数据集[table]中新增一列供checkbox绑定使用.偶尔的一瞬间,我在DevExpress 的Demo上发现有使用CheckBox的例子,找了半天Demo的代码,还是没找到.然后就找到了设置的属性. 晚上的时候,想了想,感觉能试出来简直是运气.如下配置即可: 设置GridView中的[OptionsSelection]->[MultiSelectMode]设置为CheckBoxRowSe

[DevExpress]GridControl 同步列头checkbox与列中checkbox状态

关键代码: /// <summary> /// 同步列头checkbox与列中checkbox状态 /// </summary> /// <param name="view">GridView</param> /// <param name="fieldeName">需要绘制Checkbox的列名</param> /// <param name="e">Mouse