Different behavior on AutoFit

Hi, about RowFormat.AllowAutoFit I’ve made some test and there are different results with documenti builder and native method.
This 2 snippet make the same thing, but only the native method produce an effective AutoFit.
Native Method:

Dim doc As New Document()
Dim tb As New Table(doc)
Dim c As Cell
Dim rw As Row

'First row
rw = New Row(doc)
rw.RowFormat.AllowAutoFit = True
c = New Cell(doc)
c.AppendChild(New Paragraph(doc))
c.FirstParagraph.AppendChild(New Run(doc))
rw.Cells.Add(c)
c = New Cell(doc)
c.AppendChild(New Paragraph(doc))
c.FirstParagraph.AppendChild(New Run(doc, "Long text in the second cell"))
rw.Cells.Add(c)
tb.Rows.Add(rw)

'Second row
rw = New Row(doc)
c = New Cell(doc)
c.AppendChild(New Paragraph(doc))
c.FirstParagraph.AppendChild(New Run(doc, "Native"))
rw.Cells.Add(c)
c = New Cell(doc)
c.AppendChild(New Paragraph(doc))
c.FirstParagraph.AppendChild(New Run(doc))
rw.Cells.Add(c)
tb.Rows.Add(rw)

doc.FirstSection.Body.Tables.Add(tb)
doc.Save("D:\nativedemo.docx", SaveFormat.Docx)


Document builder method
Dim doc As New Document()
Dim db As New DocumentBuilder(doc)
db.StartTable()
db.RowFormat.AllowAutoFit = True

'Firs Row
db.InsertCell()
db.Write("")
db.InsertCell()
db.Write("Long text in the second cell")
db.EndRow()

'Second Row
db.InsertCell()
db.Write("Doc builder")
db.Write("")
db.EndRow()
db.EndTable()
doc.Save("D:\demodocbuild.docx", SaveFormat.Docx)

Where am I wrong in document builder demo ?

Hi

Thanks for your request. First of all you missed one cell in DocumentBuilder demo code:

Dim doc As New Document()
Dim db As New DocumentBuilder(doc)
db.StartTable()
db.RowFormat.AllowAutoFit = True

'Firs Row
db.InsertCell()
db.Write("")
db.InsertCell()
db.Write("Long text in the second cell")
db.EndRow()

'Second Row
db.InsertCell()
db.Write("Doc builder")
db.InsertCell()
db.Write("")
db.EndRow()
db.EndTable()
doc.Save("C:\Temp\out.docx")

When you insert cells using DocumentBuilder, default width of cells is set (72 pt), that is why auto-fit option has no effect.
Best regards.

Hi Alexey,
How can I enable AllowAutoFit options to work with document builder ? If I set a width for every cell, autofix is ignored.

Hi

Thanks for your inquiry. Unfortunately, I cannot suggest you a way to make this to work using DocumentBuilder. I linked your request to the appropriate issue. You will be notified as soon as this problem is resolved.
Best regards.

The issues you have found earlier (filed as WORDSNET-2044) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(78)