This is a simple code for transferring Excel
file to CSV
file.
Then read the data in it.
- Error.py:
- Error: An exception for error in it
- CSVReader.py:
- CSVFileName: An Enum object, which list all of the sheet name, you could directly read each csv by its name
- CSVColumnName: An Enum object, which list all of the column you might needed
- CSVReader:
- init method need to pass
filename
, which is the .CSV file - Use
getColumn(columnName)
function to get all of the data in this column, (NOTE: this function also formatting the data in it, all of the duplicate & empty elements will be removed) - Use
getDataSource()
function to get all of the data in this file
- init method need to pass
- generateCSV.py
- Directly call
Autogenerator('TextExcel.xlsx')
(Your file name) is okay
- Directly call
After installing python, directly run python3 generateCSV.py
(My environment is Python3.6) would be okay.
Here is the snapshot of my TextExcel.xlsx
Excel:
Here is the output:
HealthyFood
Weather
HealtyFood Sheet:
[{'Name': 'Orange', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Grapefruit', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Mandarins', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Nectarines', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Apricots', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Peaches', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Bananas', 'Types': 'Tropical and exotic', 'Category': 'Fruit'}, {'Name': 'Mangoes', 'Types': 'Tropical and exotic', 'Category': 'Fruit'}, {'Name': 'Watermelons', 'Types': 'Melons', 'Category': 'Fruit'}, {'Name': 'Lettuce', 'Types': 'Leafy Green', 'Category': 'Vegetables'}, {'Name': 'Cabbage', 'Types': 'Cruciferous', 'Category': 'Vegetables'}, {'Name': 'Spinach', 'Types': 'Leafy Green', 'Category': 'Vegetables'}, {'Name': 'Pumpkin', 'Types': 'Marrow', 'Category': 'Vegetables'}, {'Name': 'Cucumber', 'Types': 'Marrow', 'Category': 'Vegetables'}, {'Name': 'Potato', 'Types': 'Root', 'Category': 'Vegetables'}, {'Name': 'Sweet Potato', 'Types': 'Root', 'Category': 'Vegetables'}, {'Name': 'Onion', 'Types': 'Allium', 'Category': 'Vegetables'}]
[{'Name': 'Orange', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Grapefruit', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Mandarins', 'Types': 'Citrus', 'Category': 'Fruit'}, {'Name': 'Nectarines', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Apricots', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Peaches', 'Types': 'Stone Fruit', 'Category': 'Fruit'}, {'Name': 'Bananas', 'Types': 'Tropical and exotic', 'Category': 'Fruit'}, {'Name': 'Mangoes', 'Types': 'Tropical and exotic', 'Category': 'Fruit'}, {'Name': 'Watermelons', 'Types': 'Melons', 'Category': 'Fruit'}, {'Name': 'Lettuce', 'Types': 'Leafy Green', 'Category': 'Vegetables'}, {'Name': 'Cabbage', 'Types': 'Cruciferous', 'Category': 'Vegetables'}, {'Name': 'Spinach', 'Types': 'Leafy Green', 'Category': 'Vegetables'}, {'Name': 'Pumpkin', 'Types': 'Marrow', 'Category': 'Vegetables'}, {'Name': 'Cucumber', 'Types': 'Marrow', 'Category': 'Vegetables'}, {'Name': 'Potato', 'Types': 'Root', 'Category': 'Vegetables'}, {'Name': 'Sweet Potato', 'Types': 'Root', 'Category': 'Vegetables'}, {'Name': 'Onion', 'Types': 'Allium', 'Category': 'Vegetables'}]
Weather Sheet:
[{'Location': 'Chicago', 'Weather Forecasts': 'Cloudy'}, {'Location': 'London', 'Weather Forecasts': 'Sunny'}, {'Location': 'Tbilisi', 'Weather Forecasts': 'Sunny'}, {'Location': 'Dakar', 'Weather Forecasts': 'Cloudy'}, {'Location': 'San Jose', 'Weather Forecasts': 'Rainy'}]
[{'Location': 'Chicago', 'Weather Forecasts': 'Cloudy'}, {'Location': 'London', 'Weather Forecasts': 'Sunny'}, {'Location': 'Tbilisi', 'Weather Forecasts': 'Sunny'}, {'Location': 'Dakar', 'Weather Forecasts': 'Cloudy'}, {'Location': 'San Jose', 'Weather Forecasts': 'Rainy'}]