本文整理汇总了C#中ISheet.GetOrCreateRow方法的典型用法代码示例。如果您正苦于以下问题:C# ISheet.GetOrCreateRow方法的具体用法?C# ISheet.GetOrCreateRow怎么用?C# ISheet.GetOrCreateRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISheet
的用法示例。
在下文中一共展示了ISheet.GetOrCreateRow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCells
static void CreateCells(ISheet sheet, DataGridColumn col,
IEnumerable source, int colIndex)
{
int rowIndex = 0;
#region header
var headerStyle = GetHeaderCellStyle(sheet.Workbook);
var rowHeader = sheet.GetOrCreateRow(rowIndex++);
var cellHeader = rowHeader.GetOrCreateCell(colIndex);
cellHeader.SetCellValue(GetHeaderText(col.Header));
cellHeader.SetCellType(CellType.String);
cellHeader.CellStyle = headerStyle;
#endregion
var cellStyle = GetCellStyle(col, sheet);
if (col is DataGridBoundColumn)
{
var c = (DataGridBoundColumn)col;
var be = new BindingEvaluator(c.Binding);
foreach (var obj in source)
{
IRow row = sheet.GetOrCreateRow(rowIndex++);
ICell cell = row.GetOrCreateCell(colIndex);
cell.CellStyle = cellStyle;
be.DataContext = obj;
cell.SetCellValue(be.Value);
}
}
else if (col is System.Windows.Controls.DataGridComboBoxColumn)
{
var c = (System.Windows.Controls.DataGridComboBoxColumn)col;
var be = new BindingEvaluator(c.SelectedValueBinding);
var bValue = new BindingEvaluator(new Binding(c.SelectedValuePath));
var bDisplay = new BindingEvaluator(new Binding(c.DisplayMemberPath));
var itemSource = new Dictionary<object, object>();
foreach (var i in c.ItemsSource)
{
bValue.DataContext = i;
bDisplay.DataContext = i;
var value = bValue.Value;
if (value != null)
itemSource[value] = bDisplay.Value;
}
foreach (var obj in source)
{
IRow row = sheet.GetOrCreateRow(rowIndex++);
ICell cell = row.GetOrCreateCell(colIndex);
cell.CellStyle = cellStyle;
be.DataContext = obj;
var value = be.Value;
if (itemSource.ContainsKey(value))
cell.SetCellValue(itemSource[value]);
else
cell.SetCellValue(be.Value);
}
}
else if (col is System.Windows.Controls.DataGridTemplateColumn)
{
var c = (DataGridTemplateColumn)col;
var x = DataGridHelper.GetAttachedBinding(c);
if (x == null) return;
foreach (var obj in source)
{
var be = new BindingEvaluator(new Binding(x));
be.DataContext = obj;
IRow row = sheet.GetOrCreateRow(rowIndex++);
ICell cell = row.GetOrCreateCell(colIndex);
cell.CellStyle = cellStyle;
cell.SetCellValue(be.Value);
}
}
sheet.AutoSizeColumn(colIndex);
}