Novacode确定文字样式是否为表格 [英] Novacode Determine If Word Style Is A Table

查看:80
本文介绍了Novacode确定文字样式是否为表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析几个.docx文件,并发现使用Novacode DocX使这项工作变得容易得多.我需要解析这些文档的方式是自上而下的,当我遇到某个对象"(单词表,图片,图形,等式...)时,需要做一些特定的事情.

I need to parse several .docx files and find using Novacode DocX is making this a much easier task. The way I need to parse these documents is from a top-down approach where when I come across a certain "object" ( word table, picture, graphic, equation, ... ) do something specific.

我编写了以下代码.给定一个文档,此代码将按顺序浏览所有段落实例并打印出样式.我注意到其中某些样式(在本例中为"Normal")实际上与表对象相关联.

I wrote the following code. Given a document this code will navigate through all the paragraph instances in-order and print out the styles. I noticed that some of these styles ( "Normal" in this case ) are actually associated with a table object.

using Novacode;
using System;

namespace resrap
{
    internal class Program
    {
        private static void Main( string[] args )
        {
            using ( DocX document = DocX.Load( args[0] ) )
            {
                foreach ( var paraType in document.Paragraphs )
                {
                    Console.WriteLine( paraType.StyleName );
                }
            }
        }
    }
}

我是否可以确定给定的段落是否与Word表相关联?我知道如何获取文档中的所有表,但是由于我需要按顺序解析文档(然后将解析后的内容按排序顺序进行排序),因此使用这种方法并没有帮助,因为我不知道这些内容在哪里表格实际上位于文档中.

Is there a way for me to determine if a given paragraph is associated with a Word table? I know how to grab all the tables in the document but since I need to parse the document in order ( and later put the parsed contents in order of sorts ) using something like this isn't that helpful since I don't know where these tables are actually located within the document.

using Novacode;
using System;

namespace resrap
{
    internal class Program
    {
        private static void Main( string[] args )
        {
            using ( DocX document = DocX.Load( args[0] ) )
            {
                for ( int index = 0; index < document.Tables.Count; index++ )
                {
                    var table = document.Tables[index];
                    // do something with table
                }
            }
        }
    }
}

我不确定我的方法(第一个代码示例)是否是实现此目的的方法,但是在等待任何可能的指导/提示时,我将继续弄清楚这一点.

I am unsure if my approach I have ( first code example ) is the way to do this but I will continue to figure this out while I wait for any possible guidance/tips.

推荐答案

我知道了.我必须查看 ParentContainer 属性以检查单元格值.

I figured it out. I had to look at the ParentContainer properties to check for a cell value.

这篇关于Novacode确定文字样式是否为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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