使用书签从word 2007中的表中删除行 [英] Using bookmark to delete a row from a table in word 2007

查看:119
本文介绍了使用书签从word 2007中的表中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好全部

我需要知道如何使用Open XML从word文档中的表中删除行?
我试图做的是在桌子上添加书签以访问它,但我找不到任何方法既不删除该书签的表格,也不删除该书签的一行。

任何帮助?

问候,
Ahmad Atat

解决方案

嗨Ahmad Atat!

这取决于哪里放置书签的开头。
如果它在桌子外面,你可以这样做:
处理文字处理wordProcessingDocument;
字符串bookmarkName =" Table1";
BookmarkStart bookmarkStart = wordProcessingDocument.MainDocumentPart.Document.Body。
   后代< BookmarkStart>()&
NBSP;&NBSP;&NBSP;其中(bkmarkStart => bkmarkStart.Name == bookmarkName).First();
表tableInsideBookmark = bookmarkStart.Parent.NextSibling< Table>();
TableRow firstRow = tableInsideBookmark.GetFirstChild< TableRow>( );

//删除第一行
第一行。删除();

//删除表
tableInsideBookmark.Remove();


Hi All,

I need to know how to delete a row from a table in word document using Open XML?
What i tried to do is to add bookmark on the table to access it,but i can't find any method to delete neither the table of this bookmark nor a row from it.

Any Help?

Regards,
Ahmad Atat

解决方案

Hi Ahmad Atat!

It depends on where the start of the bookmark is placed.
If it is outside the table, you could do something like this:



WordprocessingDocument wordProcessingDocument;
string bookmarkName = "Table1";
BookmarkStart bookmarkStart = wordProcessingDocument.MainDocumentPart.Document.Body.
    Descendants<BookmarkStart>().
    Where(bkmarkStart => bkmarkStart.Name == bookmarkName).First();
Table tableInsideBookmark = bookmarkStart.Parent.NextSibling<Table>();
TableRow firstRow = tableInsideBookmark.GetFirstChild<TableRow>();

// Delete first row
firstRow.Remove();

// Delete table
tableInsideBookmark.Remove();


这篇关于使用书签从word 2007中的表中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆