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

Free Support Forum - aspose.com

If statement in ASPOSE word does properly work with only one record or last record

Hello

I have a word document that is used as a document for doing mail merge via ASPOSE. This document contains if mail merge statement simlar to {IF {MERGERFIELD CCAMT5} > 0 "..."}.

The data source is a datatable.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />If the datatable only contain one record, the IF statement does not work. If the datatable contains more than one record, the IF statement works for every record except for the last record.

All the other mail merge field works in document.

We are using Aspose 6.5.

Any assistence will be helpful.

Thanks

Kevin

Hello

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

Thanks for your inquiry. Could you please provide me your document and simple code which will allow me to reproduce the problem on my side? Also, have you tried using the latest version of Aspose.Words (8.1.0)? You can download this version from here:

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

Best regards,

Andrey

Attached is the word document. The field is CCAMT5 in the document. The VB code is

Dim createDateTime As DateTime

Dim budgetYear As String

Dim _dt As New DataTable

Dim _courtSubsidy As New CourtSubsidy

createDateTime = Request.QueryString("CreateDateTime")

budgetYear = Request.QueryString("BudgetYear")

Dim windowTitle As String

Dim docPath As String = MapPath(".") & "\Letters\"

Dim doc As Document = New Document(MapPath(".") & "\Letters\CF_COURT_SUB_LT_DD_LTR.doc")

_dt = _courtSubsidy.generateCourtSubDDLetterData(_Conn, createDateTime)

_dt.TableName = "DD_Letters"

doc.MailMerge.RemoveEmptyParagraphs = True

doc.MailMerge.Execute(_dt)

doc.UpdateFields()

doc.MailMerge.DeleteFields()

windowTitle = "Budget Letters for " + budgetYear + " Created on " + createDateTime & " Out.doc"

doc.Save(windowTitle, SaveFormat.Doc, SaveType.OpenInBrowser, Response)

generateCourtSubDDLetterData is a simple sql code that reads a table. You should be able to create a simple data table that has only 2 records in the table. You only need to worry about CCAMT5 field. The last record will no show up in the mail merger.

As for going to 8.1, we had a major problem with exception about having filepath seperators in the file name. 8.1 did not like

Dim doc As Document = New Document(MapPath(".") & "\Letters\CF_COURT_SUB_LT_DD_LTR.doc")

At this point if there is a simple fix for the exception, then we could use it but there are several subrountines using the statements like the one above. Plus, the letter document can reside in different locations, depending on the machine.

We don't want to redo all those routines.

Thanks

Kevin

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

Thank you for additional information. But I cannot reproduce the problem on my side. I used the following simple code for testing:

DataTable dt = new DataTable();

dt.Columns.Add("CCAMT5");

for (int i = 1; i < 3; i++)

dt.Rows.Add(new object[] { i });

Document doc = new Document(@"Test001\in.doc");

doc.MailMerge.Execute(dt);

doc.Save(@"Test001\out.doc");

Could you please simplify your template and also attach your output document here?

Regarding file name, what exception is thrown? I think, you should just make sure that document exists in the specified folder.

Best regards,