14
Python- Excel- Bibliotheken PyExcelerator, XLRD, PyWin32

Python - Excel - Bibliotheken

Embed Size (px)

Citation preview

Page 1: Python - Excel - Bibliotheken

Python- Excel- Bibliotheken

PyExcelerator, XLRD, PyWin32

Page 2: Python - Excel - Bibliotheken

Folie 2Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Inhalt

Hintergrund

PyExcelerator, XLRD, PyWin32

Vor- und Nachteile

Page 3: Python - Excel - Bibliotheken

Folie 3Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Anreiz und Wahl der Bibliothek

Skripterweiterung für DataFinder:

Projekt- und Auftragsverwaltung

Parsen von Excel-Tabellen zur Weiterverarbeitung

Kriterien für die Wahl der Bibliothek:

Einarbeiten und Fehlersuche

Dokumentation und Beispiele

Funktionalitäten

Plattformabhängigkeit /-unabhängigkeit

Page 4: Python - Excel - Bibliotheken

Folie 4Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

PyExcelerator

Excel-Dokumente (97+), OpenOffice Calc

Python 2.4+

Unterstützung von Unicode in Excel

Plattformunabhängig

Page 5: Python - Excel - Bibliotheken

Folie 5Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

XLRD

Excel-Reader: Daten (auch bool‘sche Ausdrücke), Referenzen, Formatinformationen

Keine Objekte, Formeln, Kommentare, Hyperlinks, etc.

Plattformunabhängig

Windows: Umgehen von COM-Objekten

Page 6: Python - Excel - Bibliotheken

Folie 6Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

PyWin32

Python unter Windows: COM-Interface

Entwickelt von Mark Hammond

Plattformabhängig

Interaktion mit Windows-Programmen (Excel)

Page 7: Python - Excel - Bibliotheken

Folie 7Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Auslesen einer Zeile in einem Excel-Worksheet

from pyExcelerator import *

test = parse_xls("C:\Test.xls")

liste = []tupel = test[]dict = tupel[1]

cellcontent = dict.get((1,4))

for y in range(0, len(dict.keys())) helpvar = dict.get((0,y))

if helpvar != None: liste.append(helpvar) else: pass print(liste)

parse_xls(filename)

get()

keys()

Page 8: Python - Excel - Bibliotheken

Folie 8Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

parse_xls(filename)

Page 9: Python - Excel - Bibliotheken

Folie 9Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Vor- und Nachteile

PyExcelerator

↑ Gute Dokumentation und Beispiele, übersichtliche Anzahl an Funktionen

↑ Standard-Python-Datentypen (Listen und Dictionaries)

↑ Plattformunabhängig

↓ Letztes Release: April 2009

↓ Kann zu Problemen mit Excel 2007/2010 führen

Page 10: Python - Excel - Bibliotheken

Folie 10Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

XLRD

xlrd.open_workbook()

sheet_by_index() / sheet_by_name()

row(), col(), cell()

import xlrd

test = xlrd.open_workbook("C:\Test1.xls")

liste = []worksheet = test.sheet_by_index(0)worksheet2 = test.sheet_by_name("Tabelle1")

row = worksheet.row(0)col = worksheet2.col(0)cellcontent = worksheet.cell(0,0)

Page 11: Python - Excel - Bibliotheken

Folie 11Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Vor- und Nachteile

XLRD

↑ Gute Dokumentation, übersichtliche Anzahl an Funktionen

↑ nur zum Lesen von Excel-Dokumenten (Schreiben: XLWT)

↑ Plattformunabhängig

↓ Schreiben in Excel nicht möglich

↓ keine einfachen Datentypen

Page 12: Python - Excel - Bibliotheken

Folie 12Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

PyWin32

Dispatch()

Open()

Sheets()

Cells()

Close()

from win32com.client Dispatch

xls = Dispatch("Excel.Application")xls.Visible = 1

wb = xls.Workbooks.Open("C:\Test.xls")

sht = wb.Sheets("Tabelle1")

for x in range (1,6): row = sht.Cells(1,x) print(row)

xls.Workbooks.Close()

Page 13: Python - Excel - Bibliotheken

Folie 13Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Vor- und Nachteile

PyWin32

↑ Viele nützliche Funktionen zur Ausgabe von Zellen,Spalten, etc.

↑ Benutzt Excel-Bezeichnungen

↨ Sehr umfangreich

↓ Plattformabhängig: nur unter Windows

↓ COM-Objekte

↓ Einarbeiten schwierig

Page 14: Python - Excel - Bibliotheken

Folie 14Python- Excel Bibliotheken > Sophia Raab > 11. August 2010

Fazit

PyWin32, XLRD oder PyExcelerator?

Kontext der Verwendung

Andere Bibliotheken: pyXLReader, pyXLWriter, PythonOffice,…