#16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    I was curious, so I tried their simple replace example. It worked with .net and CF9, so that is encouraging.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by cfSearching
    I was curious, so I tried their simple replace example. It worked with .net and CF9, so that is encouraging.
    So you imported the Open XML SDK into CF9 and used CFObject to do the logic/code?

    I was thinking about using CFZIP, since docx documents after all are just a zipped file with multiple XML files. Then just reading/writing to the document.xml file directly, and then adding in checked boxes as needed. It looks like that is what they do in the CF9 WACK Vol. 3 book.
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Essentially, yes. I had the .net 3.5 framework installed already. So I just installed the 2.0 SDK. Then used createObject. I can post the sample code if you want.

    It looks like that is what they do in the CF9 WACK Vol. 3 book.
    Oh, I do not have volume 3 so I did not realize they covered that. As long as you understand the xml schema/structure, that should work fine.
    Last edited by cfSearching; February 12th, 2012 at 05:02 PM.
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by cfSearching
    Essentially, yes. I had the .net 3.5 framework installed already. So I just installed the 2.0 SDK. Then used createObject. I can post the sample code if you want.
    If you could... I never really used outside libraries/API's before with createObject/CFObject. When I was looking at the SDK I wasn't really sure how I would use their sample code in CF.

    Thanks!
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    The syntax is mostly the same except for using createObject to instantiate classes instead of new SomeClass(); There were a few quirks, so I wrote a quick blog entry on it in case it helps.
    Last edited by cfSearching; February 12th, 2012 at 06:55 PM.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Can anyone figure this out? I am getting a corruption message when I open the word document back up. This is just a simple test and I'm not actually doing any changes to the file, but still the document gets corrupted. I set the path to my document, then made a folder called "extract" for the extracted zip files to be placed.

    Code:
    <cfset pathToDoc = GetDirectoryFromPath(ExpandPath( "./" )) & "myCheck.docx">
    <cfset destZip = GetDirectoryFromPath(ExpandPath( "./" )) & "extract/">
    
    <cfzip action="unzip"
           file="#pathToDoc#"    
           destination="#destZip#"
    	   overwrite="yes">
    
    <cffile action = "read" 
            file="#destZip#\word\document.xml"
            variable="docGen"> 
    		
    <cfset XMLDoc=XMLParse("#docGen#")>
    
    <cfdump var="#XMLDoc#">
    
    <cffile action = "write" 
            file="#destZip#\word\document.xml" 
            output="#docGen#"> 
    
    <cfzip action="zip"
           storepath="yes"   
           file="#pathToDoc#" 
           source="#destZip#">
    I'm guessing it has to do with the ending CFZip tag. I'm trying to use the code in the WACK Vol. 3, but this third volume is just plain horrible compared to the first two. None of the examples for the chapter on Office integration seem to even work.
  12. #22
  13. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,287
    Rep Power
    968
    First I would try to confirm at which point it is failing. When you write the file back to document.xml, if you open up that file, are the contents the same (correct) XML that was there when you performed the unzip? I'd use a text compare tool like WinMerge to make sure you compare everything exactly (including white space, line feed/carriage return, etc.).

    If the two files ARE the same, then move on to the zip process. Zip the final result to a different .zip file and open up/compare the zip contents manually (with WinZip or 7Zip) to look for any differences in the structure and contents of the zip file.
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Alright, I redid it, and it worked on simple examples. Would not work with placeholders wrapped around with % or # signs. Since the Word XML schema tosses that into a different tag. But it did work on replacing just plain text.

    Now when I tried it with a big template (ones I have to work with), it just exploaded with illegal XML errors. I'm not sure on using something like XMLParse and all the XML functions within CF regarding that function, since it timesout. But While looking at the document.xml file, it looks like it did do a replace on all the placeholders.
  16. #24
  17. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,287
    Rep Power
    968
    I'd try to narrow down the cause of the XML errors. Is it invalid XML tags? Unescaped characters?
  18. #25
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Invalid character.

    Code:
    An invalid character was found in text content. Error processing resource 'file:///C:/Documents and Settings/P070096/Deskto...
    
    <w:r><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/></w:rPr><w:tab/><...
    > 
    - <w:rPr>
      <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" /> 
      </w:rPr>
      <w:tab /> 
      </w:r>
    I read this and I'm starting to think learning C#/OOXML SDK is a better option. I can now see why Aspose.Words costs so much... working with Word Documents is a total nightmare.
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    What code are you using for the replacement? I ran a few tests with simple documents and replace() and did not have problems with your cffile/cfzip code.

    Update: Maybe you are not escaping the new values as kiteless mentioned earlier?

    Code:
    <cfset docGen = replace(docGen, "{placeholder}", xmlFormat("New <text> here"), "all")>
    Last edited by cfSearching; February 14th, 2012 at 04:01 PM.
  22. #27
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    working with Word Documents is a total nightmare
    Sorry but in comparison to the old binary format it is a treat {grin}
  24. #28
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by cfSearching
    Update: Maybe you are not escaping the new values as kiteless mentioned earlier?

    Code:
    <cfset docGen = replace(docGen, "{placeholder}", xmlFormat("New <text> here"), "all")>
    It still gives an illegal XML character error. I tried that example in a very basic template (and it works), but not something that is loaded with headers/footers, tables, etc (like the documents I'm working with).

    We're thinking about saving all the documents as PDF's. Then loading them up in Acrobat and adding in form fields, which we can then manipulate via CFPDF. Hopefully that will work.
  26. #29
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by ColdBreeze
    It still gives an illegal XML character error. I tried that example in a very basic template (and it works), but not something that is loaded with headers/footers, tables, etc (like the documents I'm working with).
    Well it could be a hundred different things. But unfortunately it is impossible to pinpoint without the actual document throwing the errors.

    We're thinking about saving all the documents as PDF's. Then loading them up in Acrobat and adding in form fields, which we can then manipulate via CFPDF. Hopefully that will work.
    So you are putting the "replaceable" text in form fields too?
  28. #30
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep Power
    0
    Originally Posted by cfSearching
    So you are putting the "replaceable" text in form fields too?
    The replaceable text is what I was using as a placeholder for a stored procedure to populate.

    So I was thinking just putting a form field where all the placeholders go (and just populating that form field via the stored procedure).

IMN logo majestic logo threadwatch logo seochat tools logo