Ejemplo n.º 1
0
        private List <Task> LoadTasks(ExcelWorksheet worksheet)
        {
            List <string> ids          = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.IdColumn, skipFirstRow: true).Cast <string>().ToList();
            List <string> descriptions = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.DescriptionColumn, skipFirstRow: true).Cast <string>().ToList();
            List <string> statuses     = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.StatusColumn, skipFirstRow: true).Cast <string>().ToList();
            List <string> categories   = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.CategoryColumn, skipFirstRow: true).Cast <string>().ToList();
            List <string> createDates  = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.CreateDateColumn, skipFirstRow: true).Cast <string>().ToList();
            List <string> doneDates    = ExcelPackageHelper.GetColumnByChar(worksheet, columnLayout.DoneDateColumn, skipFirstRow: true).Cast <string>().ToList();

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < descriptions.Count; i++)
            {
                tasks.Add(new Task()
                {
                    Id          = (i < ids.Count && !String.IsNullOrEmpty(ids[i])) ? Int32.Parse(ids[i]) : 0,
                    Description = descriptions[i],
                    Status      = (i < statuses.Count) ? statuses[i] : "",
                    Category    = (i < categories.Count) ? categories[i] : "",
                    CreateDate  = (i < createDates.Count && !String.IsNullOrEmpty(createDates[i])) ? DateTime.Parse(createDates[i]) : DateTime.Now,
                    DoneDate    = (i < doneDates.Count && !String.IsNullOrEmpty(doneDates[i])) ? DateTime.Parse(doneDates[i]) : (DateTime?)null
                });
            }
            return(tasks);
        }
Ejemplo n.º 2
0
        public void ExcelPackageHelper_SetColumnByChar_GetColumnByChar()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <object>  col1      = new List <object>()
            {
                null, 123, "abc", "", new DateTime(1999, 3, 2)
            };
            List <object> col2 = new List <object>()
            {
                456, "", null, null, null, null, 789
            };

            //act
            ExcelPackageHelper.SetColumnByChar(worksheet, "A", col1, skipFirstRow: false);
            ExcelPackageHelper.SetColumnByChar(worksheet, "B", col2, skipFirstRow: false);
            List <object> result1 = ExcelPackageHelper.GetColumnByChar(worksheet, "A", skipFirstRow: false);
            List <object> result2 = ExcelPackageHelper.GetColumnByChar(worksheet, "B", skipFirstRow: false);

            //assert
            Assert.AreEqual(2, ExcelPackageHelper.CountColumns(worksheet));
            Assert.AreEqual(Math.Max(col1.Count, col2.Count), ExcelPackageHelper.CountRows(worksheet));
            for (int i = 0; i < col1.Count; i++)
            {
                Assert.AreEqual(col1[i], result1[i]);
            }
            for (int i = 0; i < col2.Count; i++)
            {
                Assert.AreEqual(col2[i], result2[i]);
            }
        }