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

Free Support Forum - aspose.com

More than 64 MailMerge fields in a TextFile datasource

Dear Mams, dear Sirs,

I have an issue with textfile mailmerge datasources:

We have a html datasource-file containing fields and description of fields.

this file is set to an word template document with:

MailMergeSettings mmSettings = asposeDocument.getMailMergeSettings();
mmSettings.setDataSource(“DatasourceFile.csv”); mmSettings.setMainDocumentType(MailMergeMainDocumentType.FORM_LETTERS);
mmSettings.setDataType(MailMergeDataType.TEXT_FILE);
mmSettings.setLinkToQuery(true);
mmSettings.setViewMergedData(true);
mmSettings.setQuery(SELECT_FROM_STRING + mmSettings.getDataSource());

If there are more than 64 field-definition in this datasource-file, then the last fields are concatenated to one field in the mailmerge-field-list in MS Word and not longer regnonized in the document as mailmerge field.


Is that issue known? Is there any solution?

If we set the DataType to MailMergeDataType.SPREADSHEET the limitation is gone. But here we have the problem that MS Word opens automatically MS Excel showing the datasource file. But in our case the user should not get a glue about the datasourcefile

Kind regards,
________________________
Jens Boeckel
Abacus Research AG
Switzerland

Hello

Thanks for your inquiry. Could you please provide me your template and simple data which you use for generate the document? I will check the problem on my side and provide you more information.

Best regards,

Hi Andrey,

thanks for you quick reply! I attached an example to this reply


Kind regards!

------------------------------------
Jens Boeckel
Abacus Research AG
Switzerland

Hello

Thank you for additional information. But could you please also provide me the full code which will allow me to reproduce the problem on my side?

Best regards,

Hi Andrey,

here you’re:

import com.aspose.words.Document;
import com.aspose.words.MailMergeDataType;
import com.aspose.words.MailMergeMainDocumentType;
import com.aspose.words.MailMergeSettings;
import com.aspose.words.SaveFormat;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class TestWordAsposeFunctions {
private static final int BUFFER_SIZE = 8192;

private static final String SELECT_FROM_STRING = /NlsIgnore/“SELECT * FROM “;
private static final String NEW_LINE = /NlsIgnore/”\n”;
private static final String HTML_HTML_TAG_STRING = /NlsIgnore/"";
private static final String HTML_HTML_END_STRING = /NlsIgnore/"";
private static final String HTML_TABLE_TAG_STRING = /NlsIgnore/"";
private static final String HTML_TR_TAG_STRING = /NlsIgnore/"";
private static final String HTML_TD_TAG_STRING = /NlsIgnore/"";
private static final String HTML_TR_END_STRING = /NlsIgnore/"";
private static final String HTML_TABLE_END_STRING = /NlsIgnore/"
";
private static final String HTML_TD_END_STRING = /NlsIgnore/"
";

public static void main(final String[] args) {
try {
generateDataSourceFile(“testhtmldatasource100fields.html”, 100);
testMailMergeDataSourceWith100Fields();
}
catch (IOException e) {
throw new RuntimeException(e);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}

// @Before
// static public void setUp() throws IOException {
// generateDataSourceFile(“testhtmldatasource100fields.html”, 100);
// }
//
// @Test
static public void testMailMergeDataSourceWith100Fields() throws Exception {
Document asposeDocument = new Document();
MailMergeSettings mmSettings = asposeDocument.getMailMergeSettings();
mmSettings.setDataSource(“testhtmldatasource100fields.html”);
mmSettings.setMainDocumentType(MailMergeMainDocumentType.FORM_LETTERS);
mmSettings.setDataType(MailMergeDataType.TEXT_FILE);
mmSettings.setLinkToQuery(true);
mmSettings.setViewMergedData(true);
mmSettings.setQuery(SELECT_FROM_STRING + mmSettings.getDataSource());
File outFile = new File(“testOutput.doc”);
FileOutputStream fos = new FileOutputStream(outFile);
asposeDocument.save(fos, SaveFormat.DOC);
fos.flush();
fos.close();
}


static private void generateDataSourceFile(final String fileName, final int fieldCount) throws IOException {
StringBuilder builder = new StringBuilder( HTML_HTML_TAG_STRING );
builder.append(NEW_LINE);
builder.append(HTML_TABLE_TAG_STRING);
builder.append(NEW_LINE);
builder.append(HTML_TR_TAG_STRING);
builder.append(NEW_LINE);

for(int i=1; i<=fieldCount; i++) {
builder.append(HTML_TD_TAG_STRING);
builder.append(String.format(“fieldID%s”, i));
builder.append(HTML_TD_END_STRING);
builder.append(NEW_LINE);
}
builder.append(HTML_TR_END_STRING);
builder.append(NEW_LINE);
builder.append(HTML_TR_TAG_STRING);
builder.append(NEW_LINE);
for (int i=1; i<=fieldCount; i++) {
builder.append(HTML_TD_TAG_STRING);
builder.append(String.format(“fieldDisplayName%s”, i));
builder.append(HTML_TD_END_STRING);
builder.append(NEW_LINE);
}
builder.append(HTML_TR_END_STRING);
builder.append(NEW_LINE);
builder.append(HTML_TABLE_END_STRING);
builder.append(NEW_LINE);
builder.append(HTML_HTML_END_STRING);

FileOutputStream fos = new FileOutputStream(new File(fileName));
ByteArrayInputStream bais = new ByteArrayInputStream(builder.toString().getBytes());
copyStream(bais, fos);
bais.close();
fos.flush();
fos.close();
}

static private void copyStream(final InputStream inputStream,
final OutputStream outputStream) throws IOException {
byte[] buffer = new byte[BUFFER_SIZE];
int read = inputStream.read(buffer);
while(read != -1) {
if(read > 0 && outputStream != null)
outputStream.write(buffer, 0, read);
read = inputStream.read(buffer);
}
}

}


If you open the resulting document with MS Word you’ll find on the mailmerge function the list with the fields upto field62 and then field63field64field65…

Kind regards,

Jens Boeckel
----------------------------------
Abacus Research AG
Switzerland

Hello

Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java 10.6.0 and the code you attached. Please see the attached screenshot.

Best regards,

Hey Andrey,

thanks a lot for your very quick reply. Yes we’re using 10.5. I’ll download 10.6 and I’ll test again.

As attachment you’ll find an screenshot from office2010 and aspose.words 10.5


Kind regards,

Jens Boeckel
__________________
Abacus Research AG
Switzerland

Hello

Thank you for additional information. Could you please try using the latest version of Aspose.Words and let me know how it goes on your side.

Best regards,

Hi Andrey,

I’m sorry. I can still reproduce the problem with aspose 10.6 library. We can reproduce the error with office 2007 and office 2010. We havnt tested ofice older than 2007.

Regards,

Jens Boeckel
___________________
Abacus Research AG
Switzerland

Hello

Thank you for additional information. But I still cannot reproduce the problem on my side. I use MS Word 2007/2010 to open generated document. Could you please also attach your output document here for testing?

Best regards,

here you are!

Kind regards,

Jens Boeckel
-------------------------------
Abacus Research AG
Switzerland

Hello

Thank you for additional information. It seems it is MS Word restriction. If you try change the extension of your data source file to TXT and add this source using MS Word you will get exactly the same result. So it is expected behavior.

Best regards,

Hi Andrey,

how could you open the document without the problem? Could you send me your result outputfile?

thanks a lot!

Kind regards,

Jens Boeckel
_______________________
Abacus Research AG
Switzerland

Hello


Please see the attached document.

Best regards,

Hello,

thanks a lot! It looks like its really a word problem. If I used your attached document the limitation still exists.

What can I do that more than 63 fields are regnonized? What have you done to open the result without the limitation?


Thanks again!

Kind regards,
-------------------------------
Jens Boeckel
Abacus Research AG
Switzerland

Hi

Thanks for your inquiry. You should just use MailMergeDataType.SPREADSHEET instead of TEXT_FILE.

mmSettings.setDataType(MailMergeDataType.SPREADSHEET);

Also I’m afraid there is no way to avoid MS Word limitation.

Best regards,

Hello,

thanks again. SPREADSHEET is no solution fo our customizers:

- they would have to an installed excel, otherwise word cannot open the document
- word opens the datasource in excel automatically if it regnonize an SPREADSHEET datasource.

So it is a Microsoft Word Bug?

Cheers,
_____________________
Jens Boeckel
Abacus Research AG
Switzerland

Hi

As I mentioned earlier, in case of using MailMergeDataType.TEXT_FILE Aspose.Words process it in the same way as MS Word does, so it seems, yes, it is MS Word restriction.

Best regards,

Hi Andrey,

we’ve a solution for our problem:

We use a rtf document with comma separated entries as datasource. In rtf the encoding is set, so the encoding-dialog of word does not appear. And the limit of 63 is gone. :slight_smile:

Thanks again for your very good support!

Kind regards,
____________________
Jens Boeckel
Abacus Research AG
Switzerland

Hi

It is perfect, that you already found the solution. If you need more assistance, I will be glad to help you.

Best regards,