获取Word文档表中的最大行数和列数。 [英] Get The maximum number of rows and columns in a Word document table.
本文介绍了获取Word文档表中的最大行数和列数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
各位大家好!,
我很擅长使用这个库,我正在开发一个工具来从Word文档中的表中提取信息。
我想知道是否有任何方法可以获得表格的最大行数和列数。
I am quite new using this library and I am developing a tool to extract information from tables in a Word document.
I would like to know if is there any way to get the maximum number of rows and columns of the table.
非常感谢您的帮助。
推荐答案
嗨Chema,
Hi Chema,
根据你的描述,我认为你想要的是得到一个表的行/列数,对吗?
你可以通过Elements< TableRow>()得到行计数.Count()和通过Elements< GridColumn>()获取列.Count()
According to your describtion,i think what you want is getting row/column count of the a table,right?
You could get row count by Elements<TableRow>().Count() and get column by Elements<GridColumn>().Count()
这是一个例子。
Here is an example.
using (WordprocessingDocument doc =
WordprocessingDocument.Open(filepath, true))
{
// Find the first table in the document.
Table table =
doc.MainDocumentPart.Document.Body.Elements<Table>().First();
// Find the second row in the table.
int row = table.Elements<TableRow>().Count();
int col = table.Elements<TableGrid>().First().Elements<GridColumn>().Count();
MessageBox.Show("RowCount:" + row + "\r" +
"ColmunCount:" + col);
}
最好的问候,
Edward
这篇关于获取Word文档表中的最大行数和列数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文