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

Free Support Forum - aspose.com

Aspose, long text and sections

AsposeTest.zip (304.2 KB)

attached is sample project.
note : I can’t get the sample project to actually merge fields. however, it works in my full application. haven’t figured out what the difference is yet.

In my application, I am merging fields on the document.
expected.doc is how I expect the output to look.
got.docx is how it is getting generated using Aspose.

the template file, as well as the fields and values are in the bin\debug directory
please help.

@conniem,

mismatched lengths (D) = 132 (F) = 117

But the following code shows the above message on the console:

string dataList = File.ReadAllText(@"D:\Temp\AsposeTest\values.txt");
string fieldList = File.ReadAllText(@"D:\Temp\AsposeTest\fields.txt");
string[] rowData = dataList.Split(new char[] { ControlChar.LineFeedChar});
string[] fList = fieldList.Split(new char[] { ControlChar.LineFeedChar });
if (rowData.Length != fList.Length)
{
    Console.WriteLine("mismatched lengths (D) = " + rowData.Length + " (F) = " + fList.Length);
    Console.ReadLine();
}

Please fix the following files and share them again here for further testing:

  • fields.txt
  • values.txt

that’s because you changed the split code.
the split is on #24

@conniem,

But when I run your code, it is not correctly splitting data and field values i.e. rowData and fList both arrays have 1 length. Your code produces the following output:

output: 18.4.zip (73.3 KB)

Fields in this output document are un-merged because dataList.Split((char)24) is not working as expected. Please debug your code and provide a correct separator character that splits the .txt files into correct sub-strings. Thanks for your cooperation.

debug.zip (2.0 KB)
it was the files.
sorry

@conniem,

Thanks for your inquiry. The problem does not seem to be occurring when you remove/comment the following line (see 18.4.zip (73.8 KB)):

AsposeDocument.MailMerge.TrimWhitespaces = false;

debug.zip (27.5 KB)
actually, I think the ‘total this invoice’ label, and the invoice total are supposed to be on the same line.,

so, I commented out that code, and ran it again, using the enclosed .dot file, and got the result.docx, which is still wonky.

@conniem,

This is not an issue in Aspose.Words for .NET. The problem occurs because of poor design of template document. If you run the following code, you will see that second Section has two TextColumns. MS Word layouts content of a TextColumn on the fly that is why it pushes the invoice total to the left side on the start of next page. You will see the difference if you remove first and last Sections from “result.docx” document (see 18.4.zip (7.3 KB)),

Document doc = new Document(MyDir + @"Debug\result.docx");

foreach(Section sec in doc.Sections)
{
    Console.WriteLine(sec.PageSetup.TextColumns.Count);
}

doc.FirstSection.Remove();
doc.LastSection.Remove();

doc.Save(MyDir + @"Debug\18.4.docx");

so it’s an end user thing (they designed the template).
but why does it work when I use the word based program, and not when I use the Aspose based program?
any ideas on that?

@conniem,

You mean that MS Word produces the correct output? Please share the complete steps that you used on your end to successfully get the desired output by using MS Word.

The delphi program calls this:
if ((UpperCase(fld.DisplayText) = ‘(MEMO)’)
or (UpperCase(fld.DisplayText) = ‘(BLOB)’)) then begin
FWordServer.Selection.Range.Text := ‘’;
FWordServer.Selection.TypeText(StripEnter(fld.AsString, false));
end
for memo fields.

that old program (written in delphi 2005 and using word dll calls) doesn’t use merge fields.
the new version that I’m recreating does.

@conniem,

As shared earlier, the problem is with the structure of template document. Open test.dot, go to the beginning of line “Total This Invoice”, keep pressing Enter key until the end of Page is reached. Pressing Enter one more time will break the structure. So, I am afraid, there is nothing in Aspose.Words to fix. If we can help you with anything else, please feel free to ask.