using pandas to read old Excel files in xls (not xlsx) - xls

how can I use pandas to read an old Excel file in XLS format?
df = pd.read_excel("P:\product-screener.xls")
Pandas seems to works with XLSX files very well, but not the old XLS (Microsoft Excel 97-2003 Worksheet).
Thank you in advance for your help!

Related

Read sheet names from a xlsb file

I've been trying to read xlsb files into R.
I've tried using excel.link and readxlsb packages and they do work for reading the file but i also need to read the sheet names.
For a normal xlsx i would go gor GetSheets but it does not work for XLSB.
Any suggestion?
Thanks

Why Unicodes get converting from excel file to r data frame

I have excel file with unicode characters (like Korean and Japan language), when i load it from excel file to r data frame it's converting to some codes. For example
Excel Source Column
values=KR|512207456|투비씨엔씨(주)
After load the excel file to
DF = KR|512207456|<U+D22C><U+BE44><U+C528><U+C5D4><U+C528>(<U+C8FC>)
I did lot of google to find the solution, unfortunately not able to find any solution. Any help would be highly appreciated.

Importing .xls file that is saved as *.htm, *.html as it is saved on the backend

I have a requirement where I have to import an .xls file which is saved as .*htm, .*html.
How do we load this inside R in a data frame. The data is present in Sheet1 starting from Row Number 5. I have been struggling with this by trying to load it using xlsx package and readxl package. But neither of them worked, because the native format of the file is different.
I can't edit and re-save the file manually as .xlsx, as it cannot be automated.
Also to note, saved it as a .xlsx file and it works fine. But that's not what I need.
Kindly help me with this.
Try the openxlsx package and its function read.xlsx. If that doesn't work, you could programmatically rename the file as described for example here, and then open it using one of these excel packages.
Your file could be in xls format instead of xlsx, have you tried read_xls() function from readxl? Or it could also be in text format, in this case read.table() or fread() from data.tableshould work. The fact that it works after saving the file in xlsx strongly suggests that it is not formatted as an xlsx to begin with.
Hope this helps.

Load 93-2003 Excel Worksheet (.XLS) into Excel R

I am trying to load excel worksheets into R using the xlsx package. The files are saved as old 97-2003 worksheets (the endings are .XLS) for newer files the code below worked fine.
df <- read.xlsx(filename,sheetIndex=2)
However, when I try on the older files I get the error message:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)
I know the error has to do with the files being in the older format but I do not know how to solve this. I have too many files to manually update each one.
Any suggestions would be greatly appreciated!
P.S. apologies for not adding a fully reproducible example. I do not know how to attach files to go along with my question.
Package readxl is one way to read Excel files. The advantage is that there is no dependy to Java or other.
Your code would be
library(readxl)
df <- read_excel(path = filepath, sheet =2)
It should work with XLS and XLSX files.
Use excel_sheets(filepath) to get the name of sheets to import and pass them through the sheet arg of read_excel. You can do a loop with that if it helps you.

how to write multiple dataframe to multiple sheet of one csv excel file in R?

I am trying to write multiple dataframe to a single csv formated file but each in a different sheet of the excel file:
write.csv(dataframe1, file = "file1.csv",row.names=FALSE)
write.csv(dataframe2, file = "file2.csv",row.names=FALSE)
is there any way to specify the sheet along with the csv file in this code and write them all in one file?
thank you in advance,
This is not possible. That is the functionality of csv to be just in one sheet so that you can view it either from notepad or any other such software. If you still try to write it would get over ridden. Just try to open a csv and open a new sheet and just write some values and save it. The values which were already there is erased. one excel file in csv format can have only one sheet.
The xlsx and XLConnect packages will do the trick as well.

Resources