ShapeBaseIsLayoutInCell Property |
Namespace: Aspose.Words.Drawing
The default value is true.
Has effect only for top level shapes, the property WrapType of which is set to value other than Inline.
//Document doc = new Document(MyDir + "Shape.LayoutInCell.docx"); Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartTable(); builder.RowFormat.Height = 100; builder.RowFormat.HeightRule = HeightRule.Exactly; for (int i = 0; i < 31; i++) { if (i != 0 && i % 7 == 0) builder.EndRow(); builder.InsertCell(); builder.Write("Cell contents"); } builder.EndTable(); NodeCollection runs = doc.GetChildNodes(NodeType.Run, true); int num = 1; foreach (Run run in runs.OfType<Run>()) { Shape watermark = new Shape(doc, ShapeType.TextPlainText); watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page; // False - display the shape outside of table cell, True - display the shape outside of table cell watermark.IsLayoutInCell = true; watermark.Width = 30; watermark.Height = 30; watermark.HorizontalAlignment = HorizontalAlignment.Center; watermark.VerticalAlignment = VerticalAlignment.Center; watermark.Rotation = -40; watermark.Fill.Color = Color.Gainsboro; watermark.StrokeColor = Color.Gainsboro; watermark.TextPath.Text = string.Format("{0}", num); watermark.TextPath.FontFamily = "Arial"; watermark.Name = $"WaterMark_{Guid.NewGuid()}"; // Property will take effect only if the WrapType property is set to something other than WrapType.Inline watermark.WrapType = WrapType.None; watermark.BehindText = true; builder.MoveTo(run); builder.InsertNode(watermark); num = num + 1; } // Behaviour of MS Word on working with shapes in table cells is changed in the last versions // Adding the following line is needed to make the shape displayed in center of a page doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010); doc.Save(ArtifactsDir + "Shape.LayoutInTableCell.docx");