 | OO-Snippets: Mail MergeCommons| Keywords | mail merge |
|---|
| Language | ooRexx |
|---|
| Application | Writer |
|---|
| Authors | Matthias Prem (initial)
|
|---|
| Supported Versions | 2.0.x |
|---|
| Supported OS | All |
|---|
| Question | How can I perform a mail merge?
Assuming, you have two files: addresses.ods (with the contacts) and
letter.odt (with the letter).
|
|---|
| Answer | |
|---|
oDesktop = UNO.createDesktop()
xComponentLoader = oDesktop~XDesktop~XComponentLoader
url = "file:///c:/addresses.ods"
xCalcComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)
xSheet=xCalcComponent~XSpreadSheetDocument~getSheets~XIndexAccess~getByIndex(0)~XSpreadSheet
url= "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)
xText=xWriterComponent~XTextDocument~getText()
line = 0
do while xSheet~getCellByPosition(0,line)~getFormula() <> ""
surname = xSheet~getCellByPosition(0,line)~getFormula()
familyname = xSheet~getCellByPosition(1,line)~getFormula()
address = xSheet~getCellByPosition(2,line)~getFormula()
zip = xSheet~getCellByPosition(3,line)~getFormula()
city = xSheet~getCellByPosition(4,line)~getFormula()
xText~getEnd~setString(surname %% " " %% familyname)
call newline 1
xText~getEnd~setString(address)
call newline 1
xText~getEnd~setString(zip %% " " %% city)
call newline 5
xText~getEnd~setString("Dear " %% surname %%"!")
call newline 2
xTextCursor = xText~getText~createTextCursor
insertprops = bsf.createArray(.UNO~propertyValue, 0)
xTextCursor~gotoEnd(.false)
xTextCursor~XDocumentInsertable~insertDocumentFromURL("file:///C:/letter.odt", insertprops)
xCursorProps=xTextCursor~XPropertySet
xCursorProps~setPropertyValue("BreakType", bsf.getConstant("com.sun.star.style.BreakType", "PAGE_AFTER"))
call newline 1
line= line + 1
end
EXIT 0
newline:
use arg count
do count
xText~getEnd~setString("13" ~d2c)
end
return
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2006-07-10 | matthiasprem | Initial version |
|