Printing to a word document

This forum is for eXpress++ general support.
Post Reply
Message
Author
omni
Posts: 554
Joined: Thu Jan 28, 2010 9:34 am

Printing to a word document

#1 Post by omni »

Roger,

We have a user that wants to modify invoices for some customers on demand in word. He wants to print an invoice to something that can be saved as a .doc file, or either we can print to something where he can copy and paste to an empty work document. We cannot find a conversion tool that does this on a print job, and the print/preview does not have a method to copy and paste.

Do we have something that does that, or any suggestions?

Thanks

Fred
Omni

User avatar
Auge_Ohr
Posts: 1428
Joined: Wed Feb 24, 2010 3:44 pm

Re: Printing to a word document

#2 Post by Auge_Ohr »

omni wrote:Do we have something that does that, or any suggestions?
you can use activeX to create a Word Document.

copy / paste from Preview is not possible while Grafic ... not Text
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Printing to a word document

#3 Post by rdonnay »

I can't think of any easy solution for you.
The eXpress train is coming - and it has more cars.

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Printing to a word document

#4 Post by skiman »

Hi,

I'm doing the following in some situations.
- Create a RTF file with the layout you want.
- Use memoread to read this.
- Use some kind of tags as <[ alltrim(customer->name)]> in the header and replace them.
- Use a <[start]> and <[stop]> for the body. Define one line in your RTF.
- Read the 'body' a use a loop to fill the body. In the body use tags as <[ str(invoice->quantity,8,2)]> and so on.
- In the footer you can use <[ str(totalinvoice,9,2) ]> and so on.
- Save it with the DOC extension.
- You have your Word document.

I use the same technique with HTML templates which were saved as XLS.

Printing to RTF and saving this with DOC extension will also work.
Best regards,

Chris.
www.aboservice.be

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Printing to a word document

#5 Post by c-tec »

Hello,
a littel sample with using bookmarks in the Word document
regards
Rudolf

Code: Select all



//////////////////////////////////////////////////////////////////////
// Open a MS Word document and replace the bookmarks with the values
// passed in the array aData. The resulting document is then saved
// back to the hard drive.
//////////////////////////////////////////////////////////////////////
static FUNCTION WordFillDocument(cFile,aData,cSaveAs,nBearb)
  LOCAL oWord,oBM,oDoc,lWordFinished := .f.,x
  default nBearb to 0
  // Create a Word ActiveX component
  oWord := CreateObject("Word.Application")
  IF Empty( oWord )
    MsgBox( "Microsoft Word not installed" )
    return .f.
  ENDIF
  oWord := oWord:dynamicCast(ActiveXObject())
  oWord:Quit := {||lWordFinished := .T.}
  oWord:visible := .T.
  lWordFinished := .f.

  // Open a Word document and retrieve the bookmarks
  // collection.
  oWord:documents:open( cFile )
  oDoc := oWord:ActiveDocument
  oBM  := oDoc:Bookmarks

  // Replace the Bookmark with a new value
  ReplaceBookmark(oBM , "COMPANY"     , aData[1] )
  ReplaceBookmark(oBM , "TO"          , aData[2] )
  ReplaceBookmark(oBM , "FAX"         , aData[3] )
  ReplaceBookmark(oBM , "FROM"        , aData[4] )
  ReplaceBookmark(oBM , "TOTAL_PAGES" , "1" )
  ReplaceBookmark(oBM , "CARBON_COPY" , "" )
  ReplaceBookmark(oBM , "SUBJECT"     , aData[5] )
  ReplaceBookmark(oBM , "SALUTATION"  , aData[6] )
  ReplaceBookmark(oBM , "TEXT"        , aData[7] )
  ReplaceBookmark(oBM , "DATE"        , DToC(Date()) )

  ReplaceBookmark(oBM , "NAME1"       , aData[15] )
  ReplaceBookmark(oBM , "NAME2"       , aData[16] )
  ReplaceBookmark(oBM , "STRASSE"     , aData[17] )
  ReplaceBookmark(oBM , "LKZ"         , aData[18] )
  ReplaceBookmark(oBM , "PLZ"         , aData[19] )
  ReplaceBookmark(oBM , "ORT"         , aData[20] )
  ReplaceBookmark(oBM , "Z_HD"        , aData[21] )
  ReplaceBookmark(oBM , "LAND"        , getland(aData[18]) )


  // Save the resulting Word document
  IF(ValType(cSaveAs)=="C")
    oDoc:saveas(cSaveAs)
  ENDIF

  // Optional print out of document to standard
  // printer
  *IF nBearb = 2
    *oDoc:PrintOut()
  *ENDIF

  // Close the document and destroy the ActiveX
  // object
  if nBearb # 1
     //oDoc:sendfax()
     oDoc:close()
     oWord:Quit()
  endif
  sleep(200)
  oWord:destroy()
  set_msg()
  if nBearb = 2
     WinAPIPrint(cFile)
  endif

RETURN .t.

static FUNCTION ReplaceBookmark(oBM,cBM,cValue)
  LOCAL lRet := oBM:Exists(cBM)
  LOCAL oF
  IF(lRet)
    set_msg("Replace " + cBM + " with " + var2char(cValue))
    oF := oBM:Item(cBM)
    oF:Range:Text := cValue
    oF:Destroy()
  ENDIF
RETURN(lRet)


Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

Post Reply