Hi
I use Aspose.Words for Java to make Microsoft Word document which has mailmerge fields like below.
How can I remove empty 2 lines as below on RESULT:Useslip.docx.
I don’t want to change the Word template because we have so many ones
in our system.
Please help us. Thanks.
-----------------------------------------------------------------------------------------
(Word template:Template.docx)
ADDRESS:{MERGEFIELD “Address”}
NAME:{MERGEFIELD “Name”}
DATE SHOP AMUONT
{MERGEFIELD “Date”} {MERGEFIELD “Store”} {MERGEFIELD “Amount”}
{NEXT *MERGEFORMAT}{MERGEFIELD “Date”} {MERGEFIELD “Store”}
{MERGEFIELD “Amount”}
{NEXT *MERGEFORMAT}{MERGEFIELD “Date”} {MERGEFIELD “Store”}
{MERGEFIELD “Amount”}
{NEXT *MERGEFORMAT}{MERGEFIELD “Date”} {MERGEFIELD “Store”}
{MERGEFIELD “Amount”}
{NEXT *MERGEFORMAT}{MERGEFIELD “Date”} {MERGEFIELD “Store”}
{MERGEFIELD “Amount”}
TOTAL:{MERGEFIELD “Total”}
-----------------------------------------------------------------------------------------
(DATASOURCE:DataSource)
Address,Name,Date,Store,Amount,Total
“OSAKA-CITY”,“YAMADA”,“2011/11/01”,“SHOPabc”,“58,000”,“855,800”
“OSAKA-CITY”,“YAMADA”,“2011/11/02”,“SHOPjkl”,“550,000”,“855,800”
“OSAKA-CITY”,“YAMADA”,“2011/11/01”,“SHOPxyz”,“247,800”,“855,800”
-----------------------------------------------------------------------------------------
(RESULT:Useslip.docx)
ADDRESS:OSAKA-CITY
NAME:YAMADA
DATE SHOP AMOUNT
2011/11/01 SHOPabc 58,000
2011/11/02 SHOPjkl 550,000
2011/11/01 SHOxyz 247,800
(don’t need this line)
(don’t need this line)
TOTAL:855,800
-----------------------------------------------------------------------------------------
(CODE)
Document doc = new Document(getMyDir() + "Template.docx");
DataTable table = new DataTable(DataSource);
doc.getMailMerge().setRemoveEmptyParagraphs(true);
doc.getMailMerge().execute(table);
doc.getMailMerge().deleteFields();
doc.save(getMyDir() + "Useslip.docx", SaveFormat.DOCX);