How to read Excel by python

Hi guys,

Iwant to inform about reading excel in python. for this we need some python library . this is  openpyxl .  here is download.

install for ubuntu/windows:

cd ~/openpyxl (this is for ubuntu).

python setup.py build

python setup.py install (you should use "sudo" for ubuntu)

how about doing a reading example;

import os

from openpyxl import load_workbook

import sys

reload(sys)

sys.setdefaultencoding('utf-8')
path_xls="your file path"

wb = load_workbook(filename=path_xls, read_only=True)

ws = wb['your tab name'] # ws is now an IterableWorksheet
i=0

json_list=[]

for row in ws.rows:

if i!=0: #skip first row

json_list.append({"sentiment":str(row[0].value), "date":str(row[1].value),

"user":str(row[2].value),"text":str(row[3].value)})

i =1


have a nice day everybody. :)

Semiha Makinist Uzman on 10 Şubat 2016 yazdı
Yorum Ekle
  • 0 Yanıt(lar)
  • Yanıtınız

    Cevabınızı göndererek Gizlilik Politikası ve Hizmet Şartlarını kabul ediyorsunuz.