Browse Source

[importer] adding xlsx file type for importer

ayush.goyal 4 years ago
parent
commit
34950c37ab

+ 14 - 7
desktop/libs/indexer/src/indexer/api3.py

@@ -124,13 +124,20 @@ def guess_format(request):
   file_format = json.loads(request.POST.get('fileFormat', '{}'))
   file_format = json.loads(request.POST.get('fileFormat', '{}'))
 
 
   if file_format['inputFormat'] == 'localfile':
   if file_format['inputFormat'] == 'localfile':
-    format_ = {
-      "quoteChar": "\"",
-      "recordSeparator": '\\n',
-      "type": "csv",
-      "hasHeader": True,
-      "fieldSeparator": ","
-    }
+    path = urllib_unquote(file_format["path"])
+    if 'xlsx' in path:
+      format_ = {
+        "type": "xlsx",
+        "hasHeader": True
+      }
+    else:
+      format_ = {
+        "quoteChar": "\"",
+        "recordSeparator": '\\n',
+        "type": "csv",
+        "hasHeader": True,
+        "fieldSeparator": ","
+      }
 
 
   elif file_format['inputFormat'] == 'file':
   elif file_format['inputFormat'] == 'file':
     path = urllib_unquote(file_format["path"])
     path = urllib_unquote(file_format["path"])

+ 11 - 1
desktop/libs/indexer/src/indexer/file_format.py

@@ -50,7 +50,8 @@ IMPORT_PEEK_NLINES = 20
 def get_format_types():
 def get_format_types():
   formats = [
   formats = [
     CSVFormat,
     CSVFormat,
-    JsonFormat
+    JsonFormat,
+    XLSXFormat
   ]
   ]
 
 
   if ENABLE_SCALABLE_INDEXER.get():
   if ENABLE_SCALABLE_INDEXER.get():
@@ -303,6 +304,15 @@ class ParquetFormat(FileFormat):
   _description = _("Parquet Table")
   _description = _("Parquet Table")
 
 
 
 
+class XLSXFormat(GrokkedFormat):
+  _name = "xlsx"
+  _description = _("XLSX File")
+  _args = [
+    CheckboxArgument("hasHeader", "Has Header")
+  ]
+  _extensions = ["xlsx"]
+
+
 class CSVFormat(FileFormat):
 class CSVFormat(FileFormat):
   _name = "csv"
   _name = "csv"
   _description = _("CSV File")
   _description = _("CSV File")

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -460,8 +460,8 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
       <!-- ko ifnot: createWizard.isGuessingFormat -->
       <!-- ko ifnot: createWizard.isGuessingFormat -->
       <h4>${_('Format')}</h4>
       <h4>${_('Format')}</h4>
       <div class="card-body">
       <div class="card-body">
-        <label data-bind="visible: (createWizard.prefill.source_type().length == 0 || createWizard.prefill.target_type() == 'index') &&
-            (createWizard.source.inputFormat() == 'file' || createWizard.source.inputFormat() == 'localfile' || createWizard.source.inputFormat() == 'stream')">
+        <label data-bind="visible: (createWizard.prefill.source_type().length > 0 && createWizard.prefill.target_type().length > 0) || ((createWizard.prefill.source_type().length == 0 || createWizard.prefill.target_type() == 'index') &&
+            (createWizard.source.inputFormat() == 'file' || createWizard.source.inputFormat() == 'localfile' || createWizard.source.inputFormat() == 'stream'))">
           <div>${_('File Type')}</div>
           <div>${_('File Type')}</div>
           <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName,
           <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName,
               optionsText: 'description', optionsValue: 'name'"></select>
               optionsText: 'description', optionsValue: 'name'"></select>