Ejemplo n.º 1
0
        public void ExcelPackageHelper_SetColumnByIndex_GetColumnByIndex()
        {
            //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.SetColumnByIndex(worksheet, 1, col1, skipFirstRow: false);
            ExcelPackageHelper.SetColumnByIndex(worksheet, 2, col2, skipFirstRow: false);
            List <object> result1 = ExcelPackageHelper.GetColumnByIndex(worksheet, 1, skipFirstRow: false);
            List <object> result2 = ExcelPackageHelper.GetColumnByIndex(worksheet, 2, 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]);
            }
        }