質問

OpenPyxlを使用してPythonスクリプトを持ち、Excelファイルを読み取ります。OpenPyxlが正しくインストールされていないことを発見するまで、これは正常に機能します。ただし、これを修正した後、スクリプトは実際の値の代わりに、それらがどこから来たのかわからない数値を返します。

スクリプト:

wb=load_workbook(r'C:\test.xlsx', use_iterators = True)
ws=wb.get_sheet_by_name('Sheet1')

#Iterate trough all rows
for row in ws.iter_rows(row_offset=1):
    for cell in row:
        #If the column == A, check if there's a website value
        if cell.column == 'A':
            try:
                print cell.internal_value
                self.match = re.match(regex, cell.internal_value)
                if self.match:
                    self.match = 'OK'
            except:
                pass
.

tryブロックの印刷を追加して、プログラムによって返されるものを確認します。

0
1
31
49
143
.

それは次のようになるべきです:

None
Website
www.coolblue.nl
www.bol.com
www.elektrosky.nl
.

実際の値の代わりにMyスクリプトがこれらの数値を返すのはなぜですか?

編集:最初の6行の私のXMLファイル(最初の行は空です)

Website           |     Sender    |     Price  |    Mark(s)       |     Payment methods
www.coolblue.nl         PostNL          Free      Thuiswinkel           Ideal, Visa, Mastercard
www.bol.com             PostNL          Free      Thuiswinkel           Ideal, Visa, Mastercard
www.elektrosky.nl       PostNL         € 5,00     Webshop keurmerk      Ideal, Visa, Mastercard, Amex, PayPal
www.belsimpel.nl        PostNL, DPD    € 6,95     Thuiswinkel           Ideal, Visa, Mastercard
.

役に立ちましたか?

解決

問題は.internal_valueを使用しています。デフォルトでは、Excelはルックアップテーブルに文字列を保存し、セルにインデックスを保持します。.value

を使用している場合は大丈夫です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top