コード例 #1
0
ファイル: WebExcelEsporterEx.cs プロジェクト: bpug/MetronaWT
 /// <summary>
 /// Exports set of grouped rows to the specified worksheet.
 /// 
 /// </summary>
 protected virtual void ExportGroupedRows(GroupedRecordCollection groupedRows, Worksheet worksheet, ref int rowIndex, int columnOffset, bool hasHiddenCols, int outlineLevel, bool hidden)
 {
     ContainerGrid owner = groupedRows.Owner;
     WebHierarchicalDataGrid mainGrid = owner.MainGrid;
     string styleClassString1 = mainGrid.RunBot.StyleBot.GetStyleClassString(0, mainGrid.ControlStyle.CssClass);
     string styleClassString2 = owner.RunBot.StyleBot.GetStyleClassString(5, owner.ItemCssClass);
     string styleClassString3 = owner.RunBot.StyleBot.GetStyleClassString(6, owner.AltItemCssClass);
     string styleClassString4 = mainGrid.RunBot.StyleBot.GetStyleClassString(11, owner.Band != null ? owner.Band.GroupingSettings.GroupedRowCssClassResolved : "");
     int count = groupedRows.Owner.Fields.Count;
     if (hasHiddenCols)
     {
         foreach (ControlDataField controlDataField in (CollectionBase)groupedRows.Owner.Fields)
         {
             if (controlDataField.Hidden || controlDataField.HiddenByParent)
                 --count;
         }
     }
     foreach (GroupedRecord groupedRecord in (CollectionBase)groupedRows)
     {
         WorksheetRow worksheetRow = worksheet.Rows[rowIndex];
         worksheetRow.OutlineLevel = outlineLevel;
         worksheetRow.Hidden = hidden;
         WorksheetMergedCellsRegion mergedCellsRegion = worksheet.MergedCellsRegions.Add(rowIndex, columnOffset, rowIndex, columnOffset + count - 1);
         mergedCellsRegion.Value = (object)groupedRecord.Text;
         if (this.EnableStylesExport)
         {
             CssSelector selector1 = new CssSelector();
             selector1.AddClasses(string.Format("{0} {1}", (object)styleClassString1, (object)styleClassString4));
             CssStyle styleObject1 = this._currentStyleSheet.GetStyleObject(selector1);
             this.ApplyCellFormatFromStyle(worksheet.Workbook, mergedCellsRegion.CellFormat, styleObject1, (WebDataGrid)owner);
             CssSelector selector2 = new CssSelector();
             selector2.AddClasses(styleClassString4);
             CssStyle styleObject2 = this._currentStyleSheet.GetStyleObject(selector2);
             this.ApplyCellBorderFromStyle(mergedCellsRegion.CellFormat, styleObject2);
         }
         ++rowIndex;
         bool hidden1 = hidden || !groupedRecord.Expanded;
         if (groupedRecord.HasChildGroupRows)
         {
             this.ExportGroupedRows(groupedRecord.ChildGroupRows, worksheet, ref rowIndex, columnOffset, hasHiddenCols, outlineLevel + 1, hidden1);
         }
         else
         {
             groupedRecord.Rows.Reset();
             while (groupedRecord.Rows.MoveNext())
             {
                 ContainerGridRecord containerGridRecord = (ContainerGridRecord)groupedRecord.Rows.Current;
                 string itemCssClass = styleClassString2;
                 if (containerGridRecord.Index % 2 == 1)
                     itemCssClass = itemCssClass + " " + styleClassString3;
                 if (!string.IsNullOrEmpty(containerGridRecord.CssClass))
                     itemCssClass = itemCssClass + " " + containerGridRecord.CssClass;
                 this.ExportRow((GridRecord)containerGridRecord, worksheet, ref rowIndex, columnOffset, hasHiddenCols, outlineLevel + 1, hidden1, styleClassString1, itemCssClass);
             }
         }
     }
 }
コード例 #2
0
ファイル: WebExcelEsporterEx.cs プロジェクト: bpug/MetronaWT
 /// <summary>
 /// Exports a grid field caption (header or footer) to the specified worksheet cell.
 /// 
 /// </summary>
 protected virtual void ExportGridFieldCaption(WebDataGrid grid, GridFieldCaption caption, WorksheetRow wsRow, WorksheetCell wsCell, int rowIndex, int columnIndex, string gridCssClass, string captionRowCssClass, bool isHeader, int rowSpan, int colSpan, int colOffset)
 {
     WorksheetMergedCellsRegion mergedCellsRegion = rowSpan > 1 || colSpan > 1 ? wsRow.Worksheet.MergedCellsRegions.Add(rowIndex, columnIndex + colOffset, rowIndex + rowSpan - 1, columnIndex + colOffset + colSpan - 1) : (WorksheetMergedCellsRegion)null;
     ExcelCellExportingEventArgs e1 = new ExcelCellExportingEventArgs(wsRow.Worksheet, wsCell, rowIndex, columnIndex, wsRow.OutlineLevel, isHeader, !isHeader, false);
     this.OnCellExporting(e1);
     if (e1.Cancel)
         return;
     GridFieldCaptionExportingEventArgs e2 = new GridFieldCaptionExportingEventArgs(caption, wsRow.Worksheet, wsCell, rowIndex, columnIndex, wsRow.OutlineLevel, isHeader, !isHeader, false);
     this.OnGridFieldCaptionExporting(e2);
     if (e2.Cancel)
         return;
     if (mergedCellsRegion != null)
         mergedCellsRegion.Value = (object)caption.Text;
     else
         wsCell.Value = (object)caption.Text;
     if (this.EnableStylesExport)
     {
         string styleClassString = grid.RunBot.StyleBot.GetStyleClassString((int)caption.Role, caption.CssClassResolved);
         if (caption.OwnerField is GroupField && caption.Role == WebDataGridRoles.HeaderCaption)
             styleClassString = grid.RunBot.StyleBot.GetStyleClassString(10, styleClassString);
         CssSelector selector1 = new CssSelector();
         selector1.AddClasses(string.Format("{0} {1} {2}", (object)gridCssClass, (object)captionRowCssClass, (object)styleClassString));
         CssStyle styleObject1 = this._currentStyleSheet.GetStyleObject(selector1);
         this.ApplyCellFormatFromStyle(wsCell.Worksheet.Workbook, wsCell.CellFormat, styleObject1, grid);
         if (mergedCellsRegion != null)
             this.ApplyCellFormatFromStyle(mergedCellsRegion.Worksheet.Workbook, mergedCellsRegion.CellFormat, styleObject1, grid);
         CssSelector selector2 = new CssSelector();
         selector2.AddClasses(styleClassString);
         CssStyle styleObject2 = this._currentStyleSheet.GetStyleObject(selector2);
         this.ApplyCellBorderFromStyle(wsCell.CellFormat, styleObject2);
         if (mergedCellsRegion != null)
             this.ApplyCellBorderFromStyle(mergedCellsRegion.CellFormat, styleObject2);
     }
     if (wsCell.Value != null)
     {
         this.SetColumnWidth(wsCell.Worksheet.Columns[wsCell.ColumnIndex], wsCell);
         if (wsCell.Value.ToString().Contains(Environment.NewLine))
             wsCell.CellFormat.WrapText = ExcelDefaultableBoolean.True;
     }
     if (mergedCellsRegion != null && mergedCellsRegion.Value != null && mergedCellsRegion.Value.ToString().Contains(Environment.NewLine))
         mergedCellsRegion.CellFormat.WrapText = ExcelDefaultableBoolean.True;
     this.OnGridFieldCaptionExported(new GridFieldCaptionExportedEventArgs(caption, wsRow.Worksheet, wsCell, rowIndex, columnIndex, wsRow.OutlineLevel, isHeader, !isHeader, false));
     this.OnCellExported(new ExcelCellExportedEventArgs(wsRow.Worksheet, wsCell, rowIndex, columnIndex, wsRow.OutlineLevel, isHeader, !isHeader, false));
 }
コード例 #3
0
ファイル: WebExcelEsporterEx.cs プロジェクト: bpug/MetronaWT
 /// <summary>
 /// Exports a grid record item to its corresponding worksheet cell.
 /// 
 /// </summary>
 protected virtual void ExportCell(GridRecordItem item, WorksheetRow worksheetRow, int rowIndex, int columnIndex, string gridCssClass, string itemCssClass)
 {
     WorksheetCell worksheetCell = worksheetRow.Cells[columnIndex];
     ExcelCellExportingEventArgs e1 = new ExcelCellExportingEventArgs(worksheetRow.Worksheet, worksheetCell, rowIndex, columnIndex, worksheetRow.OutlineLevel, false, false, false);
     this.OnCellExporting(e1);
     if (e1.Cancel)
         return;
     GridRecordItemExportingEventArgs e2 = new GridRecordItemExportingEventArgs(item, worksheetRow.Worksheet, worksheetCell, rowIndex, columnIndex, worksheetRow.OutlineLevel, false, false, false);
     this.OnGridRecordItemExporting(e2);
     if (e2.Cancel)
         return;
     worksheetCell.Value = !item.HasTemplate ? (!(item.Column is FormattedGridField) || this.DisableCellValueFormatting || string.IsNullOrEmpty(((FormattedGridField)item.Column).DataFormatString) ? item.Value : (object)string.Format(((FormattedGridField)item.Column).DataFormatString, item.Value)) : (object)this.RenderTemplate(item.TemplateContainer);
     if (this.EnableStylesExport)
     {
         if (!string.IsNullOrEmpty(item.CssClass))
             itemCssClass = itemCssClass + " " + item.CssClass;
         if (!string.IsNullOrEmpty(item.Column.CssClass))
             itemCssClass = itemCssClass + " " + item.Column.CssClass;
         CssSelector selector1 = new CssSelector();
         selector1.AddClasses(string.Format("{0} {1}", (object)gridCssClass, (object)itemCssClass));
         CssStyle styleObject1 = this._currentStyleSheet.GetStyleObject(selector1);
         this.ApplyCellFormatFromStyle(worksheetCell.Worksheet.Workbook, worksheetCell.CellFormat, styleObject1, (WebDataGrid)item.Row.ControlMain);
         CssSelector selector2 = new CssSelector();
         selector2.AddClasses(itemCssClass);
         CssStyle styleObject2 = this._currentStyleSheet.GetStyleObject(selector2);
         this.ApplyCellBorderFromStyle(worksheetCell.CellFormat, styleObject2);
     }
     if (worksheetCell.Value != null)
     {
         this.SetColumnWidth(worksheetRow.Worksheet.Columns[columnIndex], worksheetCell);
         if (worksheetCell.Value.ToString().Contains(Environment.NewLine))
             worksheetCell.CellFormat.WrapText = ExcelDefaultableBoolean.True;
     }
     this.OnGridRecordItemExported(new GridRecordItemExportedEventArgs(item, worksheetRow.Worksheet, worksheetCell, rowIndex, columnIndex, worksheetRow.OutlineLevel, false, false, false));
     this.OnCellExported(new ExcelCellExportedEventArgs(worksheetRow.Worksheet, worksheetCell, rowIndex, columnIndex, worksheetRow.OutlineLevel, false, false, false));
 }
コード例 #4
0
ファイル: WebExcelEsporterEx.cs プロジェクト: bpug/MetronaWT
 /// <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));
             }
         }
     }
 }