Hyperlinks aus Visio extrahieren mit Python

Hier ist ein kleines Python-Script, welches alle Hyperlinks aus Microsoft Visio Dokumenten in eine Textdatei extrahiert. Es benötigt Pywin32!

from win32com.client import Dispatch
from sys import argv 
from sys import exit 
if len(argv)<=2:
     print 'This tool extracts all Hyperlinks from Visio Drawings to a file.'
     print '\nUsage: vsdhyperlink.exe  '
     exit() app = Dispatch('Visio.Application')
app.Visible = 0 
visioDoc = app.Documents.Open(argv[1]) 
file = open(argv[2], 'w') 
count = 0 
for page in range(visioDoc.Pages.Count):
     for shape in range(visioDoc.Pages(page+1).Shapes.Count):
         for link in range(visioDoc.Pages(page+1).Shapes.Item(shape+1).Hyperlinks.Count):
             link = visioDoc.Pages.Item(page+1).Shapes.Item(shape+1).Hyperlinks.Item(link).Address
             file.write(link+'\n')
             count += 1
             print link
file.close() 
print 'Written %s URLS to file %s'%(count, argv[2])  
app.Quit()

Hyperlinks aus Excel extrahieren mit Python

Hier ist ein kleines Python-Script, welches alle Hyperlinks aus Microsoft Excel Dokumenten in eine Textdatei extrahiert. Es benötigt Pywin32!

from win32com.client import Dispatch 
from sys import argv 
from sys import exit  
if len(argv)<=2:     
    print 'This tool extracts all Hyperlink addresses from Excel documents to a file..'
    print '\nUsage: xlshyperlink.exe  '     
    exit()
app = Dispatch('Excel.Application') 
app.Visible = 0 
doc = app.Workbooks.Open(argv[1], 0, False, 2) 
file = open(argv[2], 'w') 
count = 0 
for i in range (doc.Worksheets.Count):
     for worksheet in range (doc.Worksheets.Item(i+1).Hyperlinks.Count):
         link = doc.Worksheets.Item(i+1).Hyperlinks.Item(worksheet+1).Address
         file.write(link+'\n')
         print link
         count += 1 
file.close() 
print 'Written %s URLS to file %s'%(count, argv[2]) 
doc.Saved = 1 
app.Quit()