本文整理汇总了C#中ClosedXML.Excel.XLWorkbook.ReadSheet方法的典型用法代码示例。如果您正苦于以下问题:C# XLWorkbook.ReadSheet方法的具体用法?C# XLWorkbook.ReadSheet怎么用?C# XLWorkbook.ReadSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClosedXML.Excel.XLWorkbook
的用法示例。
在下文中一共展示了XLWorkbook.ReadSheet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFailedToReadNotFoundSheet
public void TestFailedToReadNotFoundSheet()
{
using(var wb = new XLWorkbook())
{
Assert.That(() => wb.ReadSheet<NotFoundSheet>(),
Throws.Exception.TypeOf<NotFoundSheetException>());
}
}
示例2: TestAllowedEmptyCell
public void TestAllowedEmptyCell()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("allowed_empty");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Data");
ws.Cell("A2").SetValue("a");
Assert.DoesNotThrow(() => wb.ReadSheet<AllowedEmptySheet>());
}
}
示例3: TestEnumValueColumn
public void TestEnumValueColumn()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("enum_value_column");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Kind");
ws.Cell("B2").SetValue("Foo");
ws.Cell("B3").SetValue("Bar");
var data = wb.ReadSheet<EnumValueColumnSheet>();
Assert.That(data[0].Kind, Is.EqualTo(DataKind.Foo));
Assert.That(data[1].Kind, Is.EqualTo(DataKind.Bar));
}
}
示例4: TestReadCommentSheet
public void TestReadCommentSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("comment_sheet");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Column");
ws.Cell("A2").SetValue("#comment out");
ws.Cell("B2").SetValue("1");
ws.Cell("B3").SetValue("2");
var data = wb.ReadSheet<CommentSheet>();
Assert.That(data.Count, Is.EqualTo(1));
Assert.That(data[0].Column, Is.EqualTo("2"));
}
}
示例5: TestNotAllowedEmptyCell
public void TestNotAllowedEmptyCell()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("not_allowed_empty");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Data");
ws.Cell("A2").SetValue("a");
Assert.That(() => wb.ReadSheet<NotAllowedEmptySheet>(),
Throws.Exception.TypeOf<NotAllowedEmptyException>()
.And.Property("ColumnLetter").EqualTo("B")
.And.Property("RowNumber").EqualTo(2));
}
}
示例6: TestRowNumberSheet
public void TestRowNumberSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("row_numbers");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Data");
ws.Cell("B2").SetValue("1");
ws.Cell("B3").SetValue("2");
var data = wb.ReadSheet<RowNumberSheet>();
Assert.That(data[0].Data, Is.EqualTo(1));
Assert.That(data[0].RowNumber, Is.EqualTo(2));
Assert.That(data[1].Data, Is.EqualTo(2));
Assert.That(data[1].RowNumber, Is.EqualTo(3));
}
}
示例7: TestReadTwoColumnSheet
public void TestReadTwoColumnSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("two_column");
ws.Cell("A2").SetValue("@start");
ws.Cell("B2").SetValue("column1");
ws.Cell("C2").SetValue("Column2");
ws.Cell("B3").SetValue("1");
ws.Cell("C3").SetValue("b3");
ws.Cell("B4").SetValue("2");
ws.Cell("C4").SetValue("b4");
var data = wb.ReadSheet<TwoColumnSheet>();
Assert.That(data[0].Column, Is.EqualTo("1"));
Assert.That(data[0].Column2, Is.EqualTo("b3"));
Assert.That(data[1].Column, Is.EqualTo("2"));
Assert.That(data[1].Column2, Is.EqualTo("b4"));
}
}
示例8: TestReadOneColumnSheet
public void TestReadOneColumnSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("one_column");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("column");
ws.Cell("B2").SetValue("1");
ws.Cell("B3").SetValue("2");
var data = wb.ReadSheet<OneColumnSheet>();
Assert.That(data[0].Column, Is.EqualTo("1"));
Assert.That(data[1].Column, Is.EqualTo("2"));
}
}
示例9: TestReadIndexedColumnSheet
public void TestReadIndexedColumnSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("indexed_column_sheet");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("column0");
ws.Cell("B2").SetValue("0");
ws.Cell("C1").SetValue("column1");
ws.Cell("C2").SetValue("1");
ws.Cell("D1").SetValue("column2");
ws.Cell("D2").SetValue("2");
var data = wb.ReadSheet<IndexedColumnSheet>();
Assert.That(data[0].Column["column0"], Is.EqualTo("0"));
Assert.That(data[0].Column["column1"], Is.EqualTo("1"));
Assert.That(data[0].Column["column2"], Is.EqualTo("2"));
}
}
示例10: TestReadDateTimeSheet
public void TestReadDateTimeSheet()
{
using(var wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add("date_time_sheet");
ws.Cell("A1").SetValue("@start");
ws.Cell("B1").SetValue("Time");
ws.Cell("B2").SetValue("2014/07/07 10:10:10");
ws.Cell("B3").SetValue("2014/10/1");
var data = wb.ReadSheet<DateTimeSheet>();
Assert.That(data[0].Time, Is.EqualTo(DateTime.Parse("2014/07/07 10:10:10")));
Assert.That(data[1].Time, Is.EqualTo(DateTime.Parse("2014/10/1")));
}
}