Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Oct 07, 2020 3:32 am

Hello,

I defined a formula in a excel file. For example I set B3 to formula =SUM(B1:B2) in excel and save it as text2.xlsx. I set B1 and B2 in code as below:

var workbook = new Workbook();
workbook.LoadFromFile("test2.xlsx");
var sheet = workbook.Worksheets[0];
sheet.Range[1, 2].Value = "10";
sheet.Range[2, 2].Value = "10";
workbook.SaveToFile("ntest2.xlsx");
Console.ReadKey();

When I open ntest2.xlsx, I found the formual did not work. The B3 was 0.

Regards

Lei

zhenlei1970
 
Posts: 9
Joined: Thu Oct 10, 2019 8:49 am

Wed Oct 07, 2020 3:58 am

Hello Lei,

Thanks for your inquiry.
Please add this line to recalculate the formula value. If there are any other questions, just feel free to let us know.
Code: Select all
            workbook.CalculateAllValue();
            //then save file...


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Oct 08, 2020 2:28 am

Thanks for your reply. It works now.

zhenlei1970
 
Posts: 9
Joined: Thu Oct 10, 2019 8:49 am

Thu Oct 08, 2020 2:39 am

Hello,

Glad to hear that!
Feel free to contact us if you need further assistance.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS