简体   繁体   中英

Question on python text file read write using Win32com

I am reading a text file a.txt which has so many columns and i need the data in 5 columns. I fetched it by reading and get data of 5 columns,but my question is how can I import these 5 columns data into one excel file having same column as in text file.

Here is an example explaining how to generate an excel file with the xlwt python lib.

Using win32 would be ok but i personnaly prefer to use xlwt because it doesn't require excel to be installed on the machine.

import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet("My sheet")
for line in xrange(10):
    for col in xrange(5):
        ws.write(line, col, line*10+col)
wb.save('myfile.xls')

I hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM