Ich habe ein Skript geschrieben, das Werte für ein bestimmtes Datum in einem Excel-Blatt ändert. Wenn ich eine neue Excel-Datei unter Verwendung von copy
erstelle, wird alles bis auf den Jahresteil des Datums korrekt kopiert. Zum Beispiel wird es vom 04.05.2012 bis zum 04.05.2008 gehen. Es scheint, dass alle Daten vier Jahre zurückreichen. Hier ist der Code:Python xlutils Kopien über falsches Jahr
def exceledit():
#open excel sheet
import xlrd, xlwt, xlutils
import datetime
from xlutils.copy import copy
print 'Opening excel sheet...'
book = xlrd.open_workbook('test.xls', on_demand=True, formatting_info=True)
print 'Creating and editing new excel sheet...'
wbook = copy(book)
print 'Done creating new excel sheet'
sh = book.sheet_by_index(0)
#iterate through dates in excel sheet
for colnum in range(sh.ncols):
date = sh.cell_value(3, colnum+4)
#if xlrd finds a date
if date:
#grab date data
year, month, day, hour, minute, second = xlrd.xldate_as_tuple(date\
, book.datemode)
#if dates are within the month currently being edited
if month == 04:
#format excel date information to work with parkh dict
format = str(month) + "/" + str(day) + "/" + str(year)
print 'Editing ' + format
#clear cells to eliminate old information
wbook.get_sheet(0).write(6, colnum+6, "")
wbook.get_sheet(0).write(5, colnum+6, "")
wbook.get_sheet(0).write(7, colnum+6, "")
#iterate through hour segments for that day
for x in parkh[format]:
#if regular hours, insert in "HOURS" row
if x[0] == 'Park Hours':
wbook.get_sheet(0).write(6, colnum+6, x[1])
#if extra magic hours, insert in respective row
if x[0] == 'Extra Magic Hours':
#insert in morning row
if int(x[1][0:1]) in range(2,9):
wbook.get_sheet(0).write(5, colnum+6, x[1])
#insert in evening row
else:
wbook.get_sheet(0).write(7, colnum+6, x[1])
if month == 05:
break
print 'Done editing. Now saving...'
wbook.save('new.xls')
print 'new.xls saved'
Jede Idee, warum könnte es das Jahr werden, ändert sich? Ich habe niemanden gesehen, der anderswo das gleiche Problem hat.