Search This Blog

Oct 11, 2012

Access excel file by Python

    I have a task to extract register data from SOC spec and fill in excel file. I chosen Python script language to do this automatic job. I have found two 3rd party tools xlwt and openpyxl.
    I have tried xlwt, it has well documentation and easier to operation. However, it has two major weakness, first, it only support up to excel 2003; second, it doesn't support Python 3 which is default version in my group. So I turn to Openpyxl, before that, I would like record some information for xlwt which might be useful for other who don't care about those two weakness I mentioned above.

1. xlrd
* Version 0.8.0
* c:\python26\python.exe install

2. xlwt
* version 0.7.4
* c:\python26\python.exe install

3. Sample code
These same code can generate all style I needed in my task.
from xlwt import Workbook, easyxf
from xlwt.Utils import rowcol_to_cell

row0_style = easyxf(
    'font: name Calibri, bold True, height 220;'
reg_row_style = easyxf(
    'pattern: pattern solid, fore_colour yellow;'
    'font: name Calibri, height 220;'
common_style = easyxf(
    'font: name Calibri, height 220;'

row0_data = [
    'Bit Num',
    'Bit Access',
    'Bit Field Reset',
    'Enum Name',
    'Enum Value',
    'Short Name',

w = Workbook()
#sheet1 = w.add_sheet('version')

sheet2= w.add_sheet('Base_alias')
sheet2.panes_frozen = True
sheet2.remove_splits = True
sheet2.horz_split_pos = 1
for col in range(12):
for col in range(12):
for col in range(12):
    for row in range(2,80):

Post a Comment