Ask Your Question
0

AttributeError: 'module' object has no attribute 'workbook'

asked 2017-07-19 08:26:53 -0600

mikerosz gravatar image

Hello all, I am receiving an error when trying to read an Excel document. I am not sure why.

 import os, sys

 PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN"

 sys.path.append(PSSE_LOCATION)

 import excelpy

testxls = excelpy.workbook(xlsfile, mode='r')
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-07-19 14:50:11 -0600

mikerosz gravatar image
Now I am receiving aother error. ValueError: need more than 1 value to unpack


import psspy
import excelpy
xlsfile=r'C:\Users\RoszkowskiM\Documents\PSSEEXPORT.xlsx'
testxls=excelpy.workbook(xlsfile,mode='r')

mydict = {}
for row in xlsfile:
    year,busnum,busname,change,tla,location = row[0:760]

# convert the types from string to Python numbers

change= float(change)
bus = int(busnum)

     #If this is a year not seen before, add it to the dictionary
     if year not in mydict:
        mydict[year] = {}

busses_in_year = mydict[year]
 if location not in busses_in_year:
       busses_in_year[location] = []


 #Add the bus to the list of busses that stop at this location
busses_in_year[location].append((busnum,busname,change))
edit flag offensive delete link more

Comments

year,busnum,busname,change,tla,location = row[0:760] would need to be something like this year, busnum = row[0:20], row[21:29]

nelak gravatar imagenelak ( 2017-07-20 10:03:39 -0600 )edit
0

answered 2017-07-19 13:14:07 -0600

nelak gravatar image

updated 2017-07-19 14:00:09 -0600

Where do you assign a value to xlsfile?

To elaborate: 'r' is specifying read on an existing file.

From the documentation:

(1) When used to create new Excel files or add worksheets to existing Excel files:
testxls = excelpy.workbook()
testxls = excelpy.workbook(r"c:\working dir\ex1.xls")
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet") or
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet", False) or
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", "MySheet", False, 'w') or
testxls = excelpy.workbook(xlsfile=r"c:\working dir\ex1.xls", sheet="MySheet",
overwritesheet=False, mode='w')
(2) When used to read existing Excel files:
testxls = excelpy.workbook(r"c:\working dir\ex1.xls", mode='r')
edit flag offensive delete link more

Comments

I am trying to a read a file. I don't what assigning a value is.

mikerosz gravatar imagemikerosz ( 2017-07-19 13:31:58 -0600 )edit

You would need to open an existing file. I would expect to see something like this. xlsfile = r'C:\Desktop\data.xls' testxls = excelpy.workbook(xlsfile, mode='r')

nelak gravatar imagenelak ( 2017-07-19 13:57:56 -0600 )edit

ok that works now. But I have multiple sheets on one excel workbook. How do I access that

mikerosz gravatar imagemikerosz ( 2017-07-19 14:31:39 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2017-07-19 08:26:53 -0600

Seen: 2,485 times

Last updated: Jul 19 '17