Table column always set to "Fixed Width" mode? AllowAutoFit not working?

Hi,

I just upgraded to Aspose.Words 6.0.1.0 from an older version and it seems that my table column is set to “Fixed width = 1 inch” even though no CellFormat.Width is specified for the first column…

How can I leave MS Word to autofit the first column based on its content with the new version?

I tried setting RowFormat.AllowAutoFit = true, but that did not change anything.

Here’s the code I use :

Aspose.Words.Tables.Table table;
table = builder.StartTable();

builder.RowFormat.AllowAutoFit = true; // test…
builder.RowFormat.LeftIndent = Aspose.Words.ConvertUtil.InchToPoint(0.33);

builder.InsertCell(); // skip first header cell

builder.InsertCell();
builder.Write("Date");

builder.InsertCell();
builder.Write("Montant payé");

builder.EndRow();

for ( … )
{
    builder.InsertCell();
    builder.Write( … );

    builder.InsertCell();
    builder.Write( … );

    builder.InsertCell();
    builder.Write( … );

    builder.EndRow();
}

foreach (Aspose.Words.Tables.Row row in table.Rows)
{
    row.Cells[1].CellFormat.Width = Aspose.Words.ConvertUtil.InchToPoint(0.93);
    row.Cells[2].CellFormat.Width = Aspose.Words.ConvertUtil.InchToPoint(0.84);
}

builder.EndTable();

Thanks for your help,

dstj.

Hi
Thanks for your request. Please try using the following code:

foreach (Aspose.Words.Tables.Row row in table.Rows)
{
    row.Cells[0].CellFormat.Width = 0;
    row.Cells[1].CellFormat.Width = Aspose.Words.ConvertUtil.InchToPoint(0.93);
    row.Cells[2].CellFormat.Width = Aspose.Words.ConvertUtil.InchToPoint(0.84);
}

Hope this helps.
Best regards.

Thanks for the reply, but that does not seem to fix the problem.

Here’s a sample code that reproduces the problematic output. I also did notice a situation where a real 0 width column is produced. Just uncomment the marked lines to see that too…

Thanks for your help,

dstj.

------------------

Aspose.Words.Document wordDocument = new Aspose.Words.Document();
wordDocument.RemoveAllChildren();

Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(wordDocument);

Aspose.Words.Tables.Table table;
table = builder.StartTable();
builder.RowFormat.AllowAutoFit = true;

/* // Uncomment this to create 0 width column
builder.RowFormat.ClearFormatting();
builder.RowFormat.AllowAutoFit = false;
*/

builder.InsertCell(); // skip first cell of first column
builder.InsertCell();
builder.Write("Col2");
builder.EndRow();

Random rand = new Random();
for (int i = 0; i < 5; ++i)
{
    builder.InsertCell();
    builder.Write("THIS IS A LONG SAMPLE TEXT STRING…".Substring(0, rand.Next(36)));

    builder.InsertCell();
    builder.Write("Fixed02");

    builder.EndRow();
}

foreach (Aspose.Words.Tables.Row row in table.Rows)
{
    row.Cells[0].CellFormat.Width = 0; // as suggested
    row.Cells[1].CellFormat.Width = Aspose.Words.ConvertUtil.InchToPoint(0.93);
}

builder.EndTable();

wordDocument.Save("c:\temp\asposeWords01.doc");

Hi
Thanks for your request. The behavior is correct; it is like MS Word does. If you try to insert a long word into the cell then cell width will be expanded. For example try the following:

builder.Write("THIS_IS_A_LONG_SAMPLE_TEXT_STRING...".Substring(0, rand.Next(36)));

Best regards.

Forgive me for insisting, but I want the cell to “AutoFit to Contents”, not just based on a long word. In attachment, you’ll find the result from the previous code and the desired result.

I’d like to get the same result as when I right-click on the first column and select “Autofit to Contents” (in Word 2003)

Thanks a lot,

dstj.

Hi
Thank you for additional information. Unfortunately, there is no way to auto-fit cell to content. You can try to calculate width of cell and set in before inserting text.
Best regards.

Thanks for the information, but it worked as expected in Aspose.Words 4.4.3.0. I did not have to set anything for the first column width and it was “Autofit to Contents”

Hi
Thank you for additional information and sorry for inconvenience. Now I can see the problem. I logged this in our defect database as issue #7349. I will notify you as soon as it is fixed.
Best regards.

Hi,

The problem is still present in version 7.0.0.0. Can you provide any update on this issue?

Thanks.

dstj.

Hi

Thanks for your request. Unfortunately, the issue still unresolved. Currently I cannot provide you any reliable estimate regarding this issue.
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.
(66)