Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: Using Zip-7 (or something)

$
0
0
Re: Using Zip-7 (or something)
FoxPro Programming
Re: Using Zip-7 (or something)
03/17/2012
03:11:12 PM
3GH0WJWVC Show this entire thread in new window
Gratar Image based on email address
From:
To:
Attachments:
None
Here's one way ...

*!* Example of getting a DOCX file, opening it up via 7zip, replacing a few placeholders and re-zipping *!* I normally use bookmarks, but with this it might be a bigger level of complexity. DECLARE INTEGER ShellExecute ; IN SHELL32.DLL ; INTEGER nWinHandle,; STRING cOperation,; STRING cFileName,; STRING cParameters,; STRING cDirectory,; INTEGER nShowWindow SET DEFAULT TO C:\appsvfp_6x\common60\Projects\VFP_to_xlsX\ SET SAFETY off WAIT WINDOW "select template DOcX file to unzip" lcDocXFile = GETFILE("docx") IF FILE(lcDocXFile) lcZipFile = JUSTPATH(lcDocXFile)+"\" + juststem(lcDocXFile) + ".zip" COPY File (lcDocXFile) to (lcZipFile) ELSE WAIT WINDOW "No DOCx slected -- bye" RETURN ENDIF lcOutputDir = "C:\temp\wcAttachments\_DocX"+SYS(2015)+"\" lcZipCommandToExtract = 'x ' + lcZipFile +" -o"+lcOutputDir lSuccess=ShellExecute(0,'open','7z.exe',lcZipCommandToExtract,'',1) WAIT WINDOW "Let's hesitate a few seconds to allow the file operations to complete" TIMEOUT 3 *!* OK, Let's Now maniplute the word\document.xml file and swap and a few placeholders lcDocumentXML = lcOutputDir + "word\document.xml" strDocumentXML = FileToStr(lcDocumentXML) strDocumentXML = STRTRAN(strDocumentXML,"*CAR_ID*","000001, jkt-001") strDocumentXML = STRTRAN(strDocumentXML,"*date_open*",MDY(DATE())) strDocumentXML = STRTRAN(strDocumentXML,"*cIssueCode*","TEST ZIP DOCX process") strDocumentXML = STRTRAN(strDocumentXML,"*cAsssignee*","Kevin V. Emmrich") *** Copy back to xml file STRTOFILE(strDocumentXML,lcDocumentXML) WAIT WINDOW "Let's hesitate a little " TIMEOUT 1 *** Now lets zip it back up FolderToArchive = lcOutputDir FileToOutput = "c:\temp\wcAttachments\NewDocXFile.zip" lcZipCommandToArchive = 'a ' + FileToOutput +" "+FolderToArchive+"*" lSuccess=ShellExecute(0,'open','7z.exe',lcZipCommandToArchive,'',1) *** of course then we rename the file back to DOCX

*******************************************************


I am trying to extract a DOCX into its components, manipulate it and then zip it back up.
So close, yet so far.

I used Craig Boyd's VFPCompression to extract and then rezip them up --> but it refuses to zip the \_rels\.rels folder/file combination (the folder is there, just no file inside of it). I guess .rels is not really a legal file name, so I'll have to punt that nice little library that Craig has made available. I'll have to try another zip library of some sort.

I have 7-zip and that seems to work from the windows file manager, but I can't find a good (easy) reference on calling it from vfp9 to zip it up. If anyone has ideas or a link, let me know.

Thanks,

Kevin



Viewing all articles
Browse latest Browse all 10393

Trending Articles