Free Support Forum - aspose.com

Merge Docs Exprted from Reporting Services

Hi,<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

I’m
having a problem merging two docx documents that have been exported from
Reporting Services. The reports are
simple form reports and are exported using Aspose.Words for Reporting Services
using the <DocumentLayout>Positioned</DocumentLayout>
configuration. The exported documents
are then merged so that the second document will start on an odd page. But the problem is that there isn’t a section
break being inserted between the two merged documents. It’s important that the second merged
document can be printed on an odd page.<o:p></o:p>

This
is the sample code I’m using to merge the documents.<o:p></o:p>

Document doc1 = new
Document(@“C:\temp\TestForm1.docx”);
Document doc2 = new
Document(@“C:\temp\TestForm2.docx”);

doc2.FirstSection.HeadersFooters.LinkToPrevious(false);
doc2.FirstSection.PageSetup.SectionStart
= SectionStart.OddPage;
doc2.FirstSection.PageSetup.PageStartingNumber
= 1;
doc2.FirstSection.PageSetup.RestartPageNumbering
= true;

Document doc = new
Document();
doc.RemoveAllChildren();

doc.AppendDocument(doc1, ImportFormatMode.KeepSourceFormatting);
doc.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);

doc.Save(@“C:\temp\MergedForm.docx”);

The test
report rdl, exported docx and merged docx files are attached.

Thanks Tim.

Hi Tim,

Thanks for your request. Actually a section break is there. You simply do not see it because it is under absolutely positioned textbox. You can open your output document using DocumentExplorer(Aspose.Words demo application) to make sure the section break is there.

Best regards,

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

I did some digging around in Word and apparently if there is an odd page section break and page numbering is reset then the section break will no longer start on an odd page. This was apparent when the document was printed or exported to as a xps file. The fix is to set mirror margins for multiple pages in the Page Setup dialog box.

So I added the below code after merging the documents and it's all working correctly now.

foreach (Section section in doc.Sections)

{

section.PageSetup.MirrorMargins = true;

}

Tim.

Hi Tim,

It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues, we are always glad to help you.

Best regards,