| View previous topic :: View next topic |
| Author |
Message |
dynamisg Newbie

Joined: 22 Dec 2006 Posts: 3
|
Posted: Sat Feb 10, 2007 4:06 pm Post subject: Visual Foxpro Example of How to use Cut and paste |
|
|
For all those who use Visual Foxpro to create documents in OOwriter here is an example of how to cut and paste text from a document. My starting document Testopen .odt has a header that I want to repeat a couple pages down. I wrote this code to copy and paste data from one part of the document to another.
(this only caveat is I do not show how to cut text from the middle of the doc.)
| Code: | VfpOOoWritExample()
PROCEDURE VfpOOoWritExample()
* Create a letter.
LOCAL oDoc
LOCAL oTxt
LOCAL oRng
LOCAL oCursor
LOCAL oSourceframe
LOCAL oDisp
* Test for inserting a file
LOCAL ARRAY argsinsert[1]
LOCAL ARRAY NoArg[1]
LOCAL ARRAY DownArg[2]
LOCAL SrcFile
LOCAL cInsertfilename
#DEFINE CR CHR(13)
#DEFINE wdTAB CHR(9)
** API CONTROL CHARACTERS FOR insertControlCharacter
#define PARAGRAPH_BREAK 0
#define LINE_BREAK 1
#DEFINE HARD_HYPHEN 2
#DEFINE SOFT_HYPHEN 3
#DEFINE HARD_SPACE 4
#DEFINE APPEND_PARAGRAPH 5
* oDoc = OOoOpenURL( "private:factory/swrite" )
*--------------------------------------------------------
* OOoOpenURL comes from the example code in
* OpenOffice.org Macros and API
* Changing TabStops in a write document from Visual FoxPro
*--------------------------------------------------------
* To Open a file pass in the the following
oDoc = OOoOpenURL( "file:///c:/exam/testopen.odt" )
************************************************
***------ Add text to file ------------
************************************************
oTxt = oDoc.getText
oCursor = oTxt.createTextCursor()
************************************************************************
* this is an example of cut and paste. First we will attempt to copy
* a text area to the clipboard. Later will will paste it.
************************************************************************
octl = oDoc.getCurrentController()
oSourceframe = octl.getFrame()
**** REM create the DispatcherService --> This is the Basic version
**** oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
*--------------------------------------------------------
* OOoServiceManager_CreateInstance comes from the example code in
* code in OpenOffice.org Macros and API
* Changing TabStops in a write document from Visual FoxPro
*--------------------------------------------------------
oDisp = OOoServiceManager_CreateInstance( "com.sun.star.frame.DispatchHelper" )
oCursor.gotoEnd( .T. )
*--------------------------------------------------------
* OOoMakePropertyValue comes from the example code in
* code in OpenOffice.org Macros and API
* Changing TabStops in a write document from Visual FoxPro
*--------------------------------------------------------
NoArg[1] = OOoMakePropertyValue( "EMPTY" , ".f." )
**** First we need to select the data to be copied .
oDisp.executeDispatch(octl, ".uno:SelectAll", "", 0, @ NoArg)
**** REM copy the current selection to the clipboard.
oDisp.executeDispatch(octl, ".uno:Copy", "", 0, @ NoArg)
DownArg[1] = OOoMakePropertyValue( "Count" , 1 )
DownArg[2] = OOoMakePropertyValue( "Select" , ".f." )
oDisp.executeDispatch(octl, ".uno:GoDown", "", 0, @ DownArg)
************************************************************************
* Copy to ClipBoard complete
************************************************************************
oCursor.gotoEnd( .F. )
oTxt.insertString( oCursor, "This is line number 1.", .F. )
oTxt.insertControlCharacter( oCursor, PARAGRAPH_BREAK, .F. )
* ' Insert text into 2nd paragraph. Change paragraph style.
oTxt.insertString( oCursor, "This is line number 2 (in style Heading 2)", .F. )
oCursor.ParaStyleName = "Heading 2"
* ' Insert paragraph break. There are now three paragraphs, the 3rd one is empty.
oTxt.insertControlCharacter( oCursor, PARAGRAPH_BREAK, .F. )
oTxt.insertString( oCursor, "This is line number 3.", .F. )
* ' Insert paragraph break.
oTxt.insertControlCharacter( oCursor, PARAGRAPH_BREAK, .F. )
* ' Move the cursor to the start of the document.
* oCursor.gotoStart( .F. )
* ' Insert text into beginning of 1st paragraph.
oTxt.insertString( oCursor, "This line appears at the beginning of the document.", .F. )
oTxt.insertControlCharacter( oCursor, PARAGRAPH_BREAK, .F. )
oCursor.gotoEnd( .F. )
oRng = oTxt.GetEnd()
oStrt = oTxt.GetEnd()
ctxtstring = "This Word Document will be used to test the interface to OPEN OFFICE FROM FOXPRO"+CR
oTxt.insertString( oCursor, ctxtstring , .F. )
=oboldtext(ctxtstring,1, 4, oTxt)
ctxtstring = "THIS IS A TEST TO SEE IF I CAN WRITE TEXT INTO A FILE "+CR
oTxt.insertString( oCursor, ctxtstring , .F. )
=oboldtext(ctxtstring,4, 6, oTxt)
ctxtstring = "This is the last sentence in the doc"+CR
= oboldtext(ctxtstring,4, 6, oTxt)
***********************************************************************
* Here is where we attempt to paste the area we copied from Above
***********************************************************************
oCursor.gotoEnd( .F. )
oCursor.BreakType = 4
oDisp.executeDispatch(oSourceframe, ".uno:Paste", "", 0, @ NoArg)
***********************************************************************
* Paste complete
***********************************************************************
ctxtstring = "A file Will be inserted here "+CR
oTxt.insertString( oCursor, ctxtstring , .F. )
oCursor.gotoEnd( .F. )
oCursor.BreakType = 4
argsinsert[1] = OOoMakePropertyValue( "EMPTY" , ".f." )
cInsertfilename = "c:\exam\NEXTFORM.odt"
SrcFile = OOoConvertToURL(cInsertfilename)
oCursor.insertDocumentFromUrl(SrcFile , @ argsinsert) |
Here are some of the functions I used to bold text.
| Code: | FUNCTION oboldtext(cbText, nstartloc, nendloc, oBTxt)
local cIndex
local oBRange
local oCursor
oCursor = oBTxt.createTextCursor()
oCursor.gotoEnd( .F. )
oBTxt.insertString( oCursor, cbText , .F. )
oCursor.gotoPreviousSentence( .f.)
oCursor.gotoStartOfSentence(.f.)
if nstartloc > 1
for cIndex = 1 to (nstartloc - 1)
oCursor.gotoNextWord( .F.)
endfor
endif
for cIndex = nstartloc to nendloc
oCursor.gotoNextWord( .T.)
endfor
oCursor.CharWeight = 150
oCursor.gotoNextWord( .F.)
oCursor.collapseToStart()
oCursor.CharWeight = 100
oCursor.gotoEnd( .F. )
return |
Here is a function i use to write text
| Code: | function oOOwritetext(cwtext, oTxt)
oRange = oTxt.GetEnd()
oRange.setString(cwtext)
return | [/code] |
|
| Back to top |
|
 |
luisesteban Newbie

Joined: 22 Jul 2006 Posts: 4
|
Posted: Sun May 06, 2007 3:30 pm Post subject: |
|
|
Very cool man
VFP and OO works very fine!!!!
You know the functions necesaries to make invisibles the borders of the table objects?
Tnx again!!! |
|
| Back to top |
|
 |
steffenD Newbie

Joined: 03 Aug 2007 Posts: 4
|
Posted: Fri Aug 03, 2007 7:33 am Post subject: Re: Visual Foxpro Example of How to use Cut and paste |
|
|
| dynamisg wrote: |
.....
argsinsert[1] = OOoMakePropertyValue( "EMPTY" , ".f." )
cInsertfilename = "c:\exam\NEXTFORM.odt"
SrcFile = OOoConvertToURL(cInsertfilename)
oCursor.insertDocumentFromUrl(SrcFile , @ argsinsert)[/code]
.....
[/code][/code] |
Hi,
it works fine!. Only the File insert comes with a Error. The arginsert-Array ist not ok!
Have you a tip?
Thanks!
Steffen |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|