我的应用程序中有一个UltraGrid,显示主乐队和其他子乐队。当我使用UltraGrid ExcelExporter时,Exporter将所有子带导出整个网格。我想实现出口商只输出没有所有子带的主带。到目前为止,我还没有找到实现这一目标的财产。到目前为止有什么建议吗?
我的导出代码如下所示(只是fyi ):
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();
}
答案 0 :(得分: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;
}
}
那应该成功。
答案 1 :(得分:1)
此处列出的先前解决方案可行,但它们效率低,因为它们依赖于取消每个行的导出。
更好的方法是利用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;
}
答案 2 :(得分:0)
您可以覆盖RowExporting事件:
private void ultraGridExcelExporter_RowExporting(Object sender, Infragistics.Win.UltraWinGrid.ExcelExport.RowExportingEventArgs e)
{
if (e.GridRow.Band.Key != "MainBand")
{
e.Cancel = true;
}
}
(请原谅我任何语法错误。我是VB开发人员。)