Example #1
0
        private void OnGUI()
        {
            EditorGUIUtility.labelWidth = 200;

            GUILayout.Label($"Workbook Settings for {_workbooks.Length} workbook(s)", EditorStyles.boldLabel);

            GUILayout.Space(25);
            GUILayout.Label("Checking this, will prefix all import assets with the workbook name", EditorStyles.boldLabel);
            PrefixAssetNames = EditorGUILayout.Toggle("Prefix Asset Names", PrefixAssetNames);

            GUILayout.Space(50);
            if (GUILayout.Button("Generate Importer"))
            {
                SetupWorkbooks();
                ExcelProcessor.Process(_workbooks);
                Close();
            }
        }
Example #2
0
        public async Task <ExcelResult> Get(
            IFormFile file,
            [FromForm(Name = "config")] string configJson)
        {
            var config = JsonConvert.DeserializeObject <ExcelConfig>(configJson);

            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            var path     = Path.Combine(tempPath, file.FileName);

            Directory.CreateDirectory(tempPath);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await file.CopyToAsync(stream);

                stream.Close();
                var result = processor.Process(path, config);
                Directory.Delete(tempPath, true);
                return(result);
            }
        }
Example #3
0
        public void Process_ShouldProcessFiles(string fileName)
        {
            //Given
            var processor = new ExcelProcessor(Enumerable.Empty <Validator>());
            //When
            var config = new API.Models.ExcelConfig
            {
                SheetName = "one_row",
                Fields    = new List <FieldConfig>
                {
                    new FieldConfig {
                        Index = 0
                    },
                    new FieldConfig {
                        Index = 1
                    },
                    new FieldConfig {
                        Index = 2, Type = "numeric"
                    },
                    new FieldConfig {
                        Index = 3
                    },
                }
            };

            var result = processor.Process(fileName, config);
            //Then

            var    firstItem = result.Json.First();
            var    name      = ((dynamic)firstItem).Name;
            double age       = ((dynamic)firstItem).Age;

            Assert.Equal("Kevin", name);
            Assert.Equal(10, age);
            result.Errors.Should().BeEmpty();
        }