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

Free Support Forum - aspose.com

Numbered styling failure 1. Text 1.2 Text and 1.2.3 Text -> . Text .2 Text and .2.3 Text

Hello

We’re doing a mailmerge, via Word or Aspose.Words (currently r14.8.0.0), taking

1) source content "WILLS-D-WILL_1_8_635724813262667273_0_0.rtf"
2) merging data…
3) applying OSFT-* styles from “client-635724842230153847-340-1.dot” (i.e. update target for any customer required formatting)
4) Presenting for user review/save

Production via Word (automation) results in “word-right.rtf”; production via Aspose, with engine flags of (2+4+8+16) results in "aspose-wrong.rtf"

Can’t see any reason why aspose-wrong is losing the L1 formatting, and prefixing L2+ with a "."

Can you advise?

Regards
Pat (for CM)

Code is below on how the merge works. It wont run without the rest of our code but you can clearly see all the calls that are made to Aspose...

For those that can't see the attachments.

We have a list style L1, L2, L3 to do numbering like 1. Text, 1.2 Text 1.2.3
Text.

When rendered with Word automation, we get 1. Text, 1.2 Text and 1.2.3 Text as you would expect.

With Aspose, we get Text, .2 Text, 2.3 Text (i.e. the initial section 1 number is misisng!!)


Chris



public MemoryStream MailMergeToMemoryStream( MemoryStream mailMergeTemplate, DataTable dataTable,
CCmsDocumentType saveFormat, FileInfo styleTemplate )
{
MemoryStream ret = null;

try
{
if ( mailMergeTemplate != null && mailMergeTemplate.Length > 0 && dataTable != null )
{
CCmsUtils.AsposeWordsLicence();
SaveFormat saveFormatAspose = new CCmsUtils().GetAsposeWordsSaveFormat( saveFormat );

mailMergeTemplate.Position = 0;

Document doc = null;

LoadOptions loadOptions = new LoadOptions();
if ( m_BaseUri != null && m_BaseUri.Exists )
{
loadOptions.BaseUri = m_BaseUri.FullName;
}

if ( styleTemplate != null && styleTemplate.Exists )
{
Document template = new Document( styleTemplate.FullName, loadOptions );
Document body = new Document( mailMergeTemplate, loadOptions );


template.RemoveAllChildren();
template.AppendDocument( body, ImportFormatMode.UseDestinationStyles );

doc = template;
}
else
{
doc = new Document( mailMergeTemplate, loadOptions );
}

// no point merging with no fields, just apply the style instead.
if ( dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0 )
{
doc.MailMerge.CleanupOptions = GetCleanupOptionsFromMailMergeFlags();

if ( VerboseLoggingWordMergeFields )
{
doc.MailMerge.FieldMergingCallback = new CCmsMailMergeCallbackVerboseLogging();
WriteMergeDataToDisk( dataTable );
}
doc.MailMerge.Execute( dataTable );
}

// optionally take out the style/font stuff. This I believe should not ebe necissary as the idea
// of UseDestinationStyles below means, the source body, then pasted into the template document
// should use the styles in the destination (template). This deos not work. It leaves all actual
// text not converted, line breaks seem to be. the styles also look right in the manager.
// So, this corrects this and it might be due to the way RTF is stored and then read in. It looks
// expensive though!

if ( ( m_Flags & CCmsMailMergeFlags.CleanupRtfStyleManager ) > 0 )
{
foreach (Run r in doc.GetChildNodes(NodeType.Run, true))
r.Font.ClearFormatting();
}

ret = new MemoryStream();
doc.Save( ret, saveFormatAspose );

if ( mailMergeTemplate != null )
{
mailMergeTemplate.Close();
mailMergeTemplate = null;
}

if ( ret != null )
{
ret.Position = 0;
}
}
}
catch ( Exception e )
{
CLoggingMgr.AddLogFileEntry( Classname, "***error in MailMergeToMemoryStream(MemoryStream): " + e.ToString() );
ret = null;

throw new CCmsMailMergeNotCompletedException( "Aspose failed to mailmerge the document correctly", e );
}
finally
{
if ( mailMergeTemplate != null )
{
mailMergeTemplate.Close();
mailMergeTemplate = null;
}
}

return ret;
}

Hi Pat,


Thanks for your inquiry. Have you tried latest version of Aspose.Words i.e. 15.6.0 on your end? It would be great if you please create a standalone simplified runnable console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start further investigation into your issue and provide you more information. Thanks for your cooperation.

Best regards,