openpyxl返回数值

时间:2014-07-30 10:51:37

标签: python openpyxl

我有一个使用openpyxl读取excel文件的Python脚本。这曾经工作正常,直到我发现openpyxl没有正确安装,这让我在IDE之外运行脚本时出错。但是,在修复此问题后,脚本将返回数值,我不知道它们来自何处,而不是实际值。

剧本:

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块中的print以查看程序返回的内容,前五个记录的内容如下:

0
1
31
49
143

应该是:

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

为什么我的脚本会返回这些数值而不是实际值?

编辑:我的xml文件的前6行(第一行为空)

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

1 个答案:

答案 0 :(得分:2)

问题是您正在使用.internal_value。默认情况下,Excel将字符串存储在查找表中,并将索引保​​留在单元格中。如果你只使用.value

,你应该没事
相关问题