We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can I float a table next to text

I’m Trying to recreate the table (example in the attachment) with the documentbuilder

I have a caption to the left, on the right I’m supposed to add a table with an undifined number of rows:

Caption |Cell1 | Cell2 |
|Cell 3| Cell4 |

I tried by creating the table and applying LeftPadding, RightPadding and TextWrapping.Around but I cant seem to get the table to start on the same row as my caption.

this is what I have so far:
builder.Writeln();
builder.Write(“Caption”);

var currentTable = builder.StartTable();
builder.InsertCell(“A”);
builder.InsertCell(“B”);
builder.EndRow();

foreach (var rowToInsert in rowsToInsert)
{
builder.InsertCell();
builder.InsertHtml(rowToInsert.A,true);
builder.InsertCell();
builder.InsertHtml(rowToInsert.B, true);
builder.EndRow();
}
builder.EndTable();

currentTable.LeftPadding = ConvertUtil.MillimeterToPoint(50);
currentTable.RightPadding = ConvertUtil.MillimeterToPoint(50);
currentTable.TextWrapping = TextWrapping.Around;

Is this possible, and if so, how can I accomplish this layout?

Thanks in advance!





Hi Kevin,

Thanks
for your inquiry. Unfortunately, Aspose.Words does not support to set/get positioning of floating table at the moment. However, I have logged this feature
request as WORDSNET-12204 in our issue tracking system. You will be
notified via this forum thread once this feature is available.

We apologize for your inconvenience.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan

The issues you have found earlier (filed as WORDSNET-12204) have been fixed in this Aspose.Words for .NET 20.1 update and this Aspose.Words for Java 20.1 update.

@kevin.parret

It is to inform you that starting from Aspose.Words 20.1 it is possible to float the table next to text. We added RelativeHorizontalAlignment, AbsoluteHorizontalDistance, RelativeVerticalAlignment, and AbsoluteVerticalDistance properties in table class. You can use these properties to set the table’s position on the page in Word document according to your requirement.

Following code example shows how set the location of floating tables.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a table
Table table = builder.StartTable();
builder.InsertCell();
builder.Write("Table 1, cell 1");
builder.EndTable();
table.PreferredWidth = PreferredWidth.FromPoints(300);

// We can set the table's location to a place on the page, such as the bottom right corner
table.RelativeVerticalAlignment = VerticalAlignment.Bottom;
table.RelativeHorizontalAlignment = HorizontalAlignment.Right;

table = builder.StartTable();
builder.InsertCell();
builder.Write("Table 2, cell 1");
builder.EndTable();
table.PreferredWidth = PreferredWidth.FromPoints(300);

// We can also set a horizontal and vertical offset from the location in the paragraph where the table was inserted 
table.AbsoluteVerticalDistance = 50;
table.AbsoluteHorizontalDistance = 100;

doc.Save(ArtifactsDir + "Table.ChangeFloatingTableProperties.docx");