Skip to content

Commit

Permalink
Created helper file to store common functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kodster28 authored Apr 4, 2019
1 parent a01b7e6 commit 037c53f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Helper_File.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def check_shape_for_text(shape):
#returns true if shape in MS Office has text. Requires win32com.client module.
if shape.HasTextFrame or 'TextBox' in shape.Name:
return True
else:
return False

def is_shape_a_group(shape):
#returns true if shape in MS Office is part of a group. Requires win32com.client module.
try:
if shape.GroupItems.Count > 0:
return True
except:
return False

def find_replace(shape, find_phrase, replace_phrase):
#finds and replaces text within a shape in MS Office. Requires win32com.client module.
return shape.TextFrame.TextRange.Replace(FindWhat=find_phrase, ReplaceWhat=replace_phrase, MatchCase = True)

def add_comment(object, author, text):
#adds a comment to a PPT or Word Document. Make sure you select slide object for PPT, document object for Word. Does not work for Excel. Requires win32com.client module.
return object.Comments.Add(Left = 12, Top = 12, Author = author, AuthorInitials = 'Py', Text = text)

def open_office_application(win32_import, application_type, visible):
#opens an office application. Requires proper naming of objects (Word, Excel, PowerPoint). Returns application object. Visible is boolean.
Application = win32_import.gencache.EnsureDispatch(application_type + '.Application')
Application.Visible = visible
return Application

0 comments on commit 037c53f

Please sign in to comment.