Заранее спасибо!
Роберт
Код: Выделить всё
foreach (var row in sheetData.Elements().Reverse())
{
for (int i = 0; i < 7; i++) // Only check the first 7 columns
{
var cell = row.Elements().ElementAtOrDefault(i);
if (HasText(cell, workbookPart))
{
lastRowIndex = row.RowIndex.Value;
Console.WriteLine(lastRowIndex);
break;
}
}
if (lastRowIndex != 0)
break;
}
private bool HasText(Cell cell, WorkbookPart workbookPart)
{
if (cell == null) return false;
if (cell.DataType != null && cell.DataType == CellValues.SharedString)
{
int sharedStringIndex = int.Parse(cell.CellValue.InnerText);
SharedStringItem item = workbookPart.SharedStringTablePart.SharedStringTable.Elements().ElementAt(sharedStringIndex);
return !string.IsNullOrEmpty(item.InnerText);
}
return !string.IsNullOrEmpty(cell.CellValue?.InnerText);
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -all-forma