Last active
August 2, 2020 16:10
-
-
Save chuongmep/fd78488691ded852a22b49ff9ad1923a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import clr | |
clr.AddReferenceToFileAndPath(r'C:\Users\chuon\Downloads\Read From Excel\Read From Excel\EPPlus.dll') | |
from OfficeOpenXml import ExcelPackage | |
clr.AddReference('System.IO') | |
from System.IO import FileInfo | |
class ExcelData(object): | |
def __init__(self, path_to_work_book): | |
excel_package = ExcelPackage(FileInfo(path_to_work_book)) | |
work_book = excel_package.Workbook | |
self._first_list = work_book.Worksheets[1] | |
def get_data(self): | |
data = [] | |
rows_count = self._first_list.Dimension.End.Row | |
columns_count = self._first_list.Dimension.End.Column | |
for row_num in range(1, rows_count + 1): | |
row = [] | |
for column_num in range(1, columns_count + 1): | |
row.append(self._first_list.Cells[row_num, column_num].Text) | |
data.append(row) | |
return data | |
path = r"C:\Users\chuon\Downloads\Read From Excel\Read From Excel\testbook.xlsx" | |
excel_data = ExcelData(path_to_work_book=path) | |
data = excel_data.get_data() | |
OUT = data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment