/// <summary> /// 将 exportable 中的数据连接到当前 sheet 中 /// 调用顺序: NewExcel() -> NewSheet() -> Union() -> WriteTo() -> CloseExcel(). /// </summary> /// <param name="header">导出对象头.</param> /// <param name="callback">导出回调.</param> /// <returns> /// this, 以支持链式操作. /// </returns> public Exporter UnionHeader(IExportHeader header, ExportCallback callback) { //ExportCallback exportCallback = callback; var context = this._context; if (context == null) { throw new Exception("请先调用 NewExcel()"); } var sheet = context.Sheet; if (sheet == null) { throw new Exception("请先调用 NewSheet()"); } var y = context.StartRowIndex; IRow row = null; int columnIndex = 0, x = 0; context.RowIndex = 0; context.CellType = CellType.HeaderCell; while (true) { context.Reset(); context.ColumnIndex = columnIndex; if (header.NextHeaderCell(columnIndex, context)) { if (callback != null) { callback(context); } if (context.IsValid) { // 创建单元格 if (row == null) { row = sheet.CreateRow(y++); } var cell = row.CreateCell(x++); // 设置单元格 SetCell(cell, context); } ++columnIndex; } else { break; } } context.StartRowIndex = y; return(this); }
/// <summary> /// Initializes a new instance of the <see cref="PagedExportable"/> class. /// </summary> /// <param name="header">导出头.</param> /// <param name="target">包含要导出数据的 Exportable.</param> /// <param name="pageSize">分页大小.</param> public PagedExportable(IExportHeader header, IExportable target, int pageSize) { if (target == null) throw new ArgumentNullException("target"); if (pageSize < 1 || pageSize > 65536) throw new ArgumentOutOfRangeException("pageSize"); this._header = header; this._target = target; this._pageSize = pageSize; this._startIndex = 0; }