gpt4 book ai didi

c# - OpenXmlReader.Skip 应该如何工作?

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:35 49 4
gpt4 key购买 nike

来自 documentation :

Skips the child elements of the current node.

代码如下:

var reader = DocumentFormat.OpenXml.OpenXmlReader.Create(worksheetPart);

// Header
while (reader.Read())
{
if (reader.ElementType == typeof (Row)) // reader is at row r="1"
{
headers = GetHeaders((Row)reader.LoadCurrentElement(), _doc.WorkbookPart);
reader.ReadNextSibling(); // reader is at row r="2"
break;
}
}

//...
reader.Skip(); // reader is at row r="3"

工作表 xml(剪切):

<x:sheetData xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:row r="1" spans="1:1">
<x:c r="A1" s="1" t="s">
<x:v>36</x:v>
</x:c>
</x:row>
<x:row r="2" spans="1:1"> <!-- before calling Skip reader is here -->
<x:c r="A2" s="1" t="s">
<x:v>38</x:v>
</x:c>
</x:row> <!-- I expect reader to be here after calling Skip because closing tag != child element -->
<x:row r="3" spans="1:1"> <!-- after calling Skip reader goes here -->
<x:c r="A3" s="1" t="s">
<x:v>38</x:v>
</x:c>
</x:row>
</x:sheetData>

为什么 Skip也跳过 </x:row>

最佳答案

<x:row>是开始标记(标记开始)和 </x:row>是 XML 文件中 one 元素的结束标记(标记结束)。

解析 XML 文档后,它表示为节点对象树,每个节点都有父节点、兄弟节点和子节点。

所以不要混淆内存中树的表示和文件的表示。

关于c# - OpenXmlReader.Skip 应该如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35230243/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com