public void TableShowHeader() { var wb = new XLWorkbook(); IXLWorksheet ws = wb.AddWorksheet("Sheet1"); ws.FirstCell().SetValue("Categories") .CellBelow().SetValue("A") .CellBelow().SetValue("B") .CellBelow().SetValue("C"); ws.RangeUsed().CreateTable().SetShowHeaderRow(false); IXLTable table = ws.Tables.First(); //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox1.xlsx"); Assert.IsTrue(ws.Cell(1, 1).IsEmpty(true)); Assert.AreEqual(null, table.HeadersRow()); Assert.AreEqual("A", table.DataRange.FirstRow().Field("Categories").GetString()); Assert.AreEqual("C", table.DataRange.LastRow().Field("Categories").GetString()); Assert.AreEqual("A", table.DataRange.FirstCell().GetString()); Assert.AreEqual("C", table.DataRange.LastCell().GetString()); table.SetShowHeaderRow(); IXLRangeRow headerRow = table.HeadersRow(); Assert.AreNotEqual(null, headerRow); Assert.AreEqual("Categories", headerRow.Cell(1).GetString()); table.SetShowHeaderRow(false); ws.FirstCell().SetValue("x"); table.SetShowHeaderRow(); //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox2.xlsx"); //wb.SaveAs(@"D:\Excel Files\ForTesting\Sandbox3.xlsx"); Assert.AreEqual("x", ws.FirstCell().GetString()); Assert.AreEqual("Categories", ws.Cell("A2").GetString()); Assert.AreNotEqual(null, headerRow); Assert.AreEqual("A", table.DataRange.FirstRow().Field("Categories").GetString()); Assert.AreEqual("C", table.DataRange.LastRow().Field("Categories").GetString()); Assert.AreEqual("A", table.DataRange.FirstCell().GetString()); Assert.AreEqual("C", table.DataRange.LastCell().GetString()); }
public void TableShowHeader() { using (var wb = new XLWorkbook()) { IXLWorksheet ws = wb.AddWorksheet("Sheet1"); ws.FirstCell().SetValue("Categories") .CellBelow().SetValue("A") .CellBelow().SetValue("B") .CellBelow().SetValue("C"); IXLTable table = ws.RangeUsed().CreateTable(); Assert.AreEqual("Categories", table.Fields.First().Name); table.SetShowHeaderRow(false); Assert.AreEqual("Categories", table.Fields.First().Name); Assert.IsTrue(ws.Cell(1, 1).IsEmpty(true)); Assert.AreEqual(null, table.HeadersRow()); Assert.AreEqual("A", table.DataRange.FirstRow().Field("Categories").GetString()); Assert.AreEqual("C", table.DataRange.LastRow().Field("Categories").GetString()); Assert.AreEqual("A", table.DataRange.FirstCell().GetString()); Assert.AreEqual("C", table.DataRange.LastCell().GetString()); table.SetShowHeaderRow(); IXLRangeRow headerRow = table.HeadersRow(); Assert.AreNotEqual(null, headerRow); Assert.AreEqual("Categories", headerRow.Cell(1).GetString()); table.SetShowHeaderRow(false); ws.FirstCell().SetValue("x"); table.SetShowHeaderRow(); Assert.AreEqual("x", ws.FirstCell().GetString()); Assert.AreEqual("Categories", ws.Cell("A2").GetString()); Assert.AreNotEqual(null, headerRow); Assert.AreEqual("A", table.DataRange.FirstRow().Field("Categories").GetString()); Assert.AreEqual("C", table.DataRange.LastRow().Field("Categories").GetString()); Assert.AreEqual("A", table.DataRange.FirstCell().GetString()); Assert.AreEqual("C", table.DataRange.LastCell().GetString()); } }