Benny
11-26-2002, 09:01 PM
Hey all,
I am writing a web app to do some processing to a Microsoft Word Mail Merge Document.
In order to do this processing I need to determine what the datafile is of the document. Currently I have these two functions:
def getDataFilename(file):
wd = win32com.client.Dispatch('Word.application')
wd.Documents.Open(file)
doc = wd.ActiveDocument
dataFile = doc.MailMerge.DataSource.Name
doc.Close()
wd.Quit()
return dataFile
def updateDataFilename(file, dataFile):
wd = win32com.client.Dispatch('Word.application')
wd.Documents.Open(file)
doc = wd.ActiveDocument
doc.MailMerge.OpenDataSource(dataFile)
doc.Close()
wd.Quit()
Now, this works if the mail merge document I test it with has been created on the machine that this script is run from.
This is no good, because the whole point of my web application is so people can upload mail merge documents (created on their home pc's) and then have them processed accordingly.
The process flow is as follows:
1. User uploads the mail merge document
2. The datafile is determined
3. User is prompted to upload the datafile - it tells them the location of the file.
4. The mail merge document stored on the server is updated to reflect the new datafile path.
5. The mail merge document is then processed
I've looked everywhere but been unable to find a foolproof way to determine the datafile of ANY Word Mail Merge document.
ANY advice/suggestions, anything would be greatly apprieciated. I'm at a real loss with this one.
Cheers
Ben.
I am writing a web app to do some processing to a Microsoft Word Mail Merge Document.
In order to do this processing I need to determine what the datafile is of the document. Currently I have these two functions:
def getDataFilename(file):
wd = win32com.client.Dispatch('Word.application')
wd.Documents.Open(file)
doc = wd.ActiveDocument
dataFile = doc.MailMerge.DataSource.Name
doc.Close()
wd.Quit()
return dataFile
def updateDataFilename(file, dataFile):
wd = win32com.client.Dispatch('Word.application')
wd.Documents.Open(file)
doc = wd.ActiveDocument
doc.MailMerge.OpenDataSource(dataFile)
doc.Close()
wd.Quit()
Now, this works if the mail merge document I test it with has been created on the machine that this script is run from.
This is no good, because the whole point of my web application is so people can upload mail merge documents (created on their home pc's) and then have them processed accordingly.
The process flow is as follows:
1. User uploads the mail merge document
2. The datafile is determined
3. User is prompted to upload the datafile - it tells them the location of the file.
4. The mail merge document stored on the server is updated to reflect the new datafile path.
5. The mail merge document is then processed
I've looked everywhere but been unable to find a foolproof way to determine the datafile of ANY Word Mail Merge document.
ANY advice/suggestions, anything would be greatly apprieciated. I'm at a real loss with this one.
Cheers
Ben.