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

Free Support Forum - aspose.com

Foating table / text wrapping

Hi,

I try to make a table next to a paragraph like in “FloatingTableCreatedWanted.doc” but i have not found any content in website to help me to do this and actually i just can do the document “FloatingTableCreated.doc”.

Is there anyway to create a document like “FloatingTableCreatedWanted.doc” ?
See attachment for codes & examples.

Thank you.


Hi,

Unfortunately, floating tables are not supported as for yet. However, you can substitute table positioning by placing a table in a textbox, something like this:

Dim doc As Document = New Document()

Dim textbox As Shape = New Shape(doc, ShapeType.TextBox)

Dim table As Table = New Table(doc)

Dim row As Row = New Row(doc)

Dim cell As Cell = New Cell(doc)

cell.CellFormat.Width = 100

Dim para As Paragraph = New Paragraph(doc)

para.AppendChild(New Run(doc, "Cell 1.1"))

cell.AppendChild(para)

row.AppendChild(cell)

cell = New Cell(doc)

cell.CellFormat.Width = 100

para = New Paragraph(doc)

para.AppendChild(New Run(doc, "Cell 1.2"))

cell.AppendChild(para)

row.AppendChild(cell)

table.AppendChild(row)

textbox.AppendChild(table)

textbox.Left = 300

textbox.Top = 200

textbox.Width = 220

textbox.Height = 50

textbox.Stroked = False

doc.FirstSection.Body.FirstParagraph.AppendChild(textbox)

Another option is loading a precreated template containing a floating table. Aspose.Words does preserve any formatting even if it does not expose particular formatting properties.

Thank you

Hi,

I have a new question about this topic. I try to apply border style and i get an error.

'won’t work between <New lines & </New lines -> “Object reference not set to an instance of an object.”
Dim doc As Document = New Document()
Dim textbox As Shape = New Shape(doc, ShapeType.TextBox)
Dim table As Table = New Table(doc)
Dim row As Row = New Row(doc)
Dim cell As Cell = New Cell(doc)
cell.CellFormat.Width = 100
'<New lines
cell.CellFormat.Borders(BorderType.Left).LineStyle = LineStyle.Thick
cell.CellFormat.Borders(BorderType.Right).LineStyle = LineStyle.Thick
cell.CellFormat.Borders(BorderType.Top).LineStyle = LineStyle.Thick
cell.CellFormat.Borders(BorderType.Bottom).LineStyle = LineStyle.Thick
cell.CellFormat.Borders.Color = System.Drawing.Color.FromArgb(0, 212, 212, 212)
'</New lines
Dim para As Paragraph = New Paragraph(doc)
para.AppendChild(New Run(doc, “Cell 1.1”))
cell.AppendChild(para)
row.AppendChild(cell)
cell = New Cell(doc)
cell.CellFormat.Width = 100
para = New Paragraph(doc)
para.AppendChild(New Run(doc, “Cell 1.2”))
cell.AppendChild(para)
row.AppendChild(cell)
table.AppendChild(row)
textbox.AppendChild(table)
textbox.Left = 300
textbox.Top = 200
textbox.Width = 220
textbox.Height = 50
textbox.Stroked = False
doc.FirstSection.Body.FirstParagraph.AppendChild(textbox)

Code is in attachment file too
How Can i apply border style to my table in a shape ?
Thank you

The problem is that table borders can be set on table, row or cell level. Cell borders inherit row and table borders. When the cell borders properties are set the inherited border settings also need to be checked. In your case you are trying to set the cell borders before cell is appended to the row and setting the borders of the orphaned cell cause exception. To work around append cell to row and row to table first and only then appy the border settings.

As you can see the current behavior is not really a bug, but still I think we should fix it to avoid the situations like this. I have logged this to our defect base as issue #1348. We will try to fix it in the next release.

Please also consider using DocumentBuilder to construct the table. You may find that it is much more convenient to use builder for the task like this. There are plenty of examples in the documentation how to work with the DocumentBuilder. Please check them too.

Best regards,

The problem is fixed in our production code. The version with this fix will be released in a few days. Please follow the announcements on our team blog: http://www.aspose.com/Community/blogs/aspose.words/default.aspx

Best regards,

I understand. Thanks for your reactivity.

We have releases version 4.0.2 of Aspose.Words. The problem is fixed there. Please try your application with the new version.

Best regards,