public abstract void FormatRange(ExternalExcelRangeFormatInfo formatInfo);
public bool Write <C, R>(IAsyncProgress2 o, object source, bool writeHeaders, IEnumerable columns, GetExcelWriteColumnName <C> getColumnName, IEnumerable items, GetExcelWriteRowItemValue <C, R> getItemValue, Action <ExternalExcelRangeFormatInfo> modifyRange) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "Write"); bool result = default(bool); if (source == null || items == null || columns == null) { return(false); } try { int rows = 0; int cols = 0; o.CrossThreadInvoke(new Action(() => { rows = (writeHeaders ? items.GetCollectionCount <R>() + 1 : items.GetCollectionCount <R>()); cols = columns.GetCollectionCount <C>(); })); int rowIndex = 1, rowIndex0 = 0; int colIndex = 1, colIndex0 = 0; object[,] values = Extensions.CreateArray(rows, cols, 1, 1); if (o != null) { o.InitializeProgress(1, rows); } ExternalExcelRangeFormatInfo rangeInfo = new ExternalExcelRangeFormatInfo(1, 1, rows, cols); if (modifyRange != null) { modifyRange(rangeInfo); } if (writeHeaders) { if (o != null) { o.UpdateStatusProgress(rowIndex, "Preparing row : " + rowIndex.ToString()); } colIndex0 = 0; foreach (C col in columns.OfType <C>()) { o.CrossThreadInvoke(new Action(() => { values[rowIndex, colIndex] = getColumnName(col, colIndex0); })); using (ExternalExcelRangeFormatInfo rangeInfo2 = new ExternalExcelRangeFormatInfo(rowIndex, colIndex, rowIndex, colIndex)) { rangeInfo2.BackColor = Color.Blue; rangeInfo2.ForeColor = Color.White; rangeInfo2.HorizontalAlignment = ExternalExcelCellHAlign.AlignLeft; rangeInfo2.VerticalAlignment = ExternalExcelCellVAlign.AlignCenter; this.FormatRange(rangeInfo2); } colIndex++; colIndex0++; } using (ExternalExcelRangeFormatInfo rangeInfo2 = new ExternalExcelRangeFormatInfo(rowIndex, 1, rowIndex, cols)) { rangeInfo2.AutoFilter = true; this.FormatRange(rangeInfo2); } rowIndex++; } IEnumerable items2 = null; o.CrossThreadInvoke(new Action(() => { items2 = items.OfType <R>(); })); IEnumerator enumerator = items2.GetEnumerator(); if (enumerator != null) { bool hasNext = true; while (hasNext) { o.CrossThreadInvoke(new Action(() => { hasNext = enumerator.MoveNext(); })); if (hasNext && enumerator.Current != null) { R dr = (R)enumerator.Current; if (rowIndex > rows) { break; } colIndex = 1; colIndex0 = 0; foreach (C col in columns) { o.CrossThreadInvoke(new Action(() => { values[rowIndex, colIndex] = getItemValue(dr, rowIndex0, col, colIndex0); })); colIndex++; colIndex0++; } if (o != null) { if (o.ExecutorService != null && o.ExecutorService.IsShutdown) { break; } o.UpdateStatusProgress(rowIndex, "Preparing row : " + rowIndex.ToString()); } rowIndex++; rowIndex0++; Thread.Sleep(1); } } } // excel writing result = this.Write(o, values, rangeInfo); // excel formatting o.UpdateStatus("Formatting..."); this.FormatRange(rangeInfo); } catch (Exception ex) { Log.Exception(PROC, ex); } return(result); }
public override void FormatRange(ExternalExcelRangeFormatInfo formatInfo) { }