Ejemplo n.º 1
0
        public void ExcelPackageHelper_AppendRow_GetRow()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <object>  row1      = new List <object>()
            {
                null, 123, "abc", "", new DateTime(1999, 3, 2)
            };
            List <object> row2 = new List <object>()
            {
                456, "", null, null, null, null, 789
            };

            //act
            ExcelPackageHelper.AppendRow(worksheet, row1);
            ExcelPackageHelper.AppendRow(worksheet, row2);
            List <object> result1 = ExcelPackageHelper.GetRow(worksheet, 1);
            List <object> result2 = ExcelPackageHelper.GetRow(worksheet, 2);

            //assert
            Assert.AreEqual(2, ExcelPackageHelper.CountRows(worksheet));
            Assert.AreEqual(Math.Max(row1.Count, row2.Count), ExcelPackageHelper.CountColumns(worksheet));
            for (int i = 0; i < row1.Count; i++)
            {
                Assert.AreEqual(row1[i], result1[i]);
            }
            for (int i = 0; i < row2.Count; i++)
            {
                Assert.AreEqual(row2[i], result2[i]);
            }
        }
Ejemplo n.º 2
0
        public void ExcelPackageHelper_CountColumns_FromRows()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <object>  rowA      = new List <object>()
            {
                "ColA", "ColB", "ColC"
            };
            List <object> rowB = new List <object>()
            {
                "ColA"
            };
            List <object> rowC = new List <object>()
            {
                "ColA", "ColB", "ColC", "ColD", "ColE"
            };

            //act
            ExcelPackageHelper.AppendRow(worksheet, rowA);
            ExcelPackageHelper.AppendRow(worksheet, rowB);
            ExcelPackageHelper.AppendRow(worksheet, rowC);
            int count = ExcelPackageHelper.CountColumns(worksheet);

            //assert
            Assert.AreEqual(5, count);
        }
Ejemplo n.º 3
0
        private void WriteConfigSheet(ExcelWorksheet worksheet)
        {
            ExcelPackageHelper.Clear(worksheet);
            ExcelPackageHelper.AppendRow(worksheet, new List <object>()
            {
                STATUS_NAME, ACTIVE_NAME, "", CATEGORY_NAME, "", ID_NAME
            });
            worksheet.Cells["A1:F1"].Style.Font.Bold = true;

            ExcelPackageHelper.SetColumnByChar(worksheet, "A", Statuses.Select(s => (object)s.Name).ToList(), skipFirstRow: true);
            ExcelPackageHelper.SetColumnByChar(worksheet, "B", Statuses.Select(s => (object)(s.Active ? IS_ACTIVE : IS_INACTIVE)).ToList(), skipFirstRow: true);
            ExcelPackageHelper.SetColumnByChar(worksheet, "D", Categories.Select(c => (object)c).ToList(), skipFirstRow: true);
            ExcelPackageHelper.SetColumnByChar(worksheet, "F", new List <object>()
            {
                (object)MaxId
            }, skipFirstRow: true);
        }
        public void WriteTask(ExcelWorksheet worksheet, Task task, bool active)
        {
            List <object> values = new List <object>()
            {
                task.Id,
                task.Description,
                task.Status,
                task.Category,
                task.CreateDateString
            };

            if (!active)
            {
                values.Add(task.DoneDateString);
            }

            ExcelPackageHelper.AppendRow(worksheet, values);
        }
        public static void WriteTaskHeaders(ExcelWorksheet worksheet, bool active)
        {
            List <object> values = new List <object>()
            {
                ID_HEADER,
                DESCRIPTION_HEADER,
                STATUS_HEADER,
                CATEGORY_HEADER,
                CREATE_DATE_HEADER
            };

            if (!active)
            {
                values.Add(DONE_DATE_HEADER);
            }

            ExcelPackageHelper.AppendRow(worksheet, values);
            worksheet.Cells["A1:F1"].Style.Font.Bold = true;
        }
Ejemplo n.º 6
0
        public void ExcelPackageHelper_CountRows_FromRows()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <string>  row       = new List <string>()
            {
                "ColA", "ColB", "ColC"
            };

            //act
            ExcelPackageHelper.AppendRow(worksheet, row);
            ExcelPackageHelper.AppendRow(worksheet, row);
            ExcelPackageHelper.AppendRow(worksheet, row);
            ExcelPackageHelper.AppendRow(worksheet, row);
            int count = ExcelPackageHelper.CountRows(worksheet);

            //assert
            Assert.AreEqual(4, count);
        }
Ejemplo n.º 7
0
        public void ExcelPackageHelper_SetColumnByHeader_GetColumnByHeader()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <string>  headers   = new List <string>()
            {
                "ColA", "ColB"
            };
            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.AppendRow(worksheet, headers);
            ExcelPackageHelper.SetColumnByHeader(worksheet, headers[0], col1);
            ExcelPackageHelper.SetColumnByHeader(worksheet, headers[1], col2);
            List <object> result1 = ExcelPackageHelper.GetColumnByHeader(worksheet, headers[0]);
            List <object> result2 = ExcelPackageHelper.GetColumnByHeader(worksheet, headers[1]);

            //assert
            Assert.AreEqual(headers[0], worksheet.Cells["A1"].Value.ToString());
            Assert.AreEqual(headers[1], worksheet.Cells["B1"].Value.ToString());
            Assert.AreEqual(2, ExcelPackageHelper.CountColumns(worksheet));
            Assert.AreEqual(Math.Max(col1.Count, col2.Count) + 1, 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]);
            }
        }
Ejemplo n.º 8
0
        public void ExcelPackageHelper_GetColumnCharForHeader()
        {
            //arrange
            ExcelPackage   package   = new ExcelPackage();
            string         name      = "Title";
            ExcelWorksheet worksheet = ExcelPackageHelper.AddWorksheet(package, name);
            List <string>  headers   = new List <string>()
            {
                "ColA", "ColB", "ColC"
            };

            //act
            ExcelPackageHelper.AppendRow(worksheet, headers);
            string a = ExcelPackageHelper.GetColumnCharForHeader(worksheet, headers[0]);
            string b = ExcelPackageHelper.GetColumnCharForHeader(worksheet, headers[1]);
            string c = ExcelPackageHelper.GetColumnCharForHeader(worksheet, headers[2]);
            string d = ExcelPackageHelper.GetColumnCharForHeader(worksheet, "Other");

            //assert
            Assert.AreEqual("A", a);
            Assert.AreEqual("B", b);
            Assert.AreEqual("C", c);
            Assert.IsNull(d);
        }