Python Forum
read multiple .xlsx files and text files in a directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read multiple .xlsx files and text files in a directory
#5
(Jun-02-2017, 11:14 AM)BNB Wrote:
#!/usr/bin/python

import os
from openpyxl.reader.excel import load_workbook
import csv

I am not sure why are you using openpyxl.reader.excel, I just checked a code I've written several week ago
from openpyxl import Workbook, load_workbook
Works just fine.  

wb.get_sheet_by_name causes exception if the sheet with that name does not exist - but I guess that is not your problem.

PS I am not sure why, but it is recommended to open csv files with newline='' argument

Another thing - you are collecting the same data for each Excel file you find. It is sort of inefficient. What exactly are you trying to do?
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: read multiple .xlsx files and text files in a directory - by volcano63 - Jun-06-2017, 02:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best fit for SVG files chihuahua998 3 983 May-04-2025, 09:25 AM
Last Post: cohik
  Copying Data from Multiple XLS Files to a Cumulative Master File Martijn 3 1,292 Apr-05-2025, 05:07 AM
Last Post: Pedroski55
  header files (python3-dev) ZZBBD 3 1,399 Aug-04-2024, 06:49 PM
Last Post: markjohn8348
  Import multiple CSV files into pandas Krayna 0 2,332 May-20-2021, 04:56 PM
Last Post: Krayna
  Python - Pandas writing blank files to file tdunphy 0 2,581 Jan-14-2021, 12:11 AM
Last Post: tdunphy
  Most Compatible Text Editor to Handle Large Files? Robotguy 2 3,356 Aug-18-2020, 03:51 PM
Last Post: FortyTwo
  Creating many csv files from Pandas EMA 0 2,184 Jul-26-2020, 06:39 PM
Last Post: EMA
  Loading multiple JSON files to create a csv 0LI5A3A 0 2,843 Jun-28-2020, 10:35 PM
Last Post: 0LI5A3A
  Binning data to files Kappel 4 3,594 Jun-22-2020, 06:25 PM
Last Post: Kappel
  Filter rows by multiple text conditions in another data frame i.e contains strings an Pan 0 2,700 Jun-09-2020, 06:05 AM
Last Post: Pan

Forum Jump:

User Panel Messages

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