Hi,
Am 13.11.2013, 20:32 Uhr, schrieb <
axf...@gmail.com>:
> Hi folks, the last line of the below code is failing for me and I'm
> afraid
> I can't quite tell why.
> workbook = openpyxl.load_workbook(workbookname)
> sheets = workbook.get_sheet_names()
> totalsheets = len(sheets)
> if totalsheets!=1:
> workbooks = {}
> for y in sheets:
> if y != "DV-IDENTITY-0":
> workbooks[y] = workbook
> for x in sheets:
> if x != y:
> workbooks[y].remove_sheet(x)
Sorry, but as you can see your code has come through garbled.
> Traceback (most recent call last):
> File "csvnormalize.py", line 33, in <module>
> workbooks[y].remove_sheet(x)
> File "/usr/local/lib/python2.7/dist-packages/openpyxl/workbook.py",
> line
> 161, in remove_sheet
> self.worksheets.remove(worksheet)
> ValueError: list.remove(x): x not in list
> not quite sure what the issue is -- I'm looping through the workbook
> object
> and creating new workbook objects that only contain one sheet, for each
> sheet. should be quite simple, but I can't see the problem. Thanks!
I can't see any code there creating sheets but I don't think you are doing
quite what you think you are.
Try:
if x in workbooks[y].get_sheet_names():
workbooks[y].remove_sheet(x)
Working backwards from that might help you find the problem.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel:
+49-211-600-3657
Mobile:
+49-178-782-6226