First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

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

asked Jul 19 '17

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')

2 answers

Sort by » oldest newest most voted
0

answered Jul 19 '17

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))
link

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 (Jul 20 '17)
0

answered Jul 19 '17

nelak gravatar image

updated Jul 19 '17

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')
link

Comments

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

mikerosz gravatar imagemikerosz (Jul 19 '17)

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 (Jul 19 '17)

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

mikerosz gravatar imagemikerosz (Jul 19 '17)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Jul 19 '17

Seen: 2,523 times

Last updated: Jul 19 '17