如何在asp.net中使用interop从word表中读取垂直合并的单元格 [英] How to read vertically merged cells from word table using interop in asp.net
问题描述
我们要求阅读类似模板的Word文档。这个word文档有多个表。我们可以读取普通表,但如果表有垂直合并单元格,则应用程序会抛出异常。
有些正文可以帮助代码。
提前致谢
Murali krishna。
Hi,
We have a requirement to read Word documents which is like template. This word document is having multiple tables. We can able to read normal tables but application is throwing exception if a table is having vertically merge cells.
Can some body help with the code.
Thanks in advance
Murali krishna.
推荐答案
我们找到的唯一方法是要做的事情
The only way that we have found is to do
var myDictionary<int,> = new Dictionary<int,>();
var cell = myTable.Cell(1, 1);
while(cell != null)
{
// Cache the line
myDictionary[cell.ColumnIndex] = cell.Range.Text;
// The second part is so we don't display if we just started
if(cell.ColumnIndex == 1 && cell.RowIndex != 1)
{
Trace.WriteLine("Data at row {0} is:", cell.RowIndex);
foreach(KeyValuePair<int,> kvp in myDictionary)
{
Trace.WriteLine(" Column({0}) --> {1})", kvp.Key, kvp.Value);
}
Trace.WriteLine("");// or output a \n
}
// Move to the next *valid* cell
// cell.Next skips cells that merged and already looked at
cell = cell.next
}
为了跟踪上一个单元格中的内容,我们使用了一个字典,并在我们到达下一行的第一列时将其清除。
此代码不会显示最后一行但它会给你一个想法
To keep track of what was in the previous cell, we used a dictionary and cleared it whenever we got to the first column of the next row.
This code won't show the last row but it gives you the idea
这篇关于如何在asp.net中使用interop从word表中读取垂直合并的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!