Using Python, write an Excel file with columns copied from another Excel file -
i have excel file containing varying number of columns, loop through columns (from header row value) of file using python, write (copy) columns excel file.
any examples on how can please?
here options choose from:
- xlwt (writing xls files)
- xlrd (reading xls/xlsx files)
- openpyxl (reading/writing xlsx files)
- xlsxwriter (writing xlsx files)
if need copy data (without formatting information), can use combination of these tools reading/writing. if have xls
file, should go xlrd+xlwt option.
here's simple example of copying first row existing excel file new one:
import xlwt import xlrd workbook = xlrd.open_workbook('input.xls') sheet = workbook.sheet_by_index(0) data = [sheet.cell_value(0, col) col in range(sheet.ncols)] workbook = xlwt.workbook() sheet = workbook.add_sheet('test') index, value in enumerate(data): sheet.write(0, index, value) workbook.save('output.xls')
Comments
Post a Comment