ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/WordLib.py
(Generate patch)

Comparing Python/NinoCode/Tool_Box/WordLib.py (file contents):
Revision 610 by nino.borges, Wed Jun 15 15:54:16 2016 UTC vs.
Revision 611 by nino.borges, Wed Sep 21 15:10:23 2016 UTC

# Line 9 | Line 9 | Just a Word library to make automating w
9  
10   """
11  
12 + from win32com.client import constants as c
13   import win32com.client
14  
15 +
16   class WordConnection:
17      def __init__(self,fileName = None):
18          # Dispatch() attempts to do a GetObject() before creating a new one.
# Line 18 | Line 20 | class WordConnection:
20          self.wordApp = win32com.client.DispatchEx("Word.Application")
21          self.wordApp.Visible = 0
22          self.wordApp.DisplayAlerts = 0
23 +        #wdCollapseEnd = win32com.client.Constants.wdCollapseEnd
24 +        self.wdCollapseEnd = c.wdCollapseEnd
25          
26          
27          if fileName:
# Line 27 | Line 31 | class WordConnection:
31              ##  Replace this soon so taht it makes a new if you dont pass filename
32              #self.xlBook = self.xlApp.Workbooks.Add()
33              self.fileName = ''
34 +        
35  
36      def Save(self, newFileName = None):
37          if newFileName:
# Line 55 | Line 60 | class WordConnection:
60          
61          
62          #app.ActiveDocument.Close(SaveChanges=True)
63 <        
63 >
64 >    def CopyEntireDocument(self):
65 >        """Copies the entire document into a copy object in memory that can then be pasted in another document"""
66 >        self.wordApp.ActiveDocument.Select()
67 >        self.wordApp.Selection.Copy()
68 >        
69 >    def PasteAtEnd(self):
70 >        """Takes a copy object and pastes that to the end of this document"""
71 >        
72 >        range2 = self.wordApp.ActiveDocument.Content
73 >        ## Move to the end
74 >        range2.Collapse(self.wdCollapseEnd)
75 >        ## Paste the copy object in mem to this doc.
76 >        range2.Paste()
77 >        
78 >
79 > ## Example of using copy and past functions above.
80 > ##>>> docA = WordLib.WordConnection(r"C:\Test\TemplateTest\TermsAndConditions.docx")
81 > ##>>> docB = WordLib.WordConnection(r"C:\Test\TemplateTest\Forensic Short Form SOW3.docx")
82 > ##>>> docA.CopyEntireDocument()
83 > ##>>> docB.PasteAtEnd()
84 > ##>>> docB.search_replace_all("<<Client>>", "Umberger Zipster")
85 > ##>>> docB.Save()
86 > ##>>> docB.Close()
87 > ##>>> docA.Close()    

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)