Seite 1 von 1

In Excel auf eine Reihe zugreifen

Verfasst: Freitag 12. Januar 2007, 12:06
von alpha
Hallo Pythoncommunity,

ich habe folgendes Problem:
Mit

Code: Alles auswählen

v = MyWorkSheet.Rows(i)
lese ich eine ganze Excelzeile ein. v hat dann dann type 'instance'.
und folgenden Inhalt:
((u'OPC-Item', u'Einheit', u'Beschreibung\ndeutsch / englisch', u'Bemerkungen de
utsch / englisch', u'Beschreibung\ndeutsch', u'Bemerkungen deutsch', u'Beschreib
ung\nenglisch', u'Bemerkungen englisch', u'Beschreibung\nfranz\xf6sisch', u'Beme
rkungen franz\xf6sisch', u'Beschreibung\nspanisch', u'Bemerkungen spanisch', u'B
eschreibung\nxxxxx', u'Bemerkungen xxxxx', None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None, N
one, None, None, None, None, None, None, None, None, None, None, None, None, Non
e, None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None),)


Jetzt meine Frage. Ich möchte das in einer Liste haben, bekomme das aber nicht hin egal wie ich "v" wandle oder anderen Typen zuweise. Habt ihr einen Tip für mich?

Vielen dank
alpha

Re: In Excel auf eine Reihe zugreifen

Verfasst: Freitag 12. Januar 2007, 14:39
von gerold
alpha hat geschrieben:Habt ihr einen Tip für mich?
Hi alpha!

Ja :-)

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import os
import win32com.client


filename = os.path.abspath("aaa.xls")
valuelist = []

excel_app = win32com.client.dynamic.Dispatch("Excel.Application")
try:
    excel_workbook = excel_app.Workbooks.Open(filename)
    try:
        excel_sheet = excel_workbook.Worksheets("Tabelle1")
        try:
            for value in excel_sheet.Rows(1).Value[0]:
                if value is not None:
                    valuelist.append(value)
        finally:
            del excel_sheet
    finally:
        excel_workbook.Close()
        del excel_workbook
finally:
    excel_app.Quit()
    del excel_app

print valuelist
mfg
Gerold
:-)

Verfasst: Dienstag 16. Januar 2007, 14:15
von alpha
Danke Gerold,

werd ich gleich mal ausprobieren.
alpha