Python script to get some columns from one excel to new

enter image description here I am new to Python. I need to create another Excel file from an Excel Excel file.

I need to create a new excel file as a "final test result" with column values ​​such as test case ID"Function loop1", "function loop2", which is the result of resp test case, etc. from my test_report.xls (as in the bottom image) Can anyone share a script with Python for this?

+4
source share
2 answers

You can use csv lib for this.
More details here: http://docs.python.org/2/library/csv.html
You will 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
+1

python xlrd 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')

: Python, Excel , Excel

0

All Articles