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

Free Support Forum - aspose.com

Styles preservation

Hi Support,

I'm facing an issue with styles. First up all, i'm merging two documents using Aspose and attaching a template document to apply the styles using WordAutomation. In this case, the Template style is not preserved properly. Also i want to know the functionality of Document.AttachedTemplate Property in Aspose.Words

When you have the srcDoc as First.doc and dstDoc as Second.doc, style is preserved properly. But if we do the reverse, srcDoc as Second.Doc and dstDoc as first.doc, the style are preserved incorrectly.

I have attached the sample to reproduce the issue and screenshot. Appreciate your quick response.

Regards,
Vijay

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

Document.AttachedTemplate property gets or sets the full path of the template attached to the document.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.document.attachedtemplate.html

Best regards.

Hi,

I have already posted the sample application to reproduce the issue, in my first post (Sample.zip).

Regards

Vijay

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce this problem on my side. I use the latest version of Aspose.Words for testing. You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Which version of Asopose.Words do you use for testing? To check version of the library, right click on the dll, select Properties from the context menu, then select Version tab. You will see File version.

Best regards.

Hi,

I'm using Aspose.Words (version: 8.0.0.0)

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please also attach your correct and incorrect output documents here? I will take a look whether your output is the same as output produced on my side.

Best regards.

Hi,

I have attached the documents for your reference. Eagerly waiting for your solution

Hi Guys,

Any update on this?

Regards,

Vijay

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. It seems the problem occurs because except style formation of the paragraph, also formatting of runs is set. You can try using the following code to resolve the problem:

// Open source docuemnts

Document dst = new Document(@"C:\Temp\1.doc");

Document src = new Document(@"C:\Temp\2.doc");

// Combine documents.

dst.AppendDocument(src, ImportFormatMode.UseDestinationStyles);

// Attach template.

dst.AttachedTemplate = @"C:\Temp\Template.dot";

// Reset formatign of runs inside heading paragraphs.

NodeCollection paragraphs = dst.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in paragraphs)

{

StyleIdentifier styleIdentifier = paragraph.ParagraphFormat.StyleIdentifier;

if(styleIdentifier == StyleIdentifier.Heading1 ||

styleIdentifier == StyleIdentifier.Heading2 ||

styleIdentifier == StyleIdentifier.Heading3 ||

styleIdentifier == StyleIdentifier.Heading4 ||

styleIdentifier == StyleIdentifier.Heading5)

{

// Clear font formaing of paragraph end.

paragraph.ParagraphBreakFont.ClearFormatting();

// Clear font formatign of runs inside paragraph

foreach (Run run in paragraph.Runs)

run.Font.ClearFormatting();

}

}

// Save output document.

dst.Save(@"C:\Temp\out.doc");

Hope this helps.

Best regards.

Hi Guys,

Thanks a lot, it works.