Page 1 of 1

So erhalten Sie eine bestimmte Zeile anhand des Arbeitsblatts und des Zeilenindex in einer Excel-Datei

Posted: 24 Dec 2024, 07:06
by Anonymous
Ich muss mithilfe von openXML eine bestimmte Zelle in meiner Excel-Datei auswählen:

Worksheet workSheet = workSheetPart.Worksheet;
Cell cell = GetCell(workSheet, "B", 2);

private static Cell GetCell(Worksheet worksheet,
string columnName, uint rowIndex)
{
Row row = GetRow(worksheet, rowIndex);

if (row == null)
return null;

return row.Elements().Where(c => string.Compare
(c.CellReference.Value, columnName +
rowIndex, true) == 0).First();
}

private static Row GetRow(Worksheet worksheet, uint rowIndex)
{
var test = worksheet.GetFirstChild().
Elements().Where(r => r.RowIndex == rowIndex).First(); //Here is the problem.

return worksheet.GetFirstChild().
Elements().Where(r => r.RowIndex == rowIndex).First();
}


Beim Debuggen ist mir aufgefallen, dass RowIndex null ist, was meiner Meinung nach das Problem in der Linq-Abfrage verursacht