Tuesday, March 5, 2013

Reading/Writing xlsx File In Python

I'm using the python library openpyxl.
The below shows an example of how to iterate thru cells ...


#!/usr/bin/env python

import openpyxl
from pprint import pprint

wb = openpyxl.reader.excel.load_workbook('test.xlsx')
s = wb.get_sheet_by_name(name='Sheet1')

d = s.calculate_dimension()

r = s.range(d)
print "Range:" + str(r)
for row in r:
   for cell in row:
      print cell.get_coordinate()
      print cell.value
If you need help, u can use the python interactive session:-
%python
>>> import openpyxl
>>> help(openpyxl.reader.excel)
>>> wb = openpyxl.reader.excel.load_workbook('test.xlsx')
>>> help(wb)
>>> ws = wb.get_sheet_by_name(name='Sheet1')
>>> help(ws)
>>> cell = ws.cell(row=0, column=0)
>>> help(cell)

No comments:

Post a Comment

How To Bypass Kerberos(kinit) Authentication

Whenever you try to setuid and impersonate as someone else to run something, it is very likely that you will run into kerberos/kinit issues....