SHOW:
|
|
- or go back to the newest paste.
1 | import os | |
2 | import csv | |
3 | import xlrd | |
4 | from xlrd import open_workbook | |
5 | from xlwt import Workbook | |
6 | ||
7 | ||
8 | fname = 'Pilvetyybid_1968_Jõgeva.xls' | |
9 | eraldi=fname.split("_") | |
10 | taiendita=eraldi[2].split(".") | |
11 | pilv=eraldi[0] | |
12 | pilvnimi=pilv[:4] | |
13 | jaamanimi=pilvnimi + "_" + taiendita[0] + "_" + eraldi[1] | |
14 | #print(jaamanimi) | |
15 | ||
16 | - | myfile = xlrd.open_workbook(fname) |
16 | + | with xlrd.open_workbook(fname) as wb: |
17 | - | # get a sheet |
17 | + | sh = wb.sheet_by_index(0) # or wb.sheet_by_name('name_of_the_sheet_here') |
18 | - | mysheet = myfile.sheet_by_index(0) |
18 | + | with open(jaamanimi + '.txt', 'w', newline='') as f: |
19 | - | new_book = Workbook() |
19 | + | spamwriter = csv.writer(f, delimiter=';') |
20 | - | new_sheet = new_book.add_sheet('Sheet 1', cell_overwrite_ok=True) |
20 | + | c = csv.writer(f) |
21 | ||
22 | - | #print (mysheet.col_values(3)) |
22 | + | for a in range(1,(sh.nrows)): |
23 | - | for col in range(mysheet.ncols): |
23 | + | #row=round(row,0) |
24 | - | if col ==0 or col>10: |
24 | + | # b=int(floor(a)) |
25 | - | pass |
25 | + | #if isinstance(row, int): |
26 | - | if len(mysheet.col_values(col)) == 1 and col in range(3, 6): |
26 | + | |
27 | - | mysheet.col_values= int(0) + mysheet.col_values |
27 | + | for col in range(sh.ncols): |
28 | - | print(mysheet.col_values(3)) # <-----------------------------------return nothing! |
28 | + | if col ==0 or col>10: |
29 | - | else: |
29 | + | row_should_be_written=False |
30 | - | for row in range (mysheet.nrows): |
30 | + | else: |
31 | - | if row == 0: |
31 | + | row_should_be_written=True |
32 | - | pass |
32 | + | c.writerow(sh.row_values(a)[1:11]) |