Beispiel #1
0
        private static void processDataAreas(WordprocessingDocument document, DCTWordDataObject wdo, List <int> ignoreControls)
        {
            var titleRows = document.MainDocumentPart.Document.Body.Descendants <TableRow>().Where(o => o.Descendants <BookmarkStart>().Any());

            foreach (TableRow titleRow in titleRows)
            {
                var bookmarkStart = titleRow.Descendants <BookmarkStart>().FirstOrDefault();

                if (bookmarkStart == null)
                {
                    continue;
                }

                if (bookmarkStart.ColumnFirst == null)
                {
                    continue;
                }


                //针对每一个区域,先读取表头的控件,同时将控件加入黑名单
                DCTDataColumnCollection collection = new DCTDataColumnCollection(titleRow);

                ignoreControls.AddRange(collection.CoveredControlIds);


                //遍历区域中的每一行,生成复杂属性

                var curRow = titleRow.NextSibling <TableRow>();

                DCTComplexProperty cp = new DCTComplexProperty();

                cp.TagID = bookmarkStart.Name;

                while (null != curRow && (!curRow.Descendants <BookmarkEnd>().Any(o => o.Id == bookmarkStart.Id)))
                {
                    DCTWordDataObject childWdo = new DCTWordDataObject();

                    DCTDataRow newDataRow = DCTDataRow.FromTableRow(curRow, collection);

                    if (!newDataRow.IsEmpty)
                    {
                        childWdo.PropertyCollection.AddRange <DCTSimpleProperty>(newDataRow.ToSimpleProperties());
                    }

                    curRow = curRow.NextSibling <TableRow>();

                    cp.DataObjects.Add(childWdo);
                }

                wdo.PropertyCollection.Add(cp);
            }
        }
Beispiel #2
0
        public static DCTDataRow FromTableRow(TableRow row, DCTDataColumnCollection colCollection)
        {
            List <TableCell> cells  = row.Descendants <TableCell>().ToList();
            DCTDataRow       result = new DCTDataRow();

            result.isEmpty = true;
            for (int i = 0; i < cells.Count; i++)
            {
                DCTDataColumn column = null;
                if (colCollection.TryGetValue(i, out column))
                {
                    if (!string.IsNullOrEmpty(cells[i].InnerText))
                    {
                        result.isEmpty = false;
                    }
                    result[column] = cells[i].InnerText;
                }
            }
            return(result);
        }