English 中文(简体)
向单一Excel文档出口几种XtraGrid控制器
原标题:Exporting Several XtraGrid Controls to a Single Excel File

我收到一些关于你如何将XtraGrid出口到一个Excel文档的信息,网址是:

现在 是否有办法将每一XtraGrid控制出口到单一Excel文档中,以便每个XtraGrid信息都出口到不同的单表。

我试图将出口路径方向定在同一个Excel档案中,但在第一次出口过程中,第二批出口过程只是压倒了前哨。

我利用这一方向描述的方法:。 XtraGrid - Export To Excel,但我想知道,使用Interop excel 图书馆是否还有其他任意的鞭).,因为我在使用该图书馆时遇到一些问题(我指的是,在使用该图书馆时,你会创建Excel进程,但在你创建之后,你却无法杀死它,尽管你使用了本应这样做的方法)。

任何帮助都将受到欢迎。

最佳回答

To do that you will want to add a printableComponentLink to each gridControl, and then Create a compositeLink that you can add each of the printableComponent links to.

这一联系可证明DevExpress KB Article可能证明有用,因为它有这方面的实例。

然后将使用<代码>compositeLink.Export ToXlsx方法。 如果您在<代码>XlsxExportOptions/code>上加上XlsxExportOptions.ExportMode,其财产等于<代码>SingleFilePageByPage,并将其通过CompositeLink.ExportToXlsx,每一页将出口到单独的表格中。

问题回答

我只是想提供更完整的答案,因为我用D.的回答共同找到解决办法。

是的——它像我一样试图印刷一些东西,但我只是向Excel出口,我承诺。

using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraGrid;

class whatever
{
    GridControl grid1;
    GridControl grid2;
    //.....

    public void exportToExcel()
    {
        using (var saveDialog = new SaveFileDialog())
        {
            saveDialog.Filter = "Excel (.xlsx)|*.xlsx";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                var printingSystem = new PrintingSystemBase();
                var compositeLink = new CompositeLinkBase();
                compositeLink.PrintingSystemBase = printingSystem;

                var link1 = new PrintableComponentLinkBase();
                link1.Component = grid1;
                var link2 = new PrintableComponentLinkBase();
                link2.Component = grid2;

                compositeLink.Links.Add(link1);
                compositeLink.Links.Add(link2);

                var options = new XlsxExportOptions();
                options.ExportMode = XlsxExportMode.SingleFilePageByPage;

                compositeLink.CreatePageForEachLink();
                compositeLink.ExportToXlsx(saveDialog.FileName, options);
            }
        }
    }
}    

希望给一些人节省了一点时间。

In above code, compositeLink.ExportToXlsx failed for me--no such method. Of course I am using V10.2.5, which is old. I suggest this link from the DEVXPRESS site that uses the ShowPreviewDialog method which allows exporting in a number of different formats. The link also shows how to do some customization of the output. https://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraPrintingLinksCompositeLinktopic





相关问题
How to do word wrap in a DevExpress TcxGrid?

I ve got a long line of text that would be a lot easier to view if it would just word wrap around multiple lines, but I can t seem to find the option for it. Does anyone know how to enable word-wrap ...

XtraPivotGrid dynamic dataset creation

I already have a dynamic XtraPivotGrid creation, but the table adapter and the dataset are 1(one) table specific. I want to be able to get data from a table specified by user, but I can t see a way of ...

WPF Devexpress ComboBoxEdit Items

i use devexpress comboBoxEdit component in my WPF app. I assign values for it like this: private void Users1_Load() { DataTable dtCat = SqlHelper.GetTable("base_UserCategory_Select", new string[] ...

WPF comboBoxEdit

i Have problem with WPF comboBoxEdit. I load values it it like this: comboBoxEdit1.ItemsSource = dtCat.DefaultView; Values are loaded, everything works good, but when i select some value from ...

How to get row index of the selected cell in WPF grid

Does anyone knows how to get row index of the selected cell in DevExpress WPF grid? In WinForms it was something like that: dataGridViewControll.SelectedCells[0].RowIndex;

Recommended ASP.NET Grid and UI tools [closed]

We are building a web application using C# and SQL server. We are thinking about buying the DevExpress ASP.NET controls. Anybody have any opinions about this tool or have any they would recommend?

TextBoxColumn in DevexpressGridControl (WPF)

In Windows grid is sucha a thing like DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); Is something like that in DevExpress GridControll for WPF?Or maybe is possible to do some ...

热门标签