public static GeneralDataProcessor CreateProcessor(WordprocessingDocument document, DCTDataProperty property) { if (property is DCTSimpleProperty) return new SimplePropertyProcessor(document, (DCTSimpleProperty)property); return new ComplexPropertyProcessor(document, (DCTComplexProperty)property); }
public override void Process() { var titleRow = document.MainDocumentPart.Document.Body .Descendants <TableRow>().Where(o => o.Descendants <BookmarkStart>().Any(mark => mark.Name == DataProperty.TagID)).FirstOrDefault(); var sdtElements = titleRow.Descendants <SdtElement>().Where(o => o.SdtProperties.Descendants <SdtAlias>().Any(a => a.Val != null)).ToList(); var bookmarkStart = titleRow.Descendants <BookmarkStart>().Where(o => o.Name == DataProperty.TagID).FirstOrDefault(); List <string> properties = new List <string>(); for (int i = 0; i < sdtElements.Count; i++) { properties.Add(sdtElements[i].Descendants <SdtAlias>().FirstOrDefault().Val.Value); } TableRow curRow = titleRow; foreach (DCTWordDataObject wordDataObj in DataProperty.DataObjects) { TableRow newRow = curRow.InsertAfterSelf <TableRow>((TableRow)curRow.NextSibling <TableRow>().CloneNode(true)); TableCell firstCell = newRow.GetFirstChild <TableCell>(); for (int j = bookmarkStart.ColumnFirst; j <= bookmarkStart.ColumnLast; j++) { DCTDataProperty dataProperty = wordDataObj.PropertyCollection[properties[j - bookmarkStart.ColumnFirst]]; if (dataProperty is DCTSimpleProperty) { DCTSimpleProperty simpleProperty = dataProperty as DCTSimpleProperty; TableCell cell = getCellByIndex(firstCell, j); Paragraph p = cell.Descendants <Paragraph>().FirstOrDefault(); p.RemoveAllChildren(); p.AppendChild <Run>(new Run(new Text((GeneralFormatter.ToString(simpleProperty.Value, simpleProperty.FormatString))))); } } curRow = newRow; } }
public GeneralDataProcessor(WordprocessingDocument document, DCTDataProperty dataProperty) { this.document = document; this.dataProperty = dataProperty; }
public override void Process() { var titleRow = document.MainDocumentPart.Document.Body .Descendants <TableRow>().Where(o => o.Descendants <BookmarkStart>().Any(mark => mark.Name == DataProperty.TagID)).FirstOrDefault(); var sdtElements = titleRow.Descendants <SdtElement>().Where(o => o.SdtProperties.Descendants <SdtAlias>().Any(a => a.Val != null)).ToList(); var bookmarkStart = titleRow.Descendants <BookmarkStart>().Where(o => o.Name == DataProperty.TagID).FirstOrDefault(); List <string> properties = new List <string>(); for (int i = 0; i < sdtElements.Count; i++) { properties.Add(sdtElements[i].Descendants <SdtAlias>().FirstOrDefault().Val.Value); } TableRow curRow = titleRow; foreach (DCTWordDataObject wordDataObj in DataProperty.DataObjects) { TableRow newRow = curRow.InsertAfterSelf <TableRow>((TableRow)curRow.NextSibling <TableRow>().CloneNode(true)); TableCell firstCell = newRow.GetFirstChild <TableCell>(); int columnFirst = Int32Value.ToInt32(bookmarkStart.ColumnFirst); //== default(Int32Value) ? bookmarkStart.ColumnFirst.Value : 0; int columnLast = Int32Value.ToInt32(bookmarkStart.ColumnLast); for (int j = columnFirst; j <= columnLast; j++) { DCTDataProperty dataProperty = wordDataObj.PropertyCollection[properties[j - columnFirst]]; if (dataProperty is DCTSimpleProperty) { DCTSimpleProperty simpleProperty = dataProperty as DCTSimpleProperty; TableCell cell = GetCellByIndex(firstCell, j); Paragraph p = cell.GetFirstChild <Paragraph>(); string[] rows = GetMultiRowsValues(simpleProperty); for (int i = 0; i < rows.Length; i++) { if (i == 0) { Run runElement = GetRunElement(p); FillText(ref runElement, GeneralFormatter.ToString(rows[i], simpleProperty.FormatString)); } else { Paragraph addrow = p.CloneNode(true) as Paragraph; Run addrunelement = GetRunElement(addrow); //addrow.GetFirstChild<Run>(); FillText(ref addrunelement, GeneralFormatter.ToString(rows[i], simpleProperty.FormatString)); p.InsertAfterSelf <Paragraph>(addrow); } } } } curRow = newRow; } }
public static GeneralDataProcessor CreateProcessor(WordprocessingDocument document, DCTDataProperty property) { if (property is DCTSimpleProperty) { return(new SamplePropertyProcessor(document, (DCTSimpleProperty)property)); } return(new ComplexPropertyProcessor(document, (DCTComplexProperty)property)); }