4

enter image description here I am new to Python. I have to create another Excel file from my test report Excel file.

I need to create a new excel file as 'test result summery' with columns-values like test case ID and 'Function loop1', 'function loop2' which is result of resp test case etc from my test_report.xls (as in below image) Can anybody share some Python script for this?

Sara
  • 41
  • 2

2 Answers2

1

You can use csv lib for this.
More information here: http://docs.python.org/2/library/csv.html
You would start with something like:

import csv
outputfile = open('Your Desired File Name', 'wb')
DataWriter = csv.writer(outputfile, delimiter=',', quotechar='|', quoting = csv.QUOTE_MINIMAL)
DataWriter.writerow(['Test Case ID', 'Result'])
DataWriter.writerow(#Some data that you want to add)
outputfile.close() # Close the file
Andy_A̷n̷d̷y̷
  • 795
  • 2
  • 11
  • 25
  • TC_ID TS_STEP ACTUAL RESULT_LOOP1 RESULT_LOOP2 TC001 BAT ON LIGHT ON PASS PASS TC002 BAT OFF LIGHT oFF PASS FAIL only want a seperate excel with TC_ID and LOOP1, LOOP2 etc – Sara Dec 07 '13 at 08:21
  • @Sara Sorry I don't understand what you really want. – Andy_A̷n̷d̷y̷ Dec 07 '13 at 08:27
  • yes , sorry , i thought it will appear like rows and column view easy to understand but its displaying in a line – Sara Dec 07 '13 at 09:10
0

Use python libraries xlrd and xlwt.

import xlrd, xlwt

workbook1 = xlrd.open_workbook('my_workbook.xls')
worksheet1 = workbook1.sheet_by_name('Sheet1')
row = 0
col = 0
cell_value = worksheet1.cell_value(row, col)

workbook2 = xlwt.Workbook()
workssheet2 = workbook2.add_sheet('A Test Sheet')
workssheet2.write(row, col, cell_value)
workbook2.save('output.xls')

Another example: Using Python, write an Excel file with columns copied from another Excel file

Community
  • 1
  • 1
Prashant Borde
  • 1,058
  • 10
  • 21