Hi
Thanks for your inquiry. Could you please provide me your input document, sample data source and code, which you use to set the data source? I will check the issue on my side and provide you more information.
Best regards.
Hi
Thanks for your inquiry. Could you please provide me your input document, sample data source and code, which you use to set the data source? I will check the issue on my side and provide you more information.
Best regards.
Hi alex,
sorry for the delay. I had to find out the circumstances on which the error occurs.
So I found these :
- setDataSource(filename) where filename is not the absolut path, but only the filename, because the csv is in same directory as the document.
- on Windows (doesnt matter which version) the flag “hide extension on known file types” is set to true
Source code:
String csvFileName = "test.csv";
File wordDocFile = new File("test.doc");
FileInputStream fis = new FileInputStream(wordDocFile);
Document asposeDoc = new Document(fis);
fis.close();
MailMergeSettings mmSettings = asposeDoc.getMailMergeSettings();
mmSettings.setDataSource(csvFileName);
mmSettings.setMainDocumentType(MailMergeMainDocumentType.FORM_LETTERS);
mmSettings.setDataType(MailMergeDataType.TEXT_FILE);
mmSettings.setLinkToQuery(true);
mmSettings.setViewMergedData(true);
mmSettings.setQuery(SELECT_FROM_STRING + mmSettings.getDataSource());
If the flag “hide extension on known file types” is set to false, then this code example is ok.
Kind regards and thank you for your support
Jens Böckel
Hi
Thanks you for additional information. It is odd to me that “hide extension on known file types” option affects the document. Have you tried to generate document with this option disabled and then enable this option before opening the document? Does it make any difference?
Anyways, please attach your test document and data source. Just to have the same inputs for test.
Best regards.
Hi Alexey,
thank you for your fast reply.
Yes we wonder why this flag infects the behaviour, too. It seems that when the flag is set to true, the setDataSource() uses the simple filename and adds the path of the document to it. If the document is opend with MS Word there is the error dialog that the file is not found, the path where word is searching is the path of the document in the moment we set the datasource.
As Attachment you’ll find a document and a csv.
Kind regards,
Jens Boeckel
Hi
Thank you for additional information. But I still cannot reproduce the problem with “Hide Extension on Known File Types”. I tested on Windows 7.
Also, I modified your code a bit:
String dataSource = "test.csv";
Document doc = new Document();
doc.getMailMergeSettings().setDataType(MailMergeDataType.TEXT_FILE);
doc.getMailMergeSettings().setMainDocumentType(MailMergeMainDocumentType.FORM_LETTERS);
doc.getMailMergeSettings().setDataSource(dataSource);
doc.getMailMergeSettings().setQuery(String.format("SELECT * FROM %s", dataSource));
Pattern whiteSpaceRegex = Pattern.compile("\\s+");
BufferedReader reader = new BufferedReader(new FileReader("C:\\Temp\\" + dataSource));
String firstLine = reader.readLine();
String[] fieldNames = firstLine.split(",");
for (int i = 0; i < fieldNames.length; i++)
{
OdsoFieldMapData mapData = new OdsoFieldMapData();
mapData = new OdsoFieldMapData();
mapData.setColumn(i);
mapData.setMappedName(fieldNames[i]);
mapData.setName(whiteSpaceRegex.matcher(fieldNames[i]).replaceAll("_"));
mapData.setType(OdsoFieldMappingType.COLUMN);
doc.getMailMergeSettings().getOdso().getFieldMapDatas().add(mapData);
}
doc.save("C:\\Temp\\out.doc");
Datasouce is txt file, which contains data in the following format:
Field1,Field2,Field3,Field4,
, , , ,
After running this code, you can insert mergefields using Mailings tab in MS Word.
Best regards,
Hi Alex,
did you try to copy the generated doc and the datasource csv to another directory and to open then the document?
That’s our problem: We generate the doc and csv file on a server and copy the two files to a client and then the document is opened with the error dialog. If we open the file on server everything is fine.
So I guess that in the case of the “Hide Extension on Known File Types” flag the absolute path is used as directory, not the relative path.
I’ll try your example tomorrow.
Thank you very much!
Kind regards,
Jens Böckel
Hi
Thanks for your inquiry. Yes, I did. I tried moving the generated document and CSV file into another folder and all works fine on my side.
Best regards.
we can reproduce it on several machines, documents. We are investigating further
there is another big issue: if the datasource file name contains empty spaces, the datasource settings of the word document get corrupt, so MS Word cant open the word file anymore.
Hi
Thank you for additional information. I cannot reproduce the problem with white spaces on my side. I used exactly the same code as I provided earlier with only one modification:
String dataSource = “data source.csv”;
Best regards,
The issues you have found earlier (filed as WORDSNET-2979) have been fixed in this .NET update and this Java update.