PreferredWidthFromPercent Method |
Namespace: Aspose.Words.Tables
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table with a width that takes up half the page width Table table = builder.StartTable(); // Insert a few cells builder.InsertCell(); table.PreferredWidth = PreferredWidth.FromPercent(50); builder.Writeln("Cell #1"); builder.InsertCell(); builder.Writeln("Cell #2"); builder.InsertCell(); builder.Writeln("Cell #3"); doc.Save(ArtifactsDir + "DocumentBuilder.InsertTableWithPreferredWidth.doc");
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table row made up of three cells which have different preferred widths Table table = builder.StartTable(); // Insert an absolute sized cell builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(40); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightYellow; builder.Writeln("Cell at 40 points width"); PreferredWidth width = builder.CellFormat.PreferredWidth; Console.WriteLine($"Width \"{width.GetHashCode()}\": {width.ToString()}"); // Insert a relative (percent) sized cell builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue; builder.Writeln("Cell at 20% width"); // Each cell had its own PreferredWidth Assert.False(builder.CellFormat.PreferredWidth.Equals(width)); width = builder.CellFormat.PreferredWidth; Console.WriteLine($"Width \"{width.GetHashCode()}\": {width.ToString()}"); // Insert a auto sized cell builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.Auto; builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGreen; builder.Writeln( "Cell automatically sized. The size of this cell is calculated from the table preferred width."); builder.Writeln("In this case the cell will fill up the rest of the available space."); doc.Save(ArtifactsDir + "DocumentBuilder.InsertCellsWithPreferredWidths.docx");