assigning second row of data to the first row of header names using excel data in sikuli

Asked by AKR

Hi Raiman,

Trying to reading excel data in sikuli which I can.
But I would like to assign the data from second row to the first row which is not accepting.
Here in the below example first row values in the excel are testfile, outfile, firtstpages, otherpages, source and second row onwards
a4, AO1,d1,d1,auto
a3,AO2,d3,d3,bypass

When I do below way it is working, but I don't want to enter column cell increment for each parameter, instead is there a way to keep the first row constant and only passing data from second row to first row parameters

 #print testcase
 testfile=worksheet.cell_value(curr_row, cell)
 outputfile=worksheet.cell_value(curr_row, cell+1)
 firstpages=worksheet.cell_value(curr_row, cell+2)
 otherpages=worksheet.cell_value(curr_row, cell+3)
 source=worksheet.cell_value(curr_row, cell+4)

Please see my below steps

workbook = xlrd1.open_workbook('C:\\Documents and Settings\\admin\\Desktop\\python\\book1.xls')
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
num_cells = worksheet.ncols - 1
curr_row = 0
header_row = curr_row
curr_row = 1
while curr_row <= num_rows:

 row = worksheet.row(curr_row)
 print 'Row:', curr_row

                '''
                 testfile=worksheet.cell_value(curr_row, cell)
 outputfile=worksheet.cell_value(curr_row, cell+1)
 firstpages=worksheet.cell_value(curr_row, cell+2)
 otherpages=worksheet.cell_value(curr_row, cell+3)
 source=worksheet.cell_value(curr_row, cell+4
                '''
 cell=0

 while cell <= num_cells:
  #worksheet.cell_value(header_row,cell)=worksheet.cell_value(curr_row, cell)

  a=worksheet.cell_value(header_row,cell)
  b=worksheet.cell_value(curr_row, cell)

  print a
  print b
  print "worksheet.cell_value(header_row,cell)=worksheet.cell_value(curr_row, cell)"
  a=b
  cell += 1

with the above steps getting error message "syntax error as "no viable alternative at input value"
So please guide us how can I assign the data from second row to first row.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

"no viable alternative at input value"
is simply a Python syntax error.
The complete error message tells you where Python in what line cannot understand the syntax anymore. The reason might well already be in the line before.

Revision history for this message
AKR (kallapuram) said :
#2

Thanks for your reply
understood it is the python syntax error.
my question was how to assign the second row data to the first row. Is there any possibility

Revision history for this message
RaiMan (raimund-hocke) said :
#3

if you are using xlrd then you can only read the values from a worksheet.

To write (fill and save) a new worksheet you need xlwt.

Can you help with this problem?

Provide an answer of your own, or ask AKR for more information if necessary.

To post a message you must log in.