Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Excel电子表格中访问行单元格计数_C#_Excel_Openxml - Fatal编程技术网

C# 在Excel电子表格中访问行单元格计数

C# 在Excel电子表格中访问行单元格计数,c#,excel,openxml,C#,Excel,Openxml,我需要知道如何使用OpenXML获取行对象中的单元格数。目前,我正在使用 row.Descendants<Cell>().Count<Cell>() row.subjections().Count()) 但这根本不正确。你知道什么方法/属性可以给我细胞计数吗 您可以使用以下方法之一获取计数: row.Descendants<Cell>().Count<Cell>() //The one you used row.Elements<Cel

我需要知道如何使用OpenXML获取行对象中的单元格数。目前,我正在使用

row.Descendants<Cell>().Count<Cell>()
row.subjections().Count())

但这根本不正确。你知道什么方法/属性可以给我细胞计数吗

您可以使用以下方法之一获取计数:

row.Descendants<Cell>().Count<Cell>() //The one you used

row.Elements<Cell>().Count<Cell>()

row.Count()

我刚刚用一个简单的Excel文档测试了您的代码,它返回了正确的单元格计数。你能告诉我们更多关于你的问题吗。该行是否包含合并的单元格?
SpreadsheetDocument ExcelSpreadSheet = SpreadsheetDocument.Open(ReportFile, true);
WorksheetPart ExcelWSP = GetWorksheetPartByName(ExcelSpreadSheet, TemplateEntity.ExcelSheetName);
MergeCells mergeList = ExcelWSP.Worksheet.Elements<MergeCells>().First();
((MergeCell)mergeList.ElementAt(i)).Reference