• 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
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
  • 相关阅读:
    子元素margin带动父元素拖动
    SideBar---fixed定位
    身份证号码
    正则表达式
    关于encodeURIComponent的用法
    判断用户使用的浏览设备
    获取cookie值
    第五周学习总结
    第四周学习总结
    寻找你的黑客偶像
  • 原文地址:https://www.cnblogs.com/zcm123/p/8715599.html
Copyright © 2020-2023  润新知