如何从word文档到DB读取目录? [英] How to read Table of Contents from word document into DB?

查看:70
本文介绍了如何从word文档到DB读取目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种从单词中读取目录的方法。

I need a way to read Table of Contents from word.

找到检索XELEMENT的代码:

Found the code to retrieve XELEMENT:


public static XElement WDRetrieveTOC(string fileName)

    {

      XElement TOC = null;



      using (var document = WordprocessingDocument.Open(fileName, false))

      {

        var docPart = document.MainDocumentPart;

        var doc = docPart.Document;



        OpenXmlElement block = doc.Descendants<DocPartGallery>().

         Where(b => b.Val.HasValue && (b.Val.Value == "Table of Contents")).FirstOrDefault();

        if (block != null)

        {

          // Back up to the enclosing SdtBlock and return that XML.

          while ((block != null) && (!(block is SdtBlock)))

          {

            block = block.Parent;



          }

        

          TOC = new XElement("TOC", block.OuterXml);



          

        }

      }

      return TOC;

    }

推荐答案

Hi Pascari,

Hi Pascari,

谢谢 你发帖了。

Thank  you for posting.

我在你的身边运行你的代码,效果很好。我不确定你想要什么信息?你能举个例子吗?我将进一步研究您的详细信息。

I run your code on my side and it works well. I am not sure what info do you want to get? Can you give a example about this? I will do further research with your detailed information.

以下是MSDN上的文章供您参考:

And here is the article on MSDN for you to reference:

http://msdn.microsoft.com/en-us/library/gg308473.aspx

希望这可以帮助你,随时跟进。

Hope this can help you and just feel free to follow up.

最好的问候,


这篇关于如何从word文档到DB读取目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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