private void SendForDownload(Workbook document, WorkbookFormat excelFormat) { string documentFileNameRoot; documentFileNameRoot = string.Format("Document.{0}", excelFormat == WorkbookFormat.Excel97To2003 ? "xls" : "xlsx"); Response.Clear(); Response.AppendHeader("content-disposition", "attachment; filename=" + documentFileNameRoot); Response.ContentType = "application/octet-stream"; document.SetCurrentFormat(excelFormat); document.Save(Response.OutputStream); Response.End(); }
public ExcelExportingModel(WorkbookFormat exportFormat) { this.excelWorkbook = new Workbook(exportFormat); }
/// <summary> /// Exports a single flat grid to the specified worksheet. /// Exporting starts from the defined row and column offsets. /// /// </summary> public virtual void Export(WebDataGrid grid, Worksheet worksheet, int rowOffset, int columnOffset) { this._currentWorkbookFormat = worksheet.Workbook.CurrentFormat; ExcelExportingEventArgs e = new ExcelExportingEventArgs(worksheet, rowOffset, columnOffset, 0); this.OnExporting(e); if (e.Cancel) return; rowOffset = e.CurrentRowIndex; this.InitStyleSheet(grid.RunBot); this.ExportGrid(grid, worksheet, ref rowOffset, columnOffset, 0); this._currentStyleSheet = (StyleSheet)null; this.OnExported(new ExcelExportedEventArgs(worksheet, rowOffset, columnOffset, 0)); this.DownloadWorkbook(worksheet.Workbook); }
public virtual void Export(Worksheet worksheet, params WebDataGridExport[] grids) { this._currentWorkbookFormat = worksheet.Workbook.CurrentFormat; var e = new ExcelExportingEventArgs(worksheet, grids[0].RowOffset, grids[0].ColumnOffset, 0); this.OnExporting(e); if (e.Cancel) { return; } int currentRowIndex = e.CurrentRowIndex; foreach (var grid in grids) { int rowIndex = grid.RowOffset; this.InitStyleSheet(grid.WebDataGrid.RunBot); this.ExportGrid(grid.WebDataGrid, worksheet, ref rowIndex, grid.ColumnOffset, 0); this._currentStyleSheet = (StyleSheet)null; currentRowIndex += this._gridsRowSpacing; } this.OnExported(new ExcelExportedEventArgs(worksheet, currentRowIndex, columnOffset, 0)); this.DownloadWorkbook(worksheet.Workbook); }
/// <summary> /// Exports multiple grids on a single worksheet. /// /// </summary> public virtual void Export(Worksheet worksheet, int rowOffset, int columnOffset, params WebControl[] grids) { this._currentWorkbookFormat = worksheet.Workbook.CurrentFormat; ExcelExportingEventArgs e = new ExcelExportingEventArgs(worksheet, rowOffset, columnOffset, 0); this.OnExporting(e); if (e.Cancel) return; int currentRowIndex = e.CurrentRowIndex; foreach (object obj in grids) { if (obj is WebDataGrid) { this.InitStyleSheet(((FlatDataBoundControl)obj).RunBot); this.ExportGrid((WebDataGrid)obj, worksheet, ref currentRowIndex, columnOffset, 0); this._currentStyleSheet = (StyleSheet)null; currentRowIndex += this._gridsRowSpacing; } else if (obj is WebHierarchicalDataGrid) { this.InitStyleSheet(((HierarchicalDataBoundControlMain)obj).RunBot); this.ExportHierarchicalGrid((WebHierarchicalDataGrid)obj, worksheet, ref currentRowIndex, columnOffset); this._currentStyleSheet = (StyleSheet)null; currentRowIndex += this._gridsRowSpacing; } else throw new InvalidOperationException(Infragistics.Web.UI.SR.GetString("EE_CONTROL_NOT_SUPPORTED_EXCEPTION", new object[1] { (object) obj.GetType().Name })); } this.OnExported(new ExcelExportedEventArgs(worksheet, currentRowIndex, columnOffset, 0)); this.DownloadWorkbook(worksheet.Workbook); }