-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcel.py
34 lines (29 loc) · 1002 Bytes
/
Excel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Author: Jose Canahui
import pandas as pd
import os.path
class Excel():
def __init__(self, fileName):
super().__init__()
self.fileName = self.__getFile(fileName)
def read(self, columnName=None):
df = pd.read_excel(self.fileName, "Sheet1")
if columnName is None:
imageURLs = df.as_matrix()
else:
imageURLs = df[columnName].tolist()
if self.__checkString(imageURLs):
return imageURLs
def __getFile(self, fileName):
if os.path.isfile(fileName):
return fileName
elif os.path.isfile(fileName + ".xlsx"):
return (fileName + ".xlsx")
else:
print("File {} does not exist.".format(fileName))
exit(1)
def __checkString(self, imageURLs):
if isinstance(imageURLs[0], str):
return True
else:
print("Looks like the file has multiple columns, please specify the column to use.")
exit(0)