本文整理汇总了C#中Row.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# Row.Descendants方法的具体用法?C# Row.Descendants怎么用?C# Row.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Row
的用法示例。
在下文中一共展示了Row.Descendants方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExcelCellEnumerator
private IEnumerator<Cell> GetExcelCellEnumerator(Row row)
{
int currentCount = 0;
foreach (Cell cell in row.Descendants<Cell>())
{
string columnName = GetColumnName(cell.CellReference);
int currentColumnIndex = ConvertColumnNameToNumber(columnName);
for (; currentCount < currentColumnIndex; currentCount++)
{
var emptycell = new Cell()
{
DataType = null,
CellValue = new CellValue(string.Empty)
};
yield return emptycell;
}
yield return cell;
currentCount++;
}
}
示例2: createColumns
private void createColumns(DataTable dt,Row row)
{
_colNameMapping = new Dictionary<string, string>();
var cells = row.Descendants<Cell>();
foreach (var cell in cells)
{
string value = getCellValue(cell);
string colHeader = Regex.Split(cell.CellReference.Value, @"\d+").First();
_colNameMapping.Add(colHeader, value);
DataColumn dc = new DataColumn(colHeader);
dt.Columns.Add(dc);
}
}
示例3: addRow
private void addRow(DataTable dt,Row row)
{
DataRow dr = dt.NewRow();
foreach (var cell in row.Descendants<Cell>())
{
string rowHeader = Regex.Split(cell.CellReference.Value, @"\d+").First();
if (_colNameMapping.ContainsKey(rowHeader))
{
dr[rowHeader] = getCellValue(cell);
}
}
dt.Rows.Add(dr);
}
示例4: ValidateCellReferences
/// <summary>
/// Validates that the cell references in the target row are correctly synchronized to
/// the index.
/// </summary>
/// <param name="toValidate">The row to validate.</param>
/// <exception cref="ArgumentException">Thrown if the row has some invalid cell references
/// inside it. This can be fixed by calling <see cref="SyncCellReferencesToRowIndex"/> on the
/// row.</exception>
private static void ValidateCellReferences(Row toValidate)
{
var cellDict = new Dictionary<string, Cell>();
foreach (var cell in toValidate.Descendants<Cell>())
{
if (cellDict.ContainsKey(cell.CellReference.InnerText))
{
throw new ArgumentException("Duplicate cell reference detected at cell: " + cell.CellReference.InnerText);
}
cellDict[cell.CellReference.InnerText] = cell;
}
// Make sure the cell row indices are correct.
var pattern = @"[a-z]+" + toValidate.RowIndex + "{1}";
var regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (var key in cellDict.Keys)
{
if (!regex.IsMatch(key))
{
throw new ArgumentException("Invalid cell reference detected at cell: " + key + ". Regex: " + pattern);
}
}
}
示例5: SyncCellReferencesToRowIndex
/// <summary>
/// Synchronizes cell references to a row's index.
/// </summary>
/// <param name="toSync">The row to synchronize.</param>
private static void SyncCellReferencesToRowIndex(Row toSync)
{
foreach (var cell in toSync.Descendants<Cell>())
{
cell.CellReference.InnerText = Regex.Replace(
cell.CellReference.InnerText,
CellReference.SingleCellRefRegexStringStrict,
@"${col}" + toSync.RowIndex,
RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
ValidateCellReferences(toSync);
}
示例6: GetCells
public IEnumerable<Cell> GetCells(Row xRow)
{
var newRow = new List<Cell>();
int columnIndex = 0;
foreach (Cell cell in xRow.Descendants<Cell>())
{
// Gets the column index of the cell with data
int? columnIndexFromName = GetColumnIndexFromName(GetColumnName(cell.CellReference));
if (columnIndexFromName != null)
{
var cellColumnIndex = (int)columnIndexFromName;
if (columnIndex < cellColumnIndex)
{
do
{
newRow.Add(new Cell());
//tempRow[columnIndex] = //Insert blank data here;
columnIndex++;
}
while (columnIndex < cellColumnIndex);
}
}
newRow.Add(cell);
columnIndex++;
}
return newRow;
}
示例7: IsValidRowDataTemplate
private static bool IsValidRowDataTemplate(Row row, List<Cell> headerCells)
{
if (row.RowIndex <= 1) //At least greater than 1 (row 1 must be the header one)
return false;
var cells = row.Descendants<Cell>().ToList();
if (cells.Count < headerCells.Count) //Must have at least as many cells as the header row to have a template cell for all data columns
return false;
string headerLastCellReference = headerCells[headerCells.Count - 1].CellReference;
string dataCellReference = cells[headerCells.Count - 1].CellReference;
//they must be in the same column
//If cellReferences of HeaderCell and DataCell differ only in the number they are on the same column
var firstDifferentCharacter = headerLastCellReference.Zip(dataCellReference).FirstEx(t => t.Item1 != t.Item2);
int number;
return int.TryParse(firstDifferentCharacter.Item1.ToString(), out number);
}
示例8: AddRow
private void AddRow(Row descendant)
{
MyRows.Add(new ExcelOpenXmlRow(descendant.Descendants<Cell>(), SharedStrings));
}
示例9: GetRowCells
///<summary>returns an empty cell when a blank cell is encountered
///</summary>
private static IEnumerable<Cell> GetRowCells(Row row)
{
int currentCount = 0;
foreach(Cell cell in row.Descendants<DocumentFormat.OpenXml.Spreadsheet.Cell>())
{
int currentColumnIndex = GetColumnIndexFromName(cell.CellReference);
for(; currentCount < currentColumnIndex; currentCount++)
{
yield return new DocumentFormat.OpenXml.Spreadsheet.Cell();
}
yield return cell;
currentCount++;
}
}