zoukankan      html  css  js  c++  java
  • foreach word items -- openxml

    The above xml text is a super simplified version but the structure is exactly the same. A simpler version of the structure is here Document > Body > Table > Table_Row > Table_Cell > Paragraph > Run > Field_Char > Form_Field_Data > Checkbox

    Below is my extremely ugly way of iterating through the xml text in an attempt to locate the bookmark and checkbox. Note: I was only planning on getting it working and then I will optimise later.

            foreach (var table in document.MainDocumentPart.Document.Body.ChildElements.Where(t => t is DocumentFormat.OpenXml.Wordprocessing.Table))
            {
                foreach (var row in table.ChildElements.Where(r => r is DocumentFormat.OpenXml.Wordprocessing.TableRow))
                {
                    foreach (var cell in row.ChildElements.Where(c => c is DocumentFormat.OpenXml.Wordprocessing.TableCell))
                    {
                        foreach (var paragraph in cell.ChildElements.Where(p => p is DocumentFormat.OpenXml.Wordprocessing.Paragraph))
                        {
                            foreach (var run in paragraph.ChildElements.Where(r => r is DocumentFormat.OpenXml.Wordprocessing.Run))
                            {
                                foreach (var fieldChar in run.ChildElements.Where(fc => fc is DocumentFormat.OpenXml.Wordprocessing.FieldChar))
                                {
                                    foreach (var formFieldData in fieldChar.ChildElements)
                                    {
                                        foreach (var child in formFieldData.ChildElements)
                                        {
                                            //Check bookmark name
                                            //If bookmark name matches, 
                                            //Set checkbox value to true
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
  • 相关阅读:
    java 实现图表展示
    jar包可以到maven下载
    eclipse java ee 添加jrebel 工具
    单链表逆序
    面试-准备
    面试基础知识整理
    mysql中CONCAT值为空的问题解决办法
    数字签名 数字证书
    java 内存泄露分析(jmap + MemoryAnalyzer)
    Chrome 控制台console的用法
  • 原文地址:https://www.cnblogs.com/zcm123/p/8715599.html
Copyright © 2011-2022 走看看