Alaska Software Inc. - docx, zip/unzip edit document.xml
Username: Password:
AuthorTopic: docx, zip/unzip edit document.xml
Rvveelen docx, zip/unzip edit document.xml
on Fri, 04 May 2012 16:11:05 +0200
Hi,

We have a routine that replaces certain codes in *.RTF files. The same
could be done for unzipped *.DOCX files (the content would be in
document.xml).

Question #1: Has anyone done such a thing?
Question #2: Has anyone ever made a routine to edit a *.DOCX?
Question #3: Has anyone ever wrote a routine to unzip (huffman) a file?

If you have code, tips or tools I would be very happy to hear from you!

Best regards,
Ronald van Veelen
AUGE_ OHRRe: docx, zip/unzip edit document.xml
on Fri, 04 May 2012 18:39:52 +0200
hi,

> We have a routine that replaces certain codes in *.RTF files. The same
> could be done for unzipped *.DOCX files (the content would be in
> document.xml).

Word 2007 does use *.DOCX as default when "load" via activeX

serach/replace : start Word Macro Editor to "see" how it works

later you can o:SaveAs( cFile, wdFormatXML )
Constante you can get with

TLB2CH.EXE WORD.APPLICATION > MYWORD.CH

greetings by OHR
Jimmy
Rvveelen Re: docx, zip/unzip edit document.xml
on Mon, 07 May 2012 14:04:50 +0200
Op Fri, 04 May 2012 18:39:52 +0200 schreef AUGE_ OHR:

> hi,
> 
>> We have a routine that replaces certain codes in *.RTF files. The same
>> could be done for unzipped *.DOCX files (the content would be in
>> document.xml).
> 
> Word 2007 does use *.DOCX as default when "load" via activeX
> 
> serach/replace : start Word Macro Editor to "see" how it works
> 
> later you can o:SaveAs( cFile, wdFormatXML )
> Constante you can get with
> 
> TLB2CH.EXE WORD.APPLICATION > MYWORD.CH
> 
> greetings by OHR
> Jimmy

Hi,

Thanks for your answer. It is not the solution though.

It is not a problem to save a docx. I want to replace certain text parts
with data from the database. I know this als could be done with
Word.application activexobject, but this is very buggy and instable. Not
when u test it. But when it is done 50.000 times a day it is. It is a MS
product 

So I still want to zip/unzip the xml's. Has anybody done that before?

best regards,
Ronald van Veelen
AUGE_ OHRRe: docx, zip/unzip edit document.xml
on Tue, 08 May 2012 02:25:11 +0200
hi,

>It is not a problem to save a docx. I want to replace certain text parts
>with data from the database. I know this als could be done with
>Word.application activexobject, but this is very buggy and instable. Not
>when u test it. But when it is done 50.000 times a day it is. It is a MS
>product 

with Xbase++ activeX 50.000 times will take a lot of time 
did you try DispHPR.DLL with ot4xb ?


>So I still want to zip/unzip the xml's. Has anybody done that before?

if you just talk about zip/unzip ... did you try AddZIP or ZLib ?

greetings by OHR
Jimmy
AUGE_ OHRRe: docx, zip/unzip edit document.xml
on Sun, 03 Jun 2012 02:12:51 +0200
hi,

>So I still want to zip/unzip the xml's. Has anybody done that before?

just think ... since XP we have "build-in ZIP"

found somewhere in Newsforum

/*!--------------------------------------------------------------------------
Function: Unzip(cZipFile, cDestFolder)
Summary: Invoke the shell as a COM object to unzip a file
Description: See MSDN for details
---------------------------------------------------------------------------*/
FUNCTION Unzip(cZipFile, cDestFolder)
LOCAL oShell, oNameSrc, oNameDest
   oShell    := CreateObject("Shell.Application")
   oNameSrc  := oShell:NameSpace(cZipFile)
   oNameDest := oShell:NameSpace(cDestFolder)
   oNameDest:CopyHere(oNameSrc:items(), 0x10)
   oShell:destroy()
RETURN NIL

greetings by OHR
Jimmy

p.s. to create a "new" ZIP File using CopyHere() you need a "spezial Header"
LOCAL aHead := {80,75,5,6,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}  use 
CHR( aHead[i] )
Andreas Gehrs-Pahl
Re: docx, zip/unzip edit document.xml
on Sat, 02 Jun 2012 15:32:09 -0400
Ronald,

>So I still want to zip/unzip the xml's. Has anybody done that before?

Have you tried XbZLib, the Zip file add-on for for Xbase++? You can 
download the current version from here: 

	http://www.EJusticeSolutions.com/EJS_OnSite/XbZLib21.zip

The documentation isn't up to date, but as you have the source code, it
shouldn't be too hard for you to figure it out. With XbZLib, you can open 
the ".docx" files and read the XML files into memory or save them as files
on disk, edit them, and save them back in the ".docx" file.

XbZLib is an Open Source project and free for commercial use, and if you 
add any new features or make corrections -- or update the docs -- you 
could post those updates here -- or email them to me -- for the benefit 
of all Xbase++ users.

Hope this helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas.GP@Charter.net
       Andreas.Gehrs-Pahl@InterAct911.com
       Andreas.Gehrs-Pahl@EJusticeSolutions.com
       Andreas@DDPSoftware.com
web:   http://www.Aerospace-History.net
Rvveelen Re: docx, zip/unzip edit document.xml
on Tue, 05 Jun 2012 14:12:17 +0200
Op Sat, 02 Jun 2012 15:32:09 -0400 schreef Andreas Gehrs-Pahl:

> Ronald,
> 
>>So I still want to zip/unzip the xml's. Has anybody done that before?
> 
> Have you tried XbZLib, the Zip file add-on for for Xbase++? You can 
> download the current version from here: 
> 
> 	http://www.EJusticeSolutions.com/EJS_OnSite/XbZLib21.zip
> 
> The documentation isn't up to date, but as you have the source code, it
> shouldn't be too hard for you to figure it out. With XbZLib, you can open 
> the ".docx" files and read the XML files into memory or save them as files
> on disk, edit them, and save them back in the ".docx" file.
> 
> XbZLib is an Open Source project and free for commercial use, and if you 
> add any new features or make corrections -- or update the docs -- you 
> could post those updates here -- or email them to me -- for the benefit 
> of all Xbase++ users.
> 
> Hope this helps,
> 
> Andreas

Hi,

Thank you! (Also the others!)

I will be starting this soon and than get back to you on this. I will post
the source to replace any kind of material in the docx.

Best regards,
Ronald van Veelen
Rvveelen Re: docx, zip/unzip edit document.xml
on Fri, 08 Jun 2012 12:34:30 +0200
Op Tue, 05 Jun 2012 14:12:17 +0200 schreef Rvveelen:

> Op Sat, 02 Jun 2012 15:32:09 -0400 schreef Andreas Gehrs-Pahl:
> 
>> Ronald,
>> 
>>>So I still want to zip/unzip the xml's. Has anybody done that before?
>> 
>> Have you tried XbZLib, the Zip file add-on for for Xbase++? You can 
>> download the current version from here: 
>> 
>> 	http://www.EJusticeSolutions.com/EJS_OnSite/XbZLib21.zip
>> 
>> The documentation isn't up to date, but as you have the source code, it
>> shouldn't be too hard for you to figure it out. With XbZLib, you can open 
>> the ".docx" files and read the XML files into memory or save them as files
>> on disk, edit them, and save them back in the ".docx" file.
>> 
>> XbZLib is an Open Source project and free for commercial use, and if you 
>> add any new features or make corrections -- or update the docs -- you 
>> could post those updates here -- or email them to me -- for the benefit 
>> of all Xbase++ users.
>> 
>> Hope this helps,
>> 
>> Andreas
> 
> Hi,
> 
> Thank you! (Also the others!)
> 
> I will be starting this soon and than get back to you on this. I will post
> the source to replace any kind of material in the docx.
> 
> Best regards,
> Ronald van Veelen

Attached is what I got till now. I have a proof of concept, now it is just
a matter of building a solid solution.

Thanks for all the help.

If I have a solid solution (and I don't forget) I wil send those classes.


docx.docx
docx.exe
docx.prg
Rudolf ReinthalerRe: docx, zip/unzip edit document.xml
on Sun, 27 May 2012 15:24:20 +0200
Hello,
make bookmarsk in the word file and replace them
regards
Rudolf



FUNCTION WordFillDocument(cFile,aData,cSaveAs)
   LOCAL oWord,oBM,oDoc,lWordFinished := .f.,x
    Create a Word ActiveX component
   oWord := CreateObject("Word.Application")
   IF Empty( oWord )
     MsgBox( "Microsoft Word ist nicht installiert" )
   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

*oDoc:PrintOut()

    Close the document and destroy the ActiveX
    object
//oDoc:sendfax()
     oDoc:close()
     oWord:Quit()
Do WHILE !lWordFinished
      Just wait
enddo
sleep(200)
oWord:destroy()
RETURN NIL

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)