【问题标题】:Multiband UltraGrid only export the main bandMultiband UltraGrid 仅导出主波段
【发布时间】:2015-04-17 06:11:19
【问题描述】:

我的应用程序中有一个 UltraGrid,它显示主波段和其他子波段。当我使用 UltraGrid ExcelExporter 时,Exporter 会导出带有所有子带的整个网格。我想实现导出器只导出主波段而不导出所有子波段。到目前为止,我还没有找到实现这一目标的属性。到目前为止有什么建议吗?

我的导出代码如下所示(仅供参考):

  this.saveFileDialog.ShowDialog();
        if (string.IsNullOrEmpty(this.saveFileDialog.FileName))
            return;

        SplashScreenManager.ShowForm(typeof(FrmWait));
        try
        {
            this.ultraGridExcelExporter.Export(this.gridFrames,
                                                this.saveFileDialog.FileName);

            MessageBox.Show("Der Excel Export wurd erfolgreich durchgeführt.",
                            "Export erfolgreich",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            SplashScreenManager.CloseForm();
        }

【问题讨论】:

    标签: c# .net winforms infragistics ultrawingrid


    【解决方案1】:

    要跳过导出所有子波段的行,您可以处理 InitializeRow 事件。如果该行在根带中,您可以像这样跳过它的所有后代:

    private void ultraGridExcelExporter1_InitializeRow(object sender, ExcelExportInitializeRowEventArgs e)
    {
        if (e.Row.Band.Index == 0)
        {
            e.SkipDescendants = true;
        }
    }
    

    但是,这仍会导出几个不必要的列标题。要跳过除第一列标题之外的所有内容,您可以创建一个布尔字段并像这样处理 HeaderRowExporting 事件:

    private bool firstHeaderExported = false;
    
    private void ultraGridExcelExporter1_HeaderRowExporting(object sender, HeaderRowExportingEventArgs e)
    {
        if (e.HeaderType == HeaderTypes.ColumnHeader && firstHeaderExported)
        {
            e.Cancel = true;
        }
        else
        {
            this.firstHeaderExported = true;
        }
    }
    

    这应该可以解决问题。

    【讨论】:

      【解决方案2】:

      此处列出的以前的解决方案将起作用,但它们效率有点低,因为它们依赖于取消每个单独行的导出。

      更好的方法是利用 UltraGridExcelExporter 克隆网格的 DisplayLayout 这一事实。这意味着您可以在不影响屏幕网格的情况下更改导出布局。您可以简单地隐藏所有子乐队:

          private void ultraGridExcelExporter1_ExportStarted(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs e)
          {
              foreach (UltraGridBand band in e.Layout.Bands)
              {
                  if (band.Index > 0)
                      band.Hidden = true;
              }
          }
      

      或者...在这种情况下更简单,只需将 ViewStyle 设置为 SingleBand。

          private void ultraGridExcelExporter1_ExportStarted(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs e)
          {
              e.Layout.ViewStyle = ViewStyle.SingleBand;
          }
      

      【讨论】:

        【解决方案3】:

        您可以覆盖 RowExporting 事件:

        private void ultraGridExcelExporter_RowExporting(Object sender, Infragistics.Win.UltraWinGrid.ExcelExport.RowExportingEventArgs e)
        {
            if (e.GridRow.Band.Key != "MainBand")
            {
                e.Cancel = true;
            }
        }
        

        (请原谅我的语法错误。我是 VB 开发人员。)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-11-30
          • 2023-04-02
          • 1970-01-01
          • 1970-01-01
          • 2015-05-28
          • 1970-01-01
          • 2012-06-22
          相关资源
          最近更新 更多