示例#1
0
 public void CreateNew_AddNewSheet_WithoutCreate_Exception_Test()
 {
     using (var con = new ExcelAdapter("TestData\\The New File.xlsx", op => op.AutoCreateNewFile = false))
     {
         con.AddNewSheet();
     }
 }
示例#2
0
        public void ReadDataFromEmptyHeader_Test()
        {
            using (var con = new ExcelAdapter("TestData\\The Empty SheetData.xlsx", op => op.AutoCreateNewFile = true))
            {
                for (var i = 0; i < _data.Columns.Count; i++)
                {
                    _data.Rows[0][i] = string.Empty;
                }

                var name = con.AddNewSheet(_data, true);
                var dt   = con[name].ToDataTable(true);
                Assert.AreEqual(_data.Rows.Count - 1, dt.Rows.Count);
            }
        }
示例#3
0
        public void AddNewSheet_WithDataTable()
        {
            const string fileName = "TestData\\The New Data File.xlsx";

            using (var con = new ExcelAdapter(fileName, op =>
            {
                op.AutoCreateNewFile = true;
                op.OpenMode = OpenMode.Editable;
            }))
            {
                var name = con.AddNewSheet(_data);
                Assert.IsTrue(con.SheetNames.Length > 3);

                var sheetData = con[name].ToDataTable(true);
                Assert.IsNotNull(sheetData);
                Assert.IsTrue(sheetData.Rows.Count == _data.Rows.Count);
                Assert.IsTrue(sheetData.Columns.Count == _data.Columns.Count);
            }
        }
示例#4
0
        public void Write_Data_To_Excel_Test()
        {
            using (var dt = new CsvAdapter("TestData\\Customers.csv").Read())
            {
                using (var con = new ExcelAdapter("TestData\\The_TestOf_WriteData_Customers.xlsx", op =>
                {
                    op.OpenMode = OpenMode.Editable;
                    op.AddDefaultSheets = false;
                }))
                {
                    con.AddNewSheet(dt);
                    con.Save();
                }

                using (var con = new ExcelAdapter("TestData\\The_TestOf_WriteData_Customers.xlsx"))
                {
                    using (var newtb = con.ReadData(dt.TableName).ToDataTable(true))
                    {
                        Assert.IsTrue(dt.Rows.Count == newtb.Rows.Count);
                        Assert.IsTrue(dt.Columns.Count == newtb.Columns.Count);
                    }
                }
            }
        }
示例#5
0
        public void CreateNew_1Sheet_Test()
        {
            const string fileName = "TestData\\The New 1 Sheets File.xlsx";

            using (var con = new ExcelAdapter(fileName, op =>
            {
                op.OpenMode = OpenMode.Editable;
                op.AutoCreateNewFile = false;
                op.AddDefaultSheets = false;
            }))
            {
                con.Create();
                con.AddNewSheet();

                Assert.IsNotNull(con.SpreadsheetDocument);
            }

            Assert.IsTrue(File.Exists(fileName));

            using (var con = new ExcelAdapter(fileName))
            {
                Assert.AreEqual(con.SheetNames.Length, 1);
            }
        }