本文整理汇总了C#中SS.Spreadsheet.GetCellValue方法的典型用法代码示例。如果您正苦于以下问题:C# Spreadsheet.GetCellValue方法的具体用法?C# Spreadsheet.GetCellValue怎么用?C# Spreadsheet.GetCellValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS.Spreadsheet
的用法示例。
在下文中一共展示了Spreadsheet.GetCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewTest1
public void NewTest1()
{
Spreadsheet sheet = new Spreadsheet();
sheet.SetContentsOfCell("A1", "3");
sheet.SetContentsOfCell("B1", "=A1");
Assert.AreEqual(sheet.GetCellValue("B1"), 3.0);
sheet.SetContentsOfCell("A1", "");
Assert.IsTrue(sheet.GetCellValue("B1") is FormulaError);
}
示例2: GetCellValueTest
public void GetCellValueTest()
{
AbstractSpreadsheet s = new Spreadsheet();
string name;
string content;
// Try a value of a string from string
name = "A1";
content = "Hello";
s.SetContentsOfCell(name, content);
string expected1 = content;
string actual1 = (string)s.GetCellValue(name);
Assert.AreEqual(expected1, actual1);
// Try a value of a double from a double
name = "B1";
content = "3";
s.SetContentsOfCell(name, content);
double expected2 = 3;
double actual2 = (double)s.GetCellValue(name);
Assert.AreEqual(expected2, actual2);
// Try a value of a double from a Formula
name = "C1";
content = "=3+1";
s.SetContentsOfCell(name, content);
double expected3 = 4;
double actual3 = (double)s.GetCellValue(name);
Assert.AreEqual(expected3, actual3);
// Try all possible FormulaError
name = "D1";
content = "=1/0";
s.SetContentsOfCell(name, content);
object actual4 = s.GetCellValue(name);
Assert.IsInstanceOfType(actual4, typeof(FormulaError));
// Try chaining several formulas together then changing the value of cell. Test before and after.
s.SetContentsOfCell("E1", "=F1 + 1");
s.SetContentsOfCell("F1", "=G1 + 1");
s.SetContentsOfCell("G1", "1");
Assert.AreEqual(3, (double)s.GetCellValue("E1"));
Assert.AreEqual(2, (double)s.GetCellValue("F1"));
s.SetContentsOfCell("G1", "2");
Assert.AreEqual(4, (double)s.GetCellValue("E1"));
Assert.AreEqual(3, (double)s.GetCellValue("F1"));
// Try switching a cell that has a formula depending on it to string.
s.SetContentsOfCell("J1", "This is a string");
s.SetContentsOfCell("K1", "=J1");
Assert.IsInstanceOfType(s.GetCellValue("K1"), typeof(FormulaError));
}
示例3: GetValueDouble
public void GetValueDouble()
{
Spreadsheet sheet = new Spreadsheet(s => true, s => s, "default");
sheet.SetContentsOfCell("D1", "5");
Assert.AreEqual(sheet.GetCellContents("D1"), (double)5);
Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
}
示例4: GetValueDoubleEmptyConstructor
public void GetValueDoubleEmptyConstructor()
{
Spreadsheet sheet = new Spreadsheet();
sheet.SetContentsOfCell("D1", "5");
Assert.AreEqual(sheet.GetCellContents("D1"), (double)5);
Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
}
示例5: CreateSaveLoadSpreadsheet
public void CreateSaveLoadSpreadsheet()
{
Spreadsheet sheet = new Spreadsheet();
sheet.SetContentsOfCell("D1", "=5");
sheet.SetContentsOfCell("C1", "=4.5");
sheet.SetContentsOfCell("E1", "apples");
sheet.SetContentsOfCell("G1", "-2");
sheet.SetContentsOfCell("H1", "-4");
sheet.SetContentsOfCell("F1", "= G1 + H1");
sheet.Save(@"MyXml2.xml");
Spreadsheet sheet2 = new Spreadsheet(@"MyXml2.xml", s => true, s => s, "default");
Assert.AreEqual(sheet2.GetCellContents("D1"), new Formula("5"));
Assert.AreEqual(sheet2.GetCellContents("C1"), new Formula("4.5"));
Assert.AreEqual(sheet2.GetCellContents("E1"), "apples");
Assert.AreEqual(sheet2.GetCellContents("G1"), (double)-2);
Assert.AreEqual(sheet2.GetCellContents("H1"), (double)-4);
Assert.AreEqual(sheet2.GetCellContents("F1"), new Formula("G1 + H1"));
Assert.AreEqual(sheet2.GetCellValue("F1"), (double)-6);
}
示例6: NewTest16
public void NewTest16()
{
Spreadsheet s = new Spreadsheet(x => true, x => x, "default");
s.GetCellValue("1a");
}
示例7: LongTest
public void LongTest()
{
AbstractSpreadsheet s = new Spreadsheet();
s.SetContentsOfCell("sum1", "= a1 + a2");
int i;
int depth = 100;
for (i = 1; i <= depth * 2; i += 2)
{
s.SetContentsOfCell("a" + i, "= a" + (i + 2) + " + a" + (i + 3));
s.SetContentsOfCell("a" + (i + 1), "= a" + (i + 2) + "+ a" + (i + 3));
}
s.SetContentsOfCell("a" + i, "1");
s.SetContentsOfCell("a" + (i + 1), "1");
Assert.AreEqual(Math.Pow(2, depth + 1), (double)s.GetCellValue("sum1"), 1e20);
s.SetContentsOfCell("a" + i, "0");
Assert.AreEqual(Math.Pow(2, depth), (double)s.GetCellValue("sum1"), 1e20);
s.SetContentsOfCell("a" + (i + 1), "0");
Assert.AreEqual(0.0, (double)s.GetCellValue("sum1"), 0.1);
}
示例8: SaveTest
public void SaveTest()
{
string existing_path = @"..\..\..\SpreadSheetTests\validspreadsheet.xml"; // the .. means up a directory
Spreadsheet target = new Spreadsheet(existing_path, s => true, s => s.ToUpper(), "dan1");
Assert.AreEqual(2.0, (double)target.GetCellValue("a2"));
target.Save(@"output22.xml");
var output = File.ReadAllText("output22.xml");
Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?><spreadsheet version=\"dan1\"><cell><name>A1</name><contents>2</contents></cell><cell><name>A2</name><contents>=A1</contents></cell></spreadsheet>", output);
}
示例9: SpreadsheetFourArgumentConstructorTest
public void SpreadsheetFourArgumentConstructorTest()
{
if (!File.Exists("fourarg.xml"))
{
Spreadsheet old = new Spreadsheet(TestValidToTrue, TestNormalizeToUpperCase, "2.2");
old.SetContentsOfCell("A1", "asdf");
old.SetContentsOfCell("B2", "23");
old.Save("fourarg.xml");
}
Spreadsheet s = new Spreadsheet("fourarg.xml", TestValidToTrue, TestNormalizeToUpperCase, "2.2");
Assert.AreEqual(true, s.IsValid("a"));
Assert.AreEqual("A", s.Normalize("a"));
Assert.AreEqual("asdf", s.GetCellContents("A1"));
Assert.AreEqual(23.0, s.GetCellContents("B2"));
Assert.AreEqual(23.0, s.GetCellValue("B2"));
Assert.AreEqual("2.2", s.Version);
}
示例10: NormalizeTest4
public void NormalizeTest4()
{
AbstractSpreadsheet ss = new Spreadsheet(s => true, s => s.ToUpper(), "");
ss.SetContentsOfCell("a1", "5");
ss.SetContentsOfCell("A1", "6");
ss.SetContentsOfCell("B1", "= a1");
Assert.AreEqual(6.0, (double)ss.GetCellValue("B1"), 1e-9);
}
示例11: LongFormulaHelper
public void LongFormulaHelper(out object result)
{
try {
AbstractSpreadsheet s = new Spreadsheet();
s.SetContentsOfCell("sum1", "= a1 + a2");
int i;
int depth = 100;
for (i = 1; i <= depth * 2; i += 2) {
s.SetContentsOfCell("a" + i, "= a" + (i + 2) + " + a" + (i + 3));
s.SetContentsOfCell("a" + (i + 1), "= a" + (i + 2) + "+ a" + (i + 3));
}
s.SetContentsOfCell("a" + i, "1");
s.SetContentsOfCell("a" + (i + 1), "1");
Assert.AreEqual(Math.Pow(2, depth + 1), (double)s.GetCellValue("sum1"), 1.0);
s.SetContentsOfCell("a" + i, "0");
Assert.AreEqual(Math.Pow(2, depth), (double)s.GetCellValue("sum1"), 1.0);
s.SetContentsOfCell("a" + (i + 1), "0");
Assert.AreEqual(0.0, (double)s.GetCellValue("sum1"), 0.1);
result = "ok";
}
catch (Exception e) {
result = e;
}
}
示例12: TestGetCellValue2
public void TestGetCellValue2()
{
Spreadsheet sheet = new Spreadsheet();
sheet.GetCellValue("84");
}
示例13: NewTest15
public void NewTest15()
{
Spreadsheet s = new Spreadsheet(x => true, x => x.Replace('a', '1'), "default");
s.SetContentsOfCell("a1", "Text");
s.GetCellValue("a1");
}
示例14: NewTest19
public void NewTest19()
{
Spreadsheet s = new Spreadsheet(x => true, x => x.Replace('a', '1'), "default");
s.GetCellValue("a1");
}
示例15: GetValueFormulaMultipleCellLayers02
public void GetValueFormulaMultipleCellLayers02()
{
Spreadsheet sheet = new Spreadsheet();
Assert.IsTrue(!sheet.Changed);
sheet.SetContentsOfCell("D1", "=5");
Assert.IsTrue(sheet.Changed);
sheet.SetContentsOfCell("C1", "=4.5");
sheet.SetContentsOfCell("E1", "0.5");
sheet.SetContentsOfCell("G1", "-2");
sheet.SetContentsOfCell("H1", "-4");
sheet.SetContentsOfCell("F1", "= G1 + H1");
Assert.AreEqual(sheet.GetCellValue("D1"), (double)5);
Assert.AreEqual(sheet.GetCellValue("C1"), (double)4.5);
Assert.AreEqual(sheet.GetCellValue("E1"), (double)0.5);
Assert.AreEqual(sheet.GetCellValue("F1"), (double)-6);
Assert.AreEqual(sheet.GetCellValue("G1"), (double)-2);
sheet.SetContentsOfCell("B1", "=(C1 + D1)/E1 + F1");
Assert.AreEqual(sheet.GetCellContents("B1"), new Formula("(C1 + D1)/E1 + F1"));
Assert.AreEqual(sheet.GetCellValue("B1"), (double)13);
}