/// <summary> /// Raises the Cell Exported Event. /// /// </summary> protected virtual void OnCellExported(ExcelCellExportedEventArgs e) { ExcelCellExportedEventHandler exportedEventHandler = this.Events[WebExcelExporter.EventCellExported] as ExcelCellExportedEventHandler; if (exportedEventHandler == null) return; exportedEventHandler((object)this, e); }
/// <summary> /// Exports grid SummaryRow to the specified worksheet. /// /// </summary> protected virtual void ExportSummaries(WebDataGrid grid, Worksheet worksheet, ref int rowIndex, int columnOffset, int outlineLevel, bool hidden, string gridCssClass, int firstDataRowIndex) { SummaryRow behavior = grid.Behaviors.GetBehavior<SummaryRow>(); int index1 = rowIndex - (grid.ShowFooter ? 2 : 1); bool renderingResolved = behavior.EnableCompactRenderingResolved; int summaryNumberVisible = behavior.ColumnSummaries.GetMaxSummaryNumberVisible(); int maxSummaryRows = behavior.ColumnSummaries.GetMaxSummaryRows(); string str1 = string.Empty; if (this.EnableStylesExport) str1 = behavior.ResolveCssClass(behavior.SummariesCssClass, 0); for (int index2 = 0; index2 < maxSummaryRows; ++index2) { if ((index2 < summaryNumberVisible || !renderingResolved) && (renderingResolved || behavior.ColumnSummaries.IsVisibleRow(index2))) { WorksheetRow worksheetRow = worksheet.Rows[rowIndex]; worksheetRow.OutlineLevel = outlineLevel; worksheetRow.Hidden = hidden; int rowIndex1 = rowIndex; ExcelRowExportingEventArgs e1 = new ExcelRowExportingEventArgs(worksheet, worksheetRow, rowIndex1, columnOffset, outlineLevel, false, false, true); this.OnRowExporting(e1); if (!e1.Cancel) { int columnIndex = columnOffset; foreach (ControlDataField summaryCell in (IVisibleItemsEnumerable)grid.Fields) { if (!summaryCell.Hidden && !summaryCell.HiddenByParent) { WorksheetCell worksheetCell = worksheetRow.Cells[columnIndex]; Summary summaryByOrder = behavior.ColumnSummaries.GetSummaryByOrder(summaryCell.Key, index2); SummarySetting summarySetting = (SummarySetting)null; ExcelCellExportingEventArgs e2 = new ExcelCellExportingEventArgs(worksheet, worksheetCell, rowIndex, columnIndex, outlineLevel, false, false, true); e2.Summary = summaryByOrder; this.OnCellExporting(e2); if (e2.Cancel) { ++columnIndex; } else { SummaryCellExportingEventArgs e3 = new SummaryCellExportingEventArgs(summaryCell, worksheet, worksheetCell, rowIndex, columnIndex, outlineLevel, false, false, true); e3.Summary = summaryByOrder; this.OnSummaryCellExporting(e3); if (e3.Cancel) { ++columnIndex; } else { if (summaryByOrder == null) { worksheetCell.Value = (object)behavior.EmptyFooterText; } else { SummaryRowSetting sumRowSetting = behavior.ColumnSettings[summaryCell.Key]; summarySetting = sumRowSetting != null ? (summaryByOrder.SummaryType == SummaryType.Custom ? sumRowSetting.SummarySettings.CustomSummaryByName(summaryByOrder.CustomSummaryName) : sumRowSetting.SummarySettings[summaryByOrder.SummaryType]) : (SummarySetting)null; string format1 = summarySetting == null ? (sumRowSetting == null ? behavior.FormatString : sumRowSetting.FormatString) : summarySetting.FormatString; if (summaryByOrder.SummaryType == SummaryType.Custom) worksheetCell.Value = (object)string.Format(format1, (object)summaryByOrder.CustomSummaryName, summaryByOrder.Value); else if (summaryByOrder.SummaryType == SummaryType.Custom) { worksheetCell.Value = (object)string.Format(format1, (object)summaryByOrder.CustomSummaryName, summaryByOrder.Value); } else { List<string> list = (List<string>)null; string str2 = string.Empty; string str3; if (grid is ContainerGrid && ((ContainerGrid)grid).HasChildGrids()) { list = new List<string>(); for (int index3 = firstDataRowIndex; index3 <= index1; ++index3) { if (worksheet.Rows[index3].OutlineLevel == outlineLevel) list.Add(worksheet.Rows[index3].Cells[columnIndex].ToString(CellReferenceMode.A1, false, true, true)); } str3 = string.Join(",", list.ToArray()); } else str3 = string.Format("{0}:{1}", (object)worksheet.Rows[firstDataRowIndex].Cells[columnIndex].ToString(CellReferenceMode.A1, false, true, true), (object)worksheet.Rows[index1].Cells[columnIndex].ToString(CellReferenceMode.A1, false, true, true)); int num1 = format1.IndexOf("{1"); string format2; if (num1 > -1) { string str4 = "\"" + format1.Substring(0, num1) + "\" & "; string str5 = format1.Substring(num1); int num2 = str5.IndexOf("}"); string str6 = str5.Insert(num2 + 1, " & \"") + "\""; format2 = "=" + str4 + str6; } else format2 = "=\"" + format1 + "\""; string format3 = string.Format(format2, (object)"{0}", (object)"{1}({3})").Replace("\"\" &", "").Replace("& \"\"", ""); if (summaryByOrder.SummaryType == SummaryType.Count && format3.Contains("{1")) format3 = format3.Replace("{1}({3})", "{1}({3}) + {2}({3})"); string[] strArray = this.GetExcelFunctionName(summaryByOrder.SummaryType).Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries); string str7 = strArray.Length > 1 ? strArray[1] : ""; string str8 = string.Format(format3, (object)behavior.GetCultureInvariantSummaryString(summaryByOrder.SummaryType, summaryByOrder.CustomSummaryName), (object)strArray[0], (object)str7, (object)str3); if (list != null && (list.Count > 30 || summaryByOrder.SummaryType == SummaryType.Count)) worksheetCell.Value = (object)behavior.GetSummaryValue((GridField)summaryCell, summaryByOrder, behavior.ColumnSummaries[summaryCell.Key], sumRowSetting, false); else worksheetCell.ApplyFormula(str8); } } if (this.EnableStylesExport) { string classes = str1; if (summarySetting != null && !string.IsNullOrEmpty(summarySetting.CssClass)) classes = classes + " " + summarySetting.CssClass; if (summaryByOrder != null && !string.IsNullOrEmpty(summaryByOrder.CssClass)) classes = classes + " " + summaryByOrder.CssClass; CssSelector selector1 = new CssSelector(); selector1.AddClasses(string.Format("{0} {1}", (object)gridCssClass, (object)classes)); CssStyle styleObject1 = this._currentStyleSheet.GetStyleObject(selector1); this.ApplyCellFormatFromStyle(worksheetCell.Worksheet.Workbook, worksheetCell.CellFormat, styleObject1, grid); CssSelector selector2 = new CssSelector(); selector2.AddClasses(classes); CssStyle styleObject2 = this._currentStyleSheet.GetStyleObject(selector2); this.ApplyCellBorderFromStyle(worksheetCell.CellFormat, styleObject2); } SummaryCellExportedEventArgs e4 = new SummaryCellExportedEventArgs(summaryCell, worksheet, worksheetCell, rowIndex1, columnIndex, outlineLevel, false, false, true); e4.Summary = summaryByOrder; this.OnSummaryCellExported(e4); ExcelCellExportedEventArgs e5 = new ExcelCellExportedEventArgs(worksheet, worksheetCell, rowIndex1, columnIndex, outlineLevel, false, false, true); e5.Summary = summaryByOrder; this.OnCellExported(e5); ++columnIndex; } } } } ++rowIndex; this.OnRowExported(new ExcelRowExportedEventArgs(worksheet, worksheetRow, rowIndex1, columnOffset, outlineLevel, false, false, true)); } } } }