Hi Team,
I have an issue in export to excel with group by from ultragrid. I did the following steps, after that Collapse (+)/ Expand (-) missing.
First Time Export: Export with Grouping
Second Time: Export without Grouping
Third Time: Export To Excel With Group by ( Collapse (-)/ Expand (-)) missing
Export to Excel Code:
private void(object sender, EventArgs e) { gridResults.Visible = false; gridResults.Enabled = false; gridResults.DataSource = null; LoadAllChildData(); gridResults.DataSource = dsKPI; }
private void newExcelExportToolStripMenuItem_Click(object sender, EventArgs e) { ExportToExcelForm etef = new ExportToExcelForm(excelExporter, filterRowCheck(), gridResults.Rows[0].HasExpansionIndicator); if (etef.ShowDialog() == DialogResult.OK) { gridResults.InitializeRow -= gridResults_InitializeRow; gridResults.BeforeRowExpanded -= gridResults_BeforeRowExpanded; gridResults.BeforeRowCollapsed -= gridResults_BeforeRowCollapsed;
ExportCheckedRowsOnly = false; ExcelExportFormat = etef.format; ExcelExportSuccesful = true;
foreach (UltraGridRow gridRow in gridResults.Rows) gridRow.Appearance.BackColor = Color.White;
Infragistics.Win.UltraWinGrid.AsynchronousExportManager.AsynchronousExportDuration = 1000; Infragistics.Win.UltraWinGrid.AsynchronousExportManager.AsynchronousExportInterval = 10;
string maxRows = "65,535"; string maxCols = "256";
gridResults.Rows.CollapseAll(true);
// If the grouping on is checked on the main form then expand everything. (SM:2-5-2019) if (etef.groupingOn == true) { gridResults.Rows.ExpandAll(true); LoadAllChildData(); }
//gridResults.UpdateData();
string extension = ".xls";
if (ExcelExportFormat == Infragistics.Documents.Excel.WorkbookFormat.Excel2007) { extension = ".xlsx"; maxRows = "1,048,576"; maxCols = "16,384"; }
dlgSaveAs.FileName = ""; Regex re = new Regex("[^A-Za-z0-9_]");
string selectedTemplate = GetCurrentTemplateName(); ; if ((selectedTemplate == "No Template") || (selectedTemplate == "No Existing Templates")) { dlgSaveAs.FileName = re.Replace(DataObject.DataObjectName.Replace(" ", "_"), ""); } else { dlgSaveAs.FileName = re.Replace(selectedTemplate.Replace(" ", "_"), ""); }
dlgSaveAs.FileName += "_" + String.Format("{0:yyyyMMddHHmmss}", DateTime.Now); dlgSaveAs.Filter = "Microsoft Excel|*" + extension;
isExcelExportToEmail = false;
if (dlgSaveAs.ShowDialog() == DialogResult.OK) { Application.DoEvents(); excelExporter.ExportAsync(gridResults, dlgSaveAs.FileName); gridResults.Rows.CollapseAll(true); gridResults.InitializeRow += gridResults_InitializeRow; gridResults.BeforeRowExpanded += gridResults_BeforeRowExpanded; gridResults.BeforeRowCollapsed += gridResults_BeforeRowCollapsed; } } }
private void excelCheckExporter_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e) { if (!ExportAllDrilldowns) e.Layout.Bands[0].Override.HeaderPlacement = HeaderPlacement.FixedOnTop; else { e.Layout.Bands[0].Override.HeaderPlacement = HeaderPlacement.OncePerRowIsland; e.Layout.Rows.CollapseAll(true); e.Layout.ViewStyle = Infragistics.Win.UltraWinGrid.ViewStyle.MultiBand; }
foreach (var band in e.Layout.Bands) { band.Indentation = 5;
if (band.Columns.Exists("FirstColumnCheckBox")) { band.Columns["FirstColumnCheckBox"].Hidden = true; band.Columns["FirstColumnCheckBox"].Header.VisiblePosition = band.Columns.Count; } } }
private void excelExporter_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExcelExportInitializeRowEventArgs e) {
if (e.Row.IsGroupByRow) { //if don't export groups if (excelExporter.OutliningStyle == Infragistics.Win.UltraWinGrid.ExcelExport.OutliningStyle.None) { e.SkipRow = true; } if (!e.Row.IsExpanded) { e.SkipRow = true; }
} else { if (!ExportAllDrilldowns) { if (!e.Row.IsExpanded) { e.SkipDescendants = true; } } } }
private void excelExporter_HeaderRowExporting(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.HeaderRowExportingEventArgs e) { e.Band.Indentation = 0;
if (e.HeaderType == Infragistics.Win.UltraWinGrid.ExcelExport.HeaderTypes.ColumnHeader) { return; }
if (!ExportAllDrilldowns) {
//if it's NOT expanded and it's NOT the first if (!e.GridRow.IsExpanded && e.CurrentRowIndex != 0) { //if it has a previous sibling if (e.GridRow.HasPrevSibling()) { //if that previous sibling is expanded if (e.GridRow.GetSibling(SiblingRow.Previous).IsExpanded) { //create new header return; } } //else if it has no previou sibling, and has a parent row, then it is the first in a child band else { if (e.GridRow.ParentRow != null) { return; } } //Otherwise, skip it e.Cancel = true; } } }
private void excelExporter_InitializeColumn(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.InitializeColumnEventArgs e) { if (e.Column.DataType == typeof(DateTime)) { if (e.Column.Format != null) { string excelFormat = e.Column.Format; if (excelFormat.Contains("tt")) excelFormat = excelFormat.Replace("tt", "AM/PM"); //if (excelFormat.Contains("\"")) //excelFormat = excelFormat.Replace("\"", ""); excelFormat = "[$-409]" + excelFormat + ";@";
e.ExcelFormatStr = excelFormat; } }
else { if (e.Column.Format != null) { e.ExcelFormatStr = e.Column.Format; } }
}
private void excelExporter_ExportEnding(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportEndingEventArgs e) { foreach (var row in e.CurrentWorksheet.Rows) { foreach (var cell in row.Cells) { cell.CellFormat.VerticalAlignment = Infragistics.Documents.Excel.VerticalCellAlignment.Center; } } }
private void excelExporter_ExportEnded(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportEndedEventArgs e) { if (e.Canceled) return; if (ExcelExportSuccesful) { if (ExportAllDrilldowns) { foreach (UltraGridRow row in gridResults.Rows) { if (!ExpandedIndexes.Contains(row.Index)) row.Expanded = false; } }
Application.DoEvents();
if (isExcelExportToEmail) { MemoryStream stream = new MemoryStream();
if (ExcelExportFormat == Infragistics.Documents.Excel.WorkbookFormat.Excel2007) { extension = ".xlsx"; }
FileStream streamReadFile = File.OpenRead(ExcelExportTempPath); streamReadFile.CopyTo(stream); streamReadFile.Close();
File.Delete(ExcelExportTempPath); stream.Seek(0, SeekOrigin.Begin);
frmEmailReport frmEmailReport = new frmEmailReport(this, stream, DataObject.DataObjectName, extension); frmEmailReport.ShowDialog();
} else { if (ShowMessage("Export Complete! Would you like to open the exported file?", "Open File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { System.Diagnostics.Process.Start(dlgSaveAs.FileName); }
} }
private void excelExporter_AsynchronousExportError(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.AsynchronousExportErrorEventArgs e) { ExcelExportSuccesful = false; }
Hello MLDav,
I have been investigating into the behavior you are seeing with the code that you have provided, but unfortunately, there is a lot of missing logic in the code that you have provided. I have picked out the pieces that I can use, but in doing so, I cannot seem to reproduce the behavior you are seeing. Each time I am exporting the UltraGrid, it looks the same as in the Windows Forms application.
I am attaching the sample project that I used to test this. My tests were made using specific version 19.2.20192.302 in Infragistics for Windows Forms 2019 Volume 2. If this version differs from the version you are using, please let me know.
It would be very helpful if you can either modify the attached sample project such that it reproduces the behavior you are seeing. Alternatively, if you have an isolated sample project that you can attach here that reproduces the behavior, I can take a look at that as well.
Please let me know if you have any other questions or concerns on this matter.
UltraGridExcelExportIssue.zip
Hi Andrew,
Thank you for response. I am able to export into excel. but few issues are there which I need to fix.
1. Extra Row Added between Group Grids Which I need to take off
2. Formatting is not all working when I export.
ExcelExporter.ExportFormattingOptions = Infragistics.Win.UltraWinGrid.ExcelExport.ExportFormattingOptions.All;
Thank you for your update on this matter.
I have been investigating into the additional behaviors you are looking to handle, and I have some information for you on this matter. I will answer your concerns in the order they were raised:
1. In order to remove the extra row between the group-by rows and the data rows in the export, you can set the BandSpacing property on the UltraGridExcelExporter being used to “BandSpacing.None.”
2. I am seeing the same behavior, but strangely this appears to only be happening for the cells within actual data rows. That is, if there is a format applied to cells that are in the data rows of the UltraGrid, this is lost, but if those columns are grouped, the formatting remains. This appears to be an issue with the control, but in order to work around this, you can handle the CellExported event of the UltraGridExcelExporter and apply the formatting manually.
I am attaching a modified version of the sample project I originally sent you to demonstrate this workaround.
As this issue appears to be an issue with the control, I have asked our development teams to examine this closer. To ensure this receives attention, I have logged this in our internal tracking systems with a development ID of 269969. I have also created you a private support case that I will be linking this issue to so you can be notified when a fix or other resolution becomes available. You can access this support case here.
UltraGridExcelExportIssueWorkaround.zip
I am getting numeric Conversion issue and it should be fixed immediately. Please suggest how to fix this issue.
Would it be possible for you to please provide a little more information about the column that is being exported from the UltraGrid and is causing this issue? Can you please provide answers to the following?
1. Is the underlying data-type for the column in the UltraGrid a string or is it numeric? I am under the impression that it may be a string with the 0 at the front of the numbers in your screenshot.
2. Can you please share a sample project that shows the behavior you are seeing?