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

Free Support Forum - aspose.com

Upgraded to new version. Tables are blown out and not "AutoFit to Contents"

I just upgraded Aspose.Words from version 3.6.1.0 to 6.5.0. All of my existing code still works fine except for one thing. I have a routine that will open an existing document, move to the end of the page, add a page break and then add a table. The problem that I am having is that the table I build ends up spanning the entire width of the page. Prior to the upgrade the table fit nicely in the middle of the page just as it would if I created it in Word and set AutoFit to Contents.

I tried the RowFormat.AllowAutoFit and this does not work. Is this a bug? If so, when will there be a hotfix for it? I upgraded my version yesterday because I have a time sensitive project that needs completion and I needed to be able to export these same documents to images.

Any help is appreciated. Thanks,
Paul

Hi

Thanks for your inquiry. Could you please provide sample code, which will allow me to reproduce the problem? Also, please attach your output document and desired output here. I will check the issue on my side and provide you more information.

Best regards.

Hi,
Here is the method that I am using to create the table. I’ve renamed some classes in this example. Attached is the output I am getting (CurrentOutput.doc) and the output that I am looking to get (DesiredOutput.doc). The part you should look at is on the second page of both documents. Essentially, if I open the document after using Aspose.Words to generate the table, manually select the table and, from the context menu, choose “AutoFit > AutoFit to Contents” then I get the desired result. Not sure what happened to this feature in your component. It seems like its not adhering to the default behavior of MS Word which I believe is “AutoFit to Contents”. Thanks for your help.
–Paul

private void AddMatrixTable(BizObject _ipo, Document doc)
{
    /*move to the end of the document, add a page break and output the table */
    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.MoveToDocumentEnd();
    builder.InsertBreak(BreakType.PageBreak);

    //add title
    Aspose.Words.Font f = builder.Font;
    f.Name = "Tahoma";
    f.Size = 12;
    f.Bold = true;
    f.Color = System.Drawing.Color.FromArgb(118, 146, 102);

    builder.Write("Projection Matrix Table");
    builder.InsertBreak(BreakType.LineBreak);
    f.Color = System.Drawing.Color.FromArgb(79, 98, 40);
    f.Size = 12;

    //insert a line break
    builder.InsertBreak(BreakType.LineBreak);
    builder.InsertBreak(BreakType.LineBreak);
    builder.InsertBreak(BreakType.LineBreak);

    f.Size = 8;
    builder.RowFormat.Alignment = RowAlignment.Center;
    builder.RowFormat.TopPadding = 5;
    builder.Write("Matrix X Axis Title Goes Here");

    //draw the table

    Table tbl = builder.StartTable();
    builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
    //builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Bottom;

    f.Size = 10;

    builder.InsertCell();
    builder.CellFormat.Borders.LineStyle = LineStyle.None;
    builder.Writeln("");

    //start with the range column headers
    builder.InsertCell();
    builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
    builder.Writeln("");

    builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
    builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
    builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
    f.Color = System.Drawing.Color.FromArgb(79, 98, 40);

    builder.InsertCell();
    builder.Writeln("-40%");

    builder.InsertCell();
    builder.Writeln("-30%");

    builder.InsertCell();
    builder.Writeln("-20%");

    builder.InsertCell();
    builder.Writeln("-10%");

    builder.InsertCell();
    builder.Writeln("0%");

    builder.InsertCell();
    builder.Writeln("10%");

    builder.InsertCell();
    builder.Writeln("20%");

    builder.InsertCell();
    builder.Writeln("30%");

    builder.InsertCell();
    builder.Writeln("40%");

    builder.EndRow();

    //now, write a row for each target
    bool yAxisWritten = false;

    for (int i = 0; i < _ipo.objs.Count; i++)
    {
        BizSubObject call = _ipo.objs[i].sub1;
        BizSubObject put = _ipo.objs[i].sub2;

        double numToBuy = put.Qty;
        double numToBuyMax = call.EqQty / call.Multiplier;
        double percentPutBuy = numToBuy / numToBuyMax;

        builder.InsertCell();
        if (!yAxisWritten)
        {
            builder.CellFormat.Orientation = TextOrientation.Upward;
            f.Size = 8;
            builder.Write("Matrix Y Axis Title Goes Here");
            builder.CellFormat.VerticalMerge = CellMerge.First;
            yAxisWritten = true;
        }
        else
        {
            builder.Writeln("");
            builder.CellFormat.VerticalMerge = CellMerge.Previous;
        }

        builder.CellFormat.Borders.LineStyle = LineStyle.None;
        builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
        builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White;
        builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
        f.Color = System.Drawing.Color.Black;

        //output cell containing the target
        f.Bold = true;
        f.Size = 10;

        builder.InsertCell();
        builder.CellFormat.Orientation = TextOrientation.Horizontal;
        builder.CellFormat.VerticalMerge = CellMerge.None;
        builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
        builder.Writeln(call.TargetPrice.ToString());

        f.Bold = false;
        if (i == _ipo.SelectedIndex)
        {
            builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
            builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
            builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
        }
        else
        {
            builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
            builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
            builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
            f.Color = System.Drawing.Color.FromArgb(79, 98, 40);
        }

        //output a cell for each value in the range
        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * -40d).ToString("N1") + "%");

        if (i == _ipo.SelectedIndex)
        {
            builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
            builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
            builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
        }
        else
        {
            builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
            builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White;
            builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
            f.Color = System.Drawing.Color.Black;
        }

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * -30d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * -20d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * -10d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * 0d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * 10d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * 20d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * 30d).ToString("N1") + "%");

        builder.InsertCell();
        builder.Writeln(((1d - percentPutBuy) * 40d).ToString("N1") + "%");

        builder.EndRow();
    }

    builder.EndTable();
}

Hi

Thank you for additional information. I linked your request to the appropriate issue. You will be notified as soon as it is resolved.

As a workaround, you can try specifying fixed width of each cell in your table.

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.
(102)