Example #1
0
 /// <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));
 }
Example #2
0
 /// <summary>
 /// Raises the GridRecordItemExporting Event.
 /// 
 /// </summary>
 protected virtual void OnGridRecordItemExporting(GridRecordItemExportingEventArgs e)
 {
     GridRecordItemExportingEventHandler exportingEventHandler = this.Events[WebExcelExporter.EventGridRecordItemExporting] as GridRecordItemExportingEventHandler;
     if (exportingEventHandler == null)
         return;
     exportingEventHandler((object)this, e);
 }