Novacode确定文字样式是否为表格

编程入门 行业动态 更新时间:2024-10-11 11:19:47
本文介绍了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确定文字样式是否为表格

本文发布于:2023-10-19 18:51:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   表格   文字   Novacode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!