Python Forum
Trouble reading files using pyexcel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble reading files using pyexcel
#1
I was able to fix the issue, I realized I accidentally type casted a variable! In terms of my other question though: should I use the
with open(...)
or would that not be appropriate in this scenario?
------------------
Hi,

I'm having some trouble using the pyexcel library to read .xlsx files. I already installed the package to read .xlsx files through pip3 but whenever I try running printing out the values in a for loop, or anywhere for that matter, it keeps giving me an error. I've tried using other inbuilt methods such as .keys(), .values(), etc. but they all keep giving me errors as well. My other question is: would it be good practice to put my code in
with open('test.xlsx', mode='r'.....)
would it make sense to do that in this situation and if so how would I incorporate that properly?

I will leave my code and my error down below. If anyone could help me that would be gladly appreciated! :)

Here is the code:
import pyexcel as p

records = p.get_records(file_name="test.xlsx")

for row in records:
	print(f"{row['Cells']}")
The error:
Error:
print(f"{row['Cells']}") TypeError: string indices must be integers
Reply
#2
[EDIT] I just see that you are reffering to a row, not column. Is that what you want?

I don't have any experience with pyexcel. But have you tried to use index numbers instead of column names? The error message tells you need to use integers, so I assume the indexnumber of the column should work (typically starting from 0).
Reply
#3
(Feb-06-2021, 07:45 PM)Jeff900 Wrote: [EDIT] I just see that you are reffering to a row, not column. Is that what you want?

I don't have any experience with pyexcel. But have you tried to use index numbers instead of column names? The error message tells you need to use integers, so I assume the indexnumber of the column should work (typically starting from 0).

Thank you for the suggestions, I was able to solve it as I noticed that I accidentally typecasted one of the variables!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  trouble reading string/module from excel as a list popular_dog 0 386 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  Trouble with threading and reading variable from a different script Lembas 14 2,844 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Reading Multiple text Files in pyhton Fatim 1 1,886 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Trouble with reading csv file and putting it into a file Milfredo 3 2,218 Sep-04-2020, 05:30 AM
Last Post: Milfredo
  Reading txt files in ssh server. therenaydin 6 4,022 Aug-06-2020, 05:17 AM
Last Post: ndc85430
  How to stop the reading of files Laplace12 4 2,313 Jul-27-2020, 04:07 PM
Last Post: Gribouillis
  How can I speed up my openpyxl program reading Excel .xlsx files? deac33 0 3,363 May-04-2020, 08:02 PM
Last Post: deac33
  Trouble reading Excel file. Shembeginner 2 2,259 Apr-07-2020, 04:55 AM
Last Post: Shembeginner
  Other modules for reading audio files? jedzz 0 1,570 Mar-25-2020, 11:07 PM
Last Post: jedzz
  Error With Reading Files In Directory And Calculating Values chascp 2 2,381 Feb-15-2020, 01:57 PM
Last Post: chascp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020