internal void FillData(DataView dv, TableDescription tableDesp, CreatingDataCellAction <DataRowView> creatingDataCellAction) { dv.NullCheck("数据源不能为空"); int rowIndex = 0; this.Rows.Clear(); foreach (DataRowView drv in dv) { TableRow newRow = this.Rows.NewTableRow(); foreach (TableColumnDescription col in tableDesp.AllColumns) { TableColumn excelColumn; if (this.TryTableColumn(col.ColumnName, col.PropertyName, out excelColumn)) { if (creatingDataCellAction == null) { newRow[excelColumn].Value = drv[col.PropertyName]; } else { creatingDataCellAction(newRow[excelColumn], new CreatingDataCellParameters <DataRowView>(drv, drv[col.PropertyName], col.ColumnName, rowIndex)); } } } rowIndex++; } this.SyncTablePropertiesAfterFillData(dv); }
private void LoadFromDataView(TableDescription tbDesp, DataView dv, CreatingDataCellAction <DataRowView> creatingDataCellAction) { dv.NullCheck("数据源不能为空"); int colIndex = tbDesp.BeginAddress.ColumnIndex; int rowIndex = tbDesp.BeginAddress.RowIndex; this.Names.AddRangeByDescription(tbDesp); foreach (DataRowView drv in dv) { rowIndex++; foreach (TableColumnDescription col in tbDesp.AllColumns) { if (creatingDataCellAction == null) { Cell cell = this.Cells[rowIndex, colIndex]; cell.Value = col.FormatValue(drv[col.PropertyName]); cell.DataType = dv.Table.Columns[col.PropertyName].DataType.ToCellDataType(); } else { creatingDataCellAction(this.Cells[rowIndex, colIndex], new CreatingDataCellParameters <DataRowView>(drv, drv[col.PropertyName], col.ColumnName, rowIndex, col)); } colIndex++; } colIndex = tbDesp.BeginAddress.ColumnIndex; } }
internal void FillData <T>(IEnumerable <T> collection, TableDescription tableDesp, CreatingDataCellAction <T> creatingDataCellAction, LoadFormTableMode fillMode = LoadFormTableMode.FillData) { int rowIndex = 0; if (creatingDataCellAction == null) { creatingDataCellAction = WorkSheet.DefaultCreatingDataCellAction; } if (fillMode == LoadFormTableMode.FillData) { this.Rows.Clear(); } foreach (var objItem in collection) { TableRow newRow = this.Rows.NewTableRow(); foreach (TableColumnDescription col in tableDesp.AllColumns) { if (this.Columns.ContainsKey(col.ColumnName) == false) { continue; } TableCell tbCell = newRow[this.Columns[col.ColumnName]]; object propertyValue = TypePropertiesCacheQueue.Instance.GetObjectPropertyValue(objItem, col.PropertyName); creatingDataCellAction(tbCell, new CreatingDataCellParameters <T>(objItem, propertyValue, col.ColumnName, rowIndex)); } rowIndex++; } }
public void LoadFromDataView(CellAddress beginAddress, ExcelTableStyles tableStyle, DataView dv, CreatingDataCellAction <DataRowView> creatingDataCellAction) { dv.NullCheck <ArgumentNullException>("数据源不能为空!"); TableDescription tbDesp = SpreadSheetAttributeHelper.GetTableDescription(dv.Table); tbDesp.BeginAddress = beginAddress; if (tableStyle == ExcelTableStyles.None && tbDesp.TableName.IsNullOrEmpty()) { this.LoadFromDataView(tbDesp, dv, creatingDataCellAction); } else { tbDesp.TableStyle = tableStyle; Table table; if (this.Tables.TryGetTable(tbDesp.TableName, out table) == false) { table = new Table(this, tbDesp); this.Tables.Add(table); } table.FillData(dv, tbDesp, creatingDataCellAction); } }
private void LoadFromCollectionNotTable <T>(TableDescription tbDesp, IEnumerable <T> collection, CreatingDataCellAction <T> creatingDataCellAction) { int col = tbDesp.BeginAddress.ColumnIndex; int row = tbDesp.BeginAddress.RowIndex; if (creatingDataCellAction == null) { creatingDataCellAction = DefaultCreatingDataCellAction; } this.Names.AddRangeByDescription(tbDesp); foreach (var objItem in collection) { row++; col = tbDesp.BeginAddress.ColumnIndex; foreach (TableColumnDescription tcDesp in tbDesp.AllColumns) { Cell cell = this.Cells[row, col]; if (tcDesp != null) { cell.DataType = tcDesp.DataType.ToCellDataType(); } creatingDataCellAction(cell, new CreatingDataCellParameters <T>(objItem, TypePropertiesCacheQueue.Instance.GetObjectPropertyValue(objItem, tcDesp.PropertyName), tcDesp.ColumnName, row, tcDesp)); col++; } } }
/// <summary> /// 将数据源对象映射生成ExcelTable /// </summary> /// <typeparam name="T">数据模型实体</typeparam> /// <param name="collection">待填充集合</param> /// <param name="tableDesp">生成ExcelTable描述信息</param> /// <param name="creatingDataCellAction">设置Cell相关信息委托</param> public void LoadFromCollection <T>(IEnumerable <T> collection, TableDescription tableDesp, CreatingDataCellAction <T> creatingDataCellAction) { collection.NullCheck("collection"); tableDesp.NullCheck("TableDescription"); if (tableDesp.TableStyle == ExcelTableStyles.None && tableDesp.TableName.IsNullOrEmpty()) { this.LoadFromCollectionNotTable <T>(tableDesp, collection, creatingDataCellAction); } else { Table table; if (this.Tables.TryGetTable(tableDesp.TableName, out table) == false) { table = new Table(this, tableDesp); this.Tables.Add(table); } table.FillData(collection, tableDesp, creatingDataCellAction, tableDesp.FillMode); } }
public void LoadFromCollection <T>(IEnumerable <T> collection, CreatingDataCellAction <T> creatingDataCellAction) { this.LoadFromCollection <T>(collection, SpreadSheetAttributeHelper.GetTableDescription <T>(), creatingDataCellAction); }