Hi Roman,
Thanks for being patient. Regarding WORDSNET-14860, our product team has completed the work on your issue and has come to a conclusion that this issue and the undesired behavior you are observing is actually not a bug in Aspose.Words for .NET. So, we will close this issue as ‘Not a Bug’. Please see the following details:
Roman:
I loop by styles of source document and copy them to destination document.
Result of case 1 : “Heading 1_0” didn’t occur. But style count of destination document increased.
It is expected behavior. Description of the ‘StyleCollection.AddCopy’ method has the following paragraph: ‘Linked style is copied.’ Styles with prefix ‘Heading’ (Heading [1…9]) in the source document contains linked styles with names ‘Überschrift [1…9] Zchn’ and these styles does not exist in the destination. So linked styles will be copied to destination and client can see that every iteration increasing count of styles.
Roman:
Result of case 2 : “Heading 1_0” occurred. And style count of destination document increased.
Current case excludes filter for styles (starts with ‘Heading’). The reason of the occurrence of styles like a ‘Heading 1_0’ is linked styles too. For example, style ‘Überschrift 9 Zchn’ is linked to style ‘Heading 9’, so it will be added as ‘Heading 9_0’.
You can update second example in the following way:
Document srcDoc = new Document(MyDir + @"1.dot");
Document doc = new Document(MyDir + @"2.doc");
foreach (Style style in srcDoc.Styles)
{
var savedStyleName = style.Name;
Console.WriteLine("-----BEFORE Style Count----->" + doc.Styles.Count);
foreach (Style style1 in doc.Styles)
{
if (style1.Name.StartsWith("Heading"))
Console.WriteLine(style1.Name);
}
Style newStyle = doc.Styles.AddCopy(style);
newStyle.Name = savedStyleName;
// Replace old style in the destination with a new linked style from the source.
if (!string.IsNullOrEmpty(newStyle.LinkedStyleName))
doc.Styles[newStyle.LinkedStyleName].Name = style.LinkedStyleName;
Console.WriteLine("-----AFTER Style Count----->" + doc.Styles.Count);
foreach (Style style1 in doc.Styles)
{
if (style1.Name.StartsWith("Heading"))
Console.WriteLine(style1.Name);
}
}
doc.Save(MyDir + @"17.5-case2.doc");
*Roman:
In MS Words currently we have 5 style types : paragraph, character, linked, table, list.
But Aspose just supports 4 : paragraph, character, table, list.
Could you explain me about it ?
We will provide way in Aspose.Words API to create Linked Styles. The ID of this feature is WORDSNET-11556. Your thread has also been linked to this issue and you will be notified as soon as it is supported. Sorry for any inconvenience.
Also, you can use ‘Style.LinkedStyleName’ property to determine a linked style. It can be used to get the name of the Style linked to this one. It returns empty string if no styles are linked.
Best regards,*