C# 如何在内容控制c中获取特定表#

C# 如何在内容控制c中获取特定表#,c#,asp.net,openxml,openxml-sdk,contentcontrol,C#,Asp.net,Openxml,Openxml Sdk,Contentcontrol,我在同一个内容控件中有3个表,如何获取第一个表并将其删除 我试过使用 SdtBlock ccWithTable = mainPart.Document.Body.Descendants<SdtBlock>().Where (r => r.SdtProperties.GetFirstChild<Tag>().Val == tag).Single(); Table theTable = ccWithTable.Descendan

我在同一个内容控件中有3个表,如何获取第一个表并将其删除

我试过使用

SdtBlock ccWithTable = mainPart.Document.Body.Descendants<SdtBlock>().Where
                    (r => r.SdtProperties.GetFirstChild<Tag>().Val == tag).Single();

Table theTable = ccWithTable.Descendants<Table>().First();

ccWithTable.RemoveChild(theTable);
SdtBlock ccWithTable=mainPart.Document.Body.subjections()。其中
(r=>r.SdtProperties.GetFirstChild().Val==tag.Single();
Table theTable=ccWithTable.subjects().First();
ccWithTable.RemoveChild(表格);
但这给了我一个错误:

指定的oldChild不是此元素的子元素


我怀疑,因为表不是内容控件的子对象,有没有其他方法可以这样做?

从您的评论中,我猜您可以访问
对象,但它不是
sdtblock
的直接子对象,因此无法使用
ccWithTable.RemoveChild()
方法删除它(是的,它假定要删除的项是此元素的直接子项的一部分)

但如果可以访问表对象(即子对象),则无需知道其父对象。 只需调用
openxmlement.Remove()
方法:它将从其父元素中删除该元素

theTable.Remove();

您遇到了什么样的错误?@Nahuell指定的oldChild不是此元素的子元素您知道如何清除表对象中表行的内容吗?@yzwboy从未尝试过,也不确定“清除内容”是什么意思。无论如何,这将是另一个问题;)