Microsoft Word displays 2 tables instead of one- for a .doc created with Aspose

Hello,

We’ve identified a weird issue when applying a custom style to a Word table for a .doc file. It seems Microsoft Word displays 2 tables instead of 1, in the .doc file created with Aspose.

I’ve attached a small console application describing the issue - running it it will generate 2 word files, one .doc and one .docx. Note that the .docx version appears to be correctly loaded in MS Word, only the .doc one has this problem.

We are using Aspose.Words version 14.5.0.0.

Any feedback will be highly appreciated.

Thank you in advance,
Mihai Andrei
Senior Software Engineer
IBM Romania

Hi Mihai,

Thanks for your inquiry.

I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10311. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Mihai,

Thanks for your patience. Regarding WORDSNET-10311, please set the custom style after table is fully created i.e all rows appended to table. Please check the highlighted code below. This will fix the issue which you are facing.

Please let us know if you have any more queries.

var document = new Document();
document.Sections.Clear();
// create the custom style
var normalTableStyle = document.Styles[StyleIdentifier.TableNormal];
var myStyle1 = document.Styles.AddCopy(normalTableStyle);
myStyle1.Name = MyStyle1Name;
myStyle1.BaseStyleName = normalTableStyle.Name;
// create a 2 x 3 table
var table = new Table(document);
bool styleWasSet = false;
for (int i = 0; i < 2; i++)
{
    var row = new Row(document);
    table.AppendChild(row);
    for (int j = 0; j < 3; j++)
    {
        var cell = new Cell(document);
        var paragraph = new Paragraph(document);
        var run = new Run(document)
        {
            Text = string.Format("Data.{0}.{1}", i, j)
        };
        paragraph.AppendChild(run);
        cell.AppendChild(paragraph);
        row.AppendChild(cell);
    }
}
if (!styleWasSet)
{
    // change table's style to use a custom one - THIS AREA is causing the issue
    var style = document.Styles[MyStyle1Name];
    table.Style = style;
    styleWasSet = true;
}
var section = new Section(document);
section.PageSetup.SectionStart = SectionStart.Continuous;
var sectionBody = new Body(document);
section.ChildNodes.Add(sectionBody);
sectionBody.ChildNodes.Clear();
section.Body.ChildNodes.Add(table);
document.ChildNodes.Add(section);
document.UpdatePageLayout();
document.Save("TestFile.doc", SaveFormat.Doc);
document.Save("TestFile.docx", SaveFormat.Docx);

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

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