Sections

We’ve run into our first problem since purchasing the ASPose product. When we pull up a mail merge with about 200 pages. The problem is everything comes up as 200 sections rather than 200 pages so we’re unable to print from say pages 10 through 20. How can we fix this? John

Hi John,

Thank you for considering Aspose.

I would ask you to elaborate your question. Are you combining 200 single documents each of which contain 1 page together and expect to get a 200 pages document but get a document with 200 sections instead? If so, you should probably try the thing I have just suggested to another customer:

https://forum.aspose.com/t/127638

Please take a look at the very last post and try to use that snippet of code. If however your issue differs from what I assume, please describe it more comprehensively.

I think that MS Word prints pages from 10 to 20 okay regardless of how many sections a document has. It just prints physical pages from 10 to 20.

This article might be relevant https://docs.aspose.com/words/net/mail-merge-and-reporting/

Also, it is possible to make your mail merge explicitly produce 1 section with all pages instead of 200 sections. To do this you need to create a mail merge region that encompasses content of the whole document and run MailMerge.ExecuteWithRegions. In this case the mail merge engine will duplicate only content of the region, not the whole section of the document.

Each time we still seem to get sections rather than pages. The template documents that we use are standard Word with just the MailMerge fields added. None are over one page presently and on File | Page Setup | Layout | Sections is set to New Page which is the default for Word 2003.

Below is a copy of the code we’re using. What we want is pages rather than sections so that we can do a print range rather than making the user select the text and choose print selected. We’d like to just print pages say 10-20;25;30 and get just those pages as you would using regular word.

Dim doc As Aspose.Word.Document = New Aspose.Word.Document(sFilename)
Dim rdrPledgeLetters As SqlClient.SqlDataReader

doc.MailMerge.RemoveEmptyParagraphs = True
doc.MailMerge.UseNonMergeFields = True

OpenDatabase()
Me.sqlLetters.CommandText = "EXEC pspDonorEntryLetterExport '" & GetNameFromPathAndName(sFilename).Replace(".doc", "") & "’, ‘Receipt’"
‘Me.sqlLetters.CommandText = "SELECT CustomerNumber, FullName, FirstName, LastName, Address1, Address2, Address3, City, State, Zip, Country, Phone, Fax, Comment1, Comment2, UserDefined1, UserDefined2, DateCreated, DateModified, PledgeNumber, CheckNumber, GiftDate, GiftAmount, Motivation, Designation, CurrentDate, ExportFilename FROM tblDonorEntryLetterExport WHERE (ExportFilename = '" & GetNameFromPathAndName(sFilename) & "’)"
Me.sqlLetters.Connection = Me.connLetters
Debug.Write(Me.sqlLetters.CommandText)
rdrPledgeLetters = sqlLetters.ExecuteReader
doc.MailMerge.Execute(rdrPledgeLetters)
doc.Save(sExportFilename, Aspose.Word.SaveFormat.FormatDocument)
connLetters.Close()
doc = Nothing

Thanks for the code, could you also attach a template to allow us take a look?

Here’s a small template that if we print 100 records to it prints 100 sections rather than 100 pages. John

First, I grossly don’t understand why 100 sections prevent you from printing selected pages 1-20,25,30 and so on. I can do that in MS Word perfectly fine, it does not matter how many sections are in the document. I have a 100 sections document with total 100 pages, I go to File/Print and enter 10-20,25,35 and it prints only those pages.

If you still don’t want 100 sections, then see this modified template. I enclosed the text of the document into a mail merge region (TableStart and TableEnd fields), you only need to change the name of the table to match yours and use one of the MailMerge.ExecuteWithRegions methods to do the mail merge. In this case only the content between TableStart and TableEnd will be repeated and you will have only one section. I also marked the first paragraph in the document to be Page Break Before so it starts on a new page.