From 3688287e6d02f29aacce8d99704fd91724fa4898 Mon Sep 17 00:00:00 2001 From: "florentin.luce" Date: Wed, 14 Feb 2024 16:20:04 +0100 Subject: [PATCH] csv delimiter --- operators/spreadsheet.py | 10 ++++++++-- ui/properties.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/operators/spreadsheet.py b/operators/spreadsheet.py index 9e18355..e2ccd17 100644 --- a/operators/spreadsheet.py +++ b/operators/spreadsheet.py @@ -125,8 +125,14 @@ class VSETB_OT_spreadsheet_from_file(Operator): filepath = Path(self.filepath) if filepath.suffix.lower() == '.csv': - with open(filepath, newline=separator) as csvfile: - rows = list(csv.reader(csvfile, delimiter=delimiter)) + if len(delimiter) == 1: + with open(filepath, newline=separator) as csvfile: + rows = list(csv.reader(csvfile, delimiter=delimiter)) + else: # Auto detect + with open(filepath, 'r', newline="") as csvfile: + dialect = csv.Sniffer().sniff(csvfile.read(1024), delimiters=delimiter) + csvfile.seek(0) + rows = list(csv.reader(csvfile, dialect)) elif filepath.suffix.lower() == '.xlsx': try: diff --git a/ui/properties.py b/ui/properties.py index 51b4770..36f1273 100644 --- a/ui/properties.py +++ b/ui/properties.py @@ -180,7 +180,7 @@ class SpreadsheetExport(PropertyGroup): class SpreadsheetImport(PropertyGroup): #use_custom_cells: BoolProperty(default=False) separator : StringProperty(default='\\n') - delimiter : StringProperty(default=';') + delimiter : StringProperty(default=',;:') use_custom_name : BoolProperty(default=False) custom_name : EnumProperty(items=get_custom_name_items, description='Use a custom name for asset using a metadata value')