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
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,
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,
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…
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,
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,
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.
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,
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,
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.
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,
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.