コード例 #1
0
        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"]);
        }