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 TestFlushWithXls() { var dt = GetTestData(); var fileName = "write" + Guid.NewGuid().ToString() + ".xls"; string dataFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file", fileName); NPOIOperator oper = new NPOIOperator(dataFilePath, true); oper.WriteSheet("Sheet3", dt, true); oper.Flush(); try { NPOIOperator oper2 = new NPOIOperator(dataFilePath, true); var sheet = oper2.GetSheet("Sheet3"); var dt2 = oper2.ReadSheet(sheet, true, true, 0); 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 TestWriteSheetWithSheetInstanceAndRowNumberAndNoTitle() { 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.WriteSheet(sheet, dt, false, 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()); }