
NOTICE: All information contained herein is, and remains
the property of TechnoCore.
The intellectual and technical concepts contained
herein are proprietary to TechnoCore and dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from TechnoCore.
The ObjImportApi class in ObjDataImportXlsx.py is designed to handle modern Excel (.xlsx) files by converting them to CSV format for further processing. It extends the ObjImportCSV.ObjImportApi class, leveraging its CSV handling capabilities after the conversion.
.xlsx files into .csv files..xlsx file to a specified processed directory, with an option to either overwrite existing files or rename them with a timestamp.__init__(self, DB=0)Initializes the ObjImportApi object, inheriting from ObjImportCSV.ObjImportApi.
PrepFile(self, Filename)This is the core method of the class. It takes an .xlsx filename as input, reads the content of the specified sheet, and writes it to a new .csv file. After the conversion, it moves the original .xlsx file to the processed directory.
The method handles:
.xlsx file using xlrd..xlsx file, with options for overwriting or renaming.# Create an instance of the importer
xlsx_importer = ObjImportApi()
# Set the necessary attributes
xlsx_importer._Directory = "/path/to/files"
xlsx_importer._Processeddir = "/path/to/processed/files"
xlsx_importer._Overwrite = "N" # Do not overwrite, rename with timestamp
# Prepare the XLSX file (converts it to CSV)
csv_filename = xlsx_importer.PrepFile("data.xlsx")
# Now, you can use the methods from the parent CSV importer class
# to open and process the newly created CSV file.
xlsx_importer.OpenFile(csv_filename)
# Get columns and rows
columns = xlsx_importer.ColumnList()
print("Columns:", columns)
while True:
row = xlsx_importer.NextRow()
if row == 'EOF':
break
print("Row data:", row)
xlsx_importer.CloseFile()