Hi,
I have problems to read a formula from a cell.
I create a new excel file like this:
Excel excel = new Excel();
Worksheet sheet = excel.Worksheets[0];
sheet.Name = "Sheet1";
Cells cells = sheet.Cells;
Cell cell_a1 = cells["A1"];
Cell cell_a2 = cells["A2"];
Cell cell_a3 = cells["A3"];
cell_a1.PutValue("test");
cell_a2.Formula = "=A1";
cell_a3.Formula = "=Sheet1!A1";
excel.CalculateFormula();
Console.WriteLine("Cell: {0}, string: {1}, formula: {2}", cell_a1.Name, cell_a1.StringValue, cell_a1.Formula);
Console.WriteLine("Cell: {0}, string: {1}, formula: {2}", cell_a2.Name, cell_a2.StringValue, cell_a2.Formula);
Console.WriteLine("Cell: {0}, string: {1}, formula: {2}", cell_a3.Name, cell_a3.StringValue, cell_a3.Formula);
excel.Save("Test_011.xls");
The output on the console is:
Cell: A1, string: test, formula:
Cell: A2, string: test, formula: =A1
Cell: A3, string: test, formula: =Sheet1!A1
That's correct.
Now I open the file and do the same "Console.WriteLine", but the result is not what I'm expecting:
excel = new Excel();
excel.Open("Test_011.xls");
sheet = excel.Worksheets[0];
cells = sheet.Cells;
cell_a1 = cells["A1"];
cell_a2 = cells["A2"];
cell_a3 = cells["A3"];
Console.WriteLine("Cell {0}, string = {1}, formula = {2}", cell_a1.Name, cell_a1.StringValue, cell_a1.Formula);
Console.WriteLine("Cell {0}, string = {1}, formula = {2}", cell_a2.Name, cell_a2.StringValue, cell_a2.Formula);
Console.WriteLine("Cell {0}, string = {1}, formula = {2}", cell_a3.Name, cell_a3.StringValue, cell_a3.Formula);
Cell: A1, string: test, formula:
Cell: A2, string: test, formula: =A1
Cell: A3, string: test, formula: =
Why is the formula in cell A3 not set?
Andreas