public void TestWriteSheetWithSheetName()
        {
            var dt = GetTestData();

            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "onesheetfile.xlsx");
            NPOIOperator oper = new NPOIOperator(dataFilePath, true);

            var writeLineNumber = oper.WriteSheet("Sheet3", dt, true);
            Assert.AreEqual(4, writeLineNumber);

            var readDT = oper.ReadSheet("Sheet3", true);
            Assert.AreEqual(3, readDT.Rows.Count);
        }
 public void TestReadSheetWithCellType()
 {
     string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "forread.xlsx");
     NPOIOperator oper = new NPOIOperator(dataFilePath, true);
     var sheet = oper.GetSheet("Sheet1");
     var readDT = oper.ReadSheet(sheet, true, true, 0);
     Assert.AreEqual(6, readDT.Rows.Count);
     Assert.AreEqual("猴六", readDT.Rows[3]["姓名"].ToString());
     Assert.AreEqual(new DateTime(1988, 3, 14), readDT.Rows[3]["出生日期"]);
 }
        public void TestFlushWithTemplate()
        {
            var dt = GetTestData();

            string templateFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "template.xlsx");

            var fileName = "template" + Guid.NewGuid().ToString() + ".xlsx";
            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", fileName);
            NPOIOperator oper = new NPOIOperator(templateFilePath, dataFilePath, true);
            var sheet = oper.GetSheet("Sheet1");
            oper.WriteContent(sheet, dt, 3, 1);
            oper.Flush();

            try
            {
                NPOIOperator oper2 = new NPOIOperator(dataFilePath, true);
                var sheet2 = oper2.GetSheet("Sheet1");
                var dt2 = oper2.ReadSheet(sheet, true, true, 2, 1);

                Assert.AreEqual(3, dt2.Rows.Count);
                Assert.AreEqual("李四", dt2.Rows[1]["姓名"]);
                Assert.AreEqual(new DateTime(2000, 8, 8), dt2.Rows[1]["出生日期"]);
            }
            finally
            {
                File.Delete(dataFilePath);
            }
        }
 public void TestReadSheetWithSencondLine()
 {
     string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "forread.xlsx");
     NPOIOperator oper = new NPOIOperator(dataFilePath, true);
     var sheet = oper.GetSheet("Sheet1");
     var readDT = oper.ReadSheet(sheet, false, 1);
     Assert.AreEqual(6, readDT.Rows.Count);
     Assert.AreEqual("猴六", readDT.Rows[3]["列2"].ToString());
     Assert.AreEqual("14-3月-1988", readDT.Rows[3]["列5"]);
 }
        public void TestReadSheetWithNameAndNoTitle()
        {
            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "forread.xlsx");
            NPOIOperator oper = new NPOIOperator(dataFilePath, true);

            var readDT = oper.ReadSheet("Sheet1", false);
            Assert.AreEqual(7, readDT.Rows.Count);
            Assert.AreEqual("猴六", readDT.Rows[4]["列2"].ToString());
            Assert.AreEqual("14-3月-1988", readDT.Rows[4]["列5"]);
        }
        public void TestWriteCell()
        {
            var dt = GetTestData();

            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "onesheetfile.xlsx");
            NPOIOperator oper = new NPOIOperator(dataFilePath, true);

            var sheet = oper.GetSheet("Sheet3");

            var row = sheet.CreateRow(0);

            var cell1 = row.CreateCell(0);
            oper.WriteCell(cell1, dt.Rows[1]["姓名"], CellDataType.Text);

            var cell2 = row.CreateCell(1);
            oper.WriteCell(cell2, dt.Rows[1]["性别"], CellDataType.Int);

            var readDT = oper.ReadSheet(sheet, false, true, 0);
            Assert.AreEqual(1, readDT.Rows.Count);
            Assert.AreEqual("李四", readDT.Rows[0]["列1"].ToString());
            Assert.AreEqual(0, readDT.Rows[0]["列2"]);
        }
        public void TestWriteRow()
        {
            var dt = GetTestData();

            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "onesheetfile.xlsx");
            NPOIOperator oper = new NPOIOperator(dataFilePath, true);

            var sheet = oper.GetSheet("Sheet3");
            var row = sheet.CreateRow(1);
            oper.WriteRow(row, dt.Columns, dt.Rows[1]);

            var readDT = oper.ReadSheet(sheet, false, 1);
            Assert.AreEqual(1, readDT.Rows.Count);
            Assert.AreEqual("李四", readDT.Rows[0]["列2"].ToString());
        }
        public void TestWriteContent()
        {
            var dt = GetTestData();

            string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", "onesheetfile.xlsx");
            NPOIOperator oper = new NPOIOperator(dataFilePath, true);

            var sheet = oper.GetSheet("Sheet3");
            var writeLineNumber = oper.WriteContent(sheet, dt, 2);
            Assert.AreEqual(5, writeLineNumber);

            var readDT = oper.ReadSheet(sheet, false, 2);
            Assert.AreEqual(3, readDT.Rows.Count);

            Assert.AreEqual("李四", readDT.Rows[1]["列2"].ToString());
        }