Loads an XLSX file into memory and exposes each worksheet as a table of string values.
Inheritance: IDisposable
Esempio n. 1
0
        public void TestTypeCreation()
        {
            //Read a test excel file as a byte array
            FileStream fileStream = new FileStream(testFilePath, FileMode.Open, FileAccess.Read);
            ExcelFile file = new ExcelFile(fileStream, dynamicProvider);

            //verify the types were created successfully.
            Assert.AreEqual("Data", ModelContext.Current.GetModelType("Data").Name);
            Assert.AreEqual("SecondData", ModelContext.Current.GetModelType("SecondData").Name);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads an <see cref="ExcelFile"/> from the specified stream as an <see cref="ITable"/> instance.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static ITable Read(Stream file, TableMapping mapping = null)
        {
            var excelFile = new ExcelFile(file);

            // Infer or load mappings from the spreadsheet if they are not specified explicitly
            if (mapping == null)
                throw new NotImplementedException("Add support for inferring the mappings for single sheet imports or loading the mappings from a manifest sheet.");

            return new Table(excelFile, mapping, null);
        }
Esempio n. 3
0
        public void TestFirstColumnIsId()
        {
            //Read a test excel file as a byte array
            FileStream fileStream = new FileStream(testFilePath, FileMode.Open, FileAccess.Read);
            ExcelFile file = new ExcelFile(fileStream, dynamicProvider);

            //verify the types were created successfully.
            Assert.AreEqual("100024", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(0).Id );
            Assert.AreEqual("101707", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(1).Id);
            Assert.AreEqual("101708", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(2).Id);
            Assert.AreEqual("101713", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(3).Id);
        }
Esempio n. 4
0
        public void TestInstanceDataCreation()
        {
            //Read a test excel file as a byte array
            FileStream fileStream = new FileStream(testFilePath, FileMode.Open, FileAccess.Read);
            ExcelFile file = new ExcelFile(fileStream, dynamicProvider);

            //verify the first instance was created
            //need to use the translated property name
            Assert.AreEqual("KELLER", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(0)["_LastName"]);
            Assert.AreEqual("RHONDA", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(0)["_FirstName"]);
            Assert.AreEqual("513826", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(0)["_Customer__"]);
            Assert.AreEqual("100024", file.GetInstances(ModelContext.Current.GetModelType("Data")).ElementAt(0)["_Location__"]);
        }
Esempio n. 5
0
        public void TestTypeStorage()
        {
            //Read a test excel file as a byte array
            FileStream fileStream = new FileStream(testFilePath, FileMode.Open, FileAccess.Read);
            ExcelFile file = new ExcelFile(fileStream, dynamicProvider);

            //verify the types were created successfully.
            //and stored in the file object correctly
            Assert.AreEqual("Data", file.GetTypesGenerated().ElementAt(0).Name);
            Assert.AreEqual("SecondData", file.GetTypesGenerated().ElementAt(1).Name);
        }
Esempio n. 6
0
            internal Table(ExcelFile file, TableMapping mapping, Table parent)
            {
                this.file = file;
                this.Name = mapping.Name;
                this.Identifier = mapping.Identifier;
                this.Parent = parent;
                parent.children.Add(this);
                this.ParentIdentifier = mapping.ParentIdentifier;

                // Find the specified worksheet
                var sheet = file.workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name.Value == mapping.Name);
                if (sheet == null)
                    throw new ArgumentException("A worksheet named '" + mapping.Name + "' was not found.");
                this.worksheet = ((WorksheetPart)file.spreadsheet.WorkbookPart.GetPartById(sheet.Id)).Worksheet;

                // Load child tables
                foreach (var child in mapping.Children)
                    children.Add(new Table(file, child, this));
            }