/// <summary> /// Add column extracting value and converting it before putting into spreadsheet. /// Column is added to the end of the list and will output into next empty sheet column. /// </summary> /// <param name="dataColumnName"> /// Name by which source column is known in underlying data table. /// </param> /// <param name="caption"> /// Caption to set in Excel. /// </param> /// <param name="conversionFunction"> /// Function converting raw column value before outputting it to Excel. The function does not have to handle null /// parameter as it will never be called for null /// </param> /// <returns></returns> public DataTableExportConfigurator AddSafeConvertingDataViewColumn <T>(string dataColumnName, string caption, Func <object, T> conversionFunction) { Check.DoRequireArgumentNotNull(dataColumnName, "dataColumnName"); Check.DoRequireArgumentNotNull(caption, "caption"); Check.DoRequireArgumentNotNull(conversionFunction, "conversionFunction"); var columnSource = new DataColumnSource(dataColumnName, typeof(T), r => GetDataRowColumnValue(r, dataColumnName, conversionFunction)); var columnConfig = new DataColumnExportAutoConfig(Config, Config.Columns.Count, caption, columnSource); Config.AddColumn(columnConfig); return(this); }
/// <summary> /// /// </summary> /// <param name="dataColumnName"></param> /// <param name="sheetColumnIndex"> /// 0-based /// </param> /// <param name="sheetColumnCaption"></param> /// <param name="autoFit"> /// null to leave default setting (as defined by <see cref="DataColumnExportAutoConfig"/>. /// </param> /// <param name="format"> /// null to leave default format (as defined by <see cref="DataColumnExportAutoConfig"/>. /// empty string overrides default format. /// </param> /// <returns></returns> public DataTableExportConfigurator AddColumn(string dataColumnName, int sheetColumnIndex, string sheetColumnCaption, bool?autoFit, string format) { Check.DoRequireArgumentNotNull(dataColumnName, "dataColumnName"); var dataColumn = _table.Columns[dataColumnName]; Check.DoCheckArgument(dataColumn != null, () => $"Column {dataColumnName} not found in data table"); var columnSource = new DataColumnSource(dataColumn); var config = new DataColumnExportAutoConfig(Config, sheetColumnIndex, sheetColumnCaption, columnSource); if (autoFit.HasValue) { config.AutoFit = autoFit.Value; } if (format != null) { config.Format = format; } Config.AddColumn(config); return(this); }