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

Free Support Forum - aspose.com

Font incorrect after builder.EndTable()

We recently upgraded from aspose.Words V 14 to aspose.Words V 17.7.(We have an enterprise license - but I am having trouble submitting a ticket to paid support - working on that)

We have a complex report we generate as a word doc, we use probably 80% of aspose features. especially a lot of tables. Wen doing compatibility testing between 14 and 17 we ran into the following issue not seen in 14. I created the minimum code below that illustrates the problem.

After bldr.EndTable() font is “popped” back to white, instead of staying black.

bldr.StartTable();
bldr.SetFont(fontSize: 9, fontName: “Arial”, bold: false, fontColor: Color.White); // (1) font set white
bldr.InsertCell();
bldr.EndRow();
bldr.SetFont(bold: false, fontColor: Color.Black); // (2) font set black
bldr.EndTable();
//font back to white.

Obviously I can work around this - but it would be in a lot of places. Again - 14 has no such issues, only 17.7.

Thanks
Sean. (AJG001)

@srgarratt

Thanks for your inquiry. We will appreciate it if you please confirm exact version of your old API. It will help us to investigate the issue exactly. We have tested the scenario with 14.6 and 14.9, but unable to notice any difference in the results of old versions and 17.7.

Furthermore, in reference to paid support forum access, if you already have paid support subscription then your old user credentials will work for paid support forum. However if you still face any issue then please share the details, we will guide you accordingly.

minimal example code, and output logs - shows the difference between 14.1 and 17.7.
Note font color after EndTable(). In our actual program, color goes back to Color.White, not [Empty]

using System;
using System.Drawing;
using Aspose.Words;

namespace test_aspose_17
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("I am currently using {0}, version number {1}.", BuildVersionInfo.Product, BuildVersionInfo.Version);

            DocumentBuilder bldr = new DocumentBuilder();

            bldr.Font.Color = Color.Blue;
            Console.WriteLine("1) Font Color: " + bldr.Font.Color);

            bldr.StartTable();
            bldr.Font.Color = Color.White;
            Console.WriteLine("2) Font Color: " + bldr.Font.Color);
            bldr.InsertCell();
            bldr.EndRow();
            bldr.Font.Color = Color.Black;
            Console.WriteLine("3) Font Color: " + bldr.Font.Color);
            bldr.EndTable();
            Console.WriteLine("4) Font Color: " + bldr.Font.Color);
        }
    }
}

I am currently using Aspose.Words for .NET, version number 14.1.0.0.

  1. Font Color: Color [A=255, R=0, G=0, B=255]
  2. Font Color: Color [A=255, R=255, G=255, B=255]
  3. Font Color: Color [A=255, R=0, G=0, B=0]
  4. Font Color: Color [Empty]

I am currently using Aspose.Words for .NET, version number 17.7.

  1. Font Color: Color [A=255, R=0, G=0, B=255]
  2. Font Color: Color [A=255, R=255, G=255, B=255]
  3. Font Color: Color [A=255, R=0, G=0, B=0]
  4. Font Color: Color [A=255, R=255, G=255, B=255]

@srgarratt

Thanks for sharing additional information. We have noticed different results in 14.1 and 17.7, so we have logged a ticket WORDSNET-15676 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

@srgarratt

Thanks for your patience. Please note we have investigated the issue and found it is a valid behavior. We try to mimic MS Word behavior as closest as possible. The behavior was changed since a fix in 14.4. This fix changes “ParagraphBreakFont” of the current paragraph together with “Font” properties of the document builder. And it is how MS Word behaves when current paragraph is empty or current position is the end of the paragraph. However, to get old behavior, you can use following workaround. Move font formatting code into table after first cell insertion.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// We call this method to start building the table.
builder.StartTable();          
Console.WriteLine("1) Font Color after start table: " + builder.Font.Color);
builder.InsertCell();
// Move formatting to this place.
builder.Font.Size = 9;
builder.Font.Color = Color.Blue;
builder.Write("Row 1, Cell 1 Content.");
// Build the second cell
builder.InsertCell();
builder.Write("Row 1, Cell 2 Content.");
// Call the following method to end the row and start a new row.
builder.EndRow();
// Build the first cell of the second row.
builder.InsertCell();
builder.Write("Row 2, Cell 1 Content");
builder.Font.Color = Color.Red;
// Build the second cell.
builder.InsertCell();
builder.Write("Row 2, Cell 2 Content.");
builder.EndRow(); 
Console.WriteLine("2) Font Color before end table: " + builder.Font.Color);
// Signal that we have finished building the table.
builder.EndTable();
Console.WriteLine("3) Font Color after end table: " + builder.Font.Color);
builder.Writeln("Font Test");
// Save the document to disk.
doc.Save("outfile.docx");