Ejemplo n.º 1
0
        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);
            }
        }