本文整理汇总了C#中ClosedXML.Excel.XLWorkbook.Cell方法的典型用法代码示例。如果您正苦于以下问题:C# XLWorkbook.Cell方法的具体用法?C# XLWorkbook.Cell怎么用?C# XLWorkbook.Cell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClosedXML.Excel.XLWorkbook
的用法示例。
在下文中一共展示了XLWorkbook.Cell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cell3
public void Cell3()
{
var wb = new XLWorkbook();
IXLWorksheet ws = wb.AddWorksheet("Sheet1");
ws.FirstCell().SetValue(1).AddToNamed("Result");
IXLCell cell = wb.Cell("Sheet1!Result");
Assert.IsNotNull(cell);
Assert.AreEqual(1, cell.GetValue<Int32>());
}
示例2: CellsUsed
public void CellsUsed()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
ws.Cell(1, 1);
ws.Cell(2, 2);
int count = ws.Range("A1:B2").CellsUsed().Count();
Assert.AreEqual(0, count);
}
示例3: IsBlank_false
public void IsBlank_false()
{
var ws = new XLWorkbook().AddWorksheet("Sheet");
ws.Cell("A1").Value = " ";
var actual = ws.Evaluate("=IsBlank(A1)");
Assert.AreEqual(false, actual);
}
示例4: IsEmpty2
public void IsEmpty2()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
IXLRange range = ws.Range("A1:B2");
bool actual = range.IsEmpty(true);
bool expected = true;
Assert.AreEqual(expected, actual);
}
示例5: Double_NaN_is_a_string
public void Double_NaN_is_a_string()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell("A1");
var doubleList = new List<Double> {0.0/0.0};
cell.Value = doubleList.AsEnumerable();
Assert.AreNotEqual(XLCellValues.Number, cell.DataType);
}
示例6: CellsUsedIncludeStyles2
public void CellsUsedIncludeStyles2()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
ws.Row(2).Style.Fill.BackgroundColor = XLColor.Red;
ws.Column(2).Style.Fill.BackgroundColor = XLColor.Red;
ws.Cell(3, 3).Value = "ASDF";
var range = ws.RangeUsed(true).RangeAddress.ToString();
Assert.AreEqual("B2:C3", range);
}
示例7: IsEmpty5
public void IsEmpty5()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
cell.Style.Fill.BackgroundColor = XLColor.Red;
IXLRange range = ws.Range("A1:B2");
bool actual = range.IsEmpty(true);
bool expected = false;
Assert.AreEqual(expected, actual);
}
示例8: ToStringTest
public void ToStringTest()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLRangeAddress address = ws.Cell(1, 1).AsRange().RangeAddress;
Assert.AreEqual("A1:A1", address.ToString());
Assert.AreEqual("A1:A1", address.ToStringRelative());
Assert.AreEqual("'Sheet1'!A1:A1", address.ToStringRelative(true));
Assert.AreEqual("$A$1:$A$1", address.ToStringFixed());
Assert.AreEqual("$A$1:$A$1", address.ToStringFixed(XLReferenceStyle.A1));
Assert.AreEqual("R1C1:R1C1", address.ToStringFixed(XLReferenceStyle.R1C1));
Assert.AreEqual("$A$1:$A$1", address.ToStringFixed(XLReferenceStyle.Default));
Assert.AreEqual("'Sheet1'!$A$1:$A$1", address.ToStringFixed(XLReferenceStyle.A1, true));
Assert.AreEqual("'Sheet1'!R1C1:R1C1", address.ToStringFixed(XLReferenceStyle.R1C1, true));
Assert.AreEqual("'Sheet1'!$A$1:$A$1", address.ToStringFixed(XLReferenceStyle.Default, true));
}
示例9: AddTextTest1
public void AddTextTest1()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
IXLRichText richString = cell.RichText;
string text = "Hello";
richString.AddText(text).SetBold().SetFontColor(XLColor.Red);
Assert.AreEqual(cell.GetString(), text);
Assert.AreEqual(cell.RichText.First().Bold, true);
Assert.AreEqual(cell.RichText.First().FontColor, XLColor.Red);
Assert.AreEqual(1, richString.Count);
richString.AddText("World");
Assert.AreEqual(richString.First().Text, text, "Item in collection is not the same as the one returned");
}
示例10: AddTextTest2
public void AddTextTest2()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
Int32 number = 123;
cell.SetValue(number).Style
.Font.SetBold()
.Font.SetFontColor(XLColor.Red);
string text = number.ToString();
Assert.AreEqual(cell.RichText.ToString(), text);
Assert.AreEqual(cell.RichText.First().Bold, true);
Assert.AreEqual(cell.RichText.First().FontColor, XLColor.Red);
Assert.AreEqual(1, cell.RichText.Count);
cell.RichText.AddText("World");
Assert.AreEqual(cell.RichText.First().Text, text, "Item in collection is not the same as the one returned");
}
示例11: AccessRichTextTest1
public void AccessRichTextTest1()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
cell.RichText.AddText("12");
cell.DataType = XLCellValues.Number;
Assert.AreEqual(12.0, cell.GetDouble());
IXLRichText richText = cell.RichText;
Assert.AreEqual("12", richText.ToString());
richText.AddText("34");
Assert.AreEqual("1234", cell.GetString());
Assert.AreEqual(XLCellValues.Number, cell.DataType);
Assert.AreEqual(1234.0, cell.GetDouble());
}
示例12: IsEmpty1
public void IsEmpty1()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
bool actual = cell.IsEmpty();
bool expected = true;
Assert.AreEqual(expected, actual);
}
示例13: ValueSetToNull
public void ValueSetToNull()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
cell.Value = new DateTime(2000, 1, 2);
cell.Value = null;
string actual = cell.GetString();
string expected = String.Empty;
Assert.AreEqual(expected, actual);
}
示例14: ValueSetDateWithShortUserDateFormat
public void ValueSetDateWithShortUserDateFormat()
{
// For this test to make sense, user's local date format should be dd/MM/yy (note without the 2 century digits)
// What happened previously was that the century digits got lost in .ToString() conversion and wrong century was sometimes returned.
var ci = new CultureInfo(CultureInfo.InvariantCulture.LCID);
ci.DateTimeFormat.ShortDatePattern = "dd/MM/yy";
Thread.CurrentThread.CurrentCulture = ci;
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
IXLCell cell = ws.Cell(1, 1);
var expected = DateTime.Today.AddYears(20);
cell.Value = expected;
var actual = (DateTime)cell.Value;
Assert.AreEqual(expected, actual);
}
示例15: TryGetValue_TimeSpan_GoodString
public void TryGetValue_TimeSpan_GoodString()
{
IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1");
TimeSpan outValue;
var timeSpan = new TimeSpan(1, 1, 1);
bool success = ws.Cell("A1").SetValue(timeSpan.ToString()).TryGetValue(out outValue);
Assert.IsTrue(success);
Assert.AreEqual(timeSpan, outValue);
}