示例#1
0
        public void HeaderTextEmptyOrNull()
        {
            string dataField = "DataField";
            AdapterBoundField <int> field = new AdapterBoundField <int>(dataField);

            Assert.AreEqual(dataField, field.HeaderText, "HeaderText property not assigned should return DataField");
        }
示例#2
0
        public void OnBoundField_CellDataBoundCalled()
        {
            XlsDocument doc   = new XlsDocument();
            Worksheet   sheet = doc.Workbook.Worksheets.Add("Test");
            Row         row   = sheet.Rows.AddRow(1);
            Cell        cell  = sheet.Cells.Add(1, 1);

            AdapterBoundField <int> field = new AdapterBoundField <int>("test");

            field.CellDataBound = TestCellDataBound;
            field.OnBoundField(this, cell, row, 50);


            Assert.IsNotNull(_storedArgs, "event not called");
            Assert.IsNotNull(_storedSender, "event not called");
            Assert.AreEqual(this, _storedSender);
            Assert.AreEqual(50, _storedArgs.DataItem);
            Assert.AreEqual(cell, _storedArgs.Cell);
            Assert.AreEqual(row, _storedArgs.Row);
        }
示例#3
0
        public void CreateSpreadsheetWithBoldHeadersAndCallback()
        {
            DataSourceConverter <DataRow> converter = new DataSourceConverter <DataRow>();

            converter.Fields.Add(new AdapterBoundField <DataRow>("Name", "Character Name"));
            AdapterBoundField <DataRow> ageField = new AdapterBoundField <DataRow>("Age");

            // Create a delegate on the field that handles populating each row
            // this delegate is called for each row for the field in the data
            ageField.CellDataBound += delegate(object sender, AdapterFieldEventArgs <DataRow> args)
            {
                args.Cell.Value = String.Format("{0} is {1} Years Old", args.DataItem["Name"], args.DataItem["Age"]);
            };

            converter.Fields.Add(ageField);
            converter.HeaderDataBound += DataSourceConverter <DataRow> .BoldAllCells;
            XlsDocument doc = new XlsDocument();

            converter.CreateWorksheet(doc, _data, "Testing");

            // validate worksheet is created
            Assert.AreEqual(1, doc.Workbook.Worksheets.Count);
            Assert.AreEqual(_data.Rows.Count + 1, doc.Workbook.Worksheets[0].Rows.Count);

            // validate header row
            Assert.AreEqual("Character Name", doc.Workbook.Worksheets[0].Rows[1].CellAtCol(1).Value);
            Assert.IsTrue(doc.Workbook.Worksheets[0].Rows[1].CellAtCol(1).Font.Bold);
            Assert.AreEqual("Age", doc.Workbook.Worksheets[0].Rows[1].CellAtCol(2).Value);
            Assert.IsTrue(doc.Workbook.Worksheets[0].Rows[1].CellAtCol(2).Font.Bold);

            ushort i = 2;

            foreach (DataRow row in _data.Rows)
            {
                Assert.AreEqual(row["Name"], doc.Workbook.Worksheets[0].Rows[i].CellAtCol(1).Value);
                Assert.AreEqual(String.Format("{0} is {1} Years Old", row["Name"], row["Age"]),
                                doc.Workbook.Worksheets[0].Rows[i].CellAtCol(2).Value);
                i++;
            }
        }