| Reference | Downloads | Github

XLRD on Pavlovia

URL of experiment: /

Description of the problem: How to import excel file on Pavlovia? Xlrd funtion is out of questions since I can’t import python libraries. Here is the code that I use in Builder:

import xlrd

infile = "file_name.xlsx"
workbook = xlrd.open_workbook(infile)
sheet = workbook.sheet_by_index(0)
for rowx in range (list_start, list_end):
    row = sheet.row_values(rowx)

I know I have to replace “append” with “push”, but I cannot seem to find an alternative for importing the file. Thank you.

Check out this thread and another thread they cite in there.

Thank you sal! I am still having trouble with this, although I followed the instructions. I get the following error: “Cannot read property ‘0’ of undefined”. So I guess nothing gets written in the list “stimData”.

Here is the piece of code:

testfile = 'additional_files/EIM_Sentence_List1.csv';
varNames = ["Item Number", "Structure", "TestSentList1", "TargetWord", "AudioFile","BeliefAnswer","twOnset","gram/ungram"];
stimData = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
    extraInfo: expInfo, originPath: undefined,
    trialList: testfile,
    seed: undefined, name: 'stimData'


Hi @pavle, where are you putting this piece of code? In the JS side or the python side? Can you take a screenshot or show what you have in both the PY and JS side of the code component?

I am not sure how this is supposed to work. I did make some progress, but it seems to be in vain. This is my test study made so that I can exercise importing and displaying data. As you can see, text_stim gets assigned value “Anja”, but nonetheless, the text that appears on the screen is “Hello World”. I tried displaying another text (variable kr) that gets declared its value at the very beginning of the study, but the same thing happens.

Okay, in the builder interface you should have a code component in builder that is defining the text stimuli kr and text_stim. It should have two panes, with python code on the left and javascript on the right. Make sure you have the code type set to “Both” so that you can edit them independently.

You don’t want to add the code to the py or js files directly, since any new changes will be overridden by builder each time you save. Could I see that?

I’m so sorry, I somehow missed this notification! I had this same problem at first. You probably already figured it out, but what you’re calling stimData is actually the file itself, but not the list of stimuli. After that bit of code where you define stimData, you need a line that actually grabs the stimuli from the file. So let’s say you’re naming your list of stimuli stimuli. You will want to add the line var stimuli = stimData.trialList;.

I also see you have nReps set to 1. I believe you want that to be the number of columns in your excel file. In my code, I have var numCat = varNames.length; before defining stimData and then nReps: numCat. I’m not 100% sure why or if you actually need this, but I remember it fixing something at some point when I was working on my code so I figured I’d let you know.