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.

Thu Aug 29, 2019 9:08 am

Hello,

Formula, which is checking some cell is not recalculating after save.
How to reproduce problem:
1. Create new excel file
2. Inside excel create named cell, lets say TESTCELL
3. In other cell put formula (sorry for formula being in polish, under i tried to translate formula but dont have access to english excel, so its word by word translation)
=JEŻELI(ORAZ(NIE(CZY.PUSTA(TESTCELL2));CZY.BŁĄD(DATA.WARTOŚĆ(TEKST(TESTCELL2;"rrrr-MM-DD"))));"error";TEKST(TESTCELL2;"rrrr-MM-DD"))
=IF(AND(NOT(IF.EMPTY(TESTCELL));IF.ERROR(DATE.VALUE(TEXT(TESTCELL;"yyyy-MM-dd"))));"error";TEXT(TESTCELL;"yyyy-MM-dd"))
4. Save template as lets say test1.xlsx
5. Code to test problem
var wrk = new Workbook();
string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Assets\\Templates\\test1.xlsx"; // Change path to your template file
wrk.LoadFromFile(filePath);
var sheet = wrk.Worksheets[0];
sheet["TESTCELL"].DateTimeValue = new DateTime(2019, 6, 7);
// Other ways also tested
//sheet["TESTCELL"].Text = new DateTime(2019, 6, 7).ToString("yyyy-MM-dd");
//sheet["TESTCELL"].DateTimeValue = new DateTime(2019, 6, 7);
//sheet["TESTCELL2"].Style.NumberFormat = "yyyy-mm-dd";
wrk.CalculateAllValue();
wrk.SaveToFile("test1output.xlsx");

6. Check output file. Value in formula cell is not calculated. If You focus on cell with date or with formula, click in formula bar and click enter, it is recalculated and is working...
But I need it already recalculated...
Or maybe it is problem with formula ?

7. Additional info:
Original sheet is protected and has lot of other formulas checking errors.
All others formulas are recalculated, only those, where dates are checked are not

Please help :)

Regards,
Tomasz

P.S.
When i edit formula, and change rrrr-MM-DD to yyyy-MM-DD, its ok, but i cannot change this in template, as it is not made by me
and used in some systems. Excel is edited in polish regional settings, so is date format written and i cannot do with this anything.
Formula cannot be edited :/
Tried also changing CurrentThread.CurrentCulture to Invariant or pl-PL, but not helped

gerciosek
 
Posts: 2
Joined: Thu Aug 29, 2019 8:27 am

Thu Aug 29, 2019 10:10 am

Hi,

Thanks for your inquiry.
Firstly, I suggest you try to use the latest version of Spire.XLS Pack(Hotfix) Version:9.8.11 which has more improvements than old versions.
If the issue still exists, to help us investigate your issue accurately, please offer us your input Excel file.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Aug 29, 2019 10:20 am

Here is test file.

Field to put value is A1, field where is formula is C1
Server regional settings are polish.
I tested it more, and Spire XLS dont understand rrrr-MM-DD date format, which is in the formula...

Need set field A1 to some date in format 2019-06-18 and formula to not evaluate to error...
I attached test file.
Attachments
TestFile.zip
(6.28 KiB) Downloaded 540 times

gerciosek
 
Posts: 2
Joined: Thu Aug 29, 2019 8:27 am

Fri Aug 30, 2019 8:55 am

Hi,

Thanks for your information.
I tested your file and code with Spire.XLS Pack(Hotfix) Version:9.8.11 but didn’t reproduce your issue. The format of sheet A1 is Date. And the formula in sheet C1 could evaluate correctly. Please check the attachment to see my result file.
Have you tried the latest version of Spire.XLS? If not, please have a try first.
If the issue still exists, to help us investigate your issue accurately, could you please tell us the Excel version you used to open the file?

Best wishes,
Amber
E-iceblue support team
Attachments
test1output.rar
(5.69 KiB) Downloaded 528 times
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Sep 04, 2019 3:52 pm

I am also having a problem with Formulas not Automatically Calculating when cells are updated.
The odd thing is the cells with formulas appear to be updated just fine when the sheet is saved as a PDF, as the PDF shows the cells with correct values. But when I open the spreadsheet in Office 365, the cells with formulas are not updating. When the spreadsheet is open in Office 365, if i double-click a cell that has a formula, and then simply click another cell, then the affected cell will update correctly.
In attached image, the open spreadsheet (which is opened, after the PDF was saved) shows Cells that are not updating, but the saved PDF shows them updated.
2019-09-04_6-28-16.jpg
2019-09-04_6-28-16.jpg (431.17 KiB) Viewed 10967 times

attached is the Spreadsheet before it is updated by code.
2019 - Test.zip
(219.86 KiB) Downloaded 544 times

attached is the Spreadsheet after it is updated by code.
See Sheet "2019 - DATA", cells I-10, I-26, I-28, I-32
and several Cells in Sheet "8-19", which are seen in the attached image.
2019 - Test After Code update.zip
(202.11 KiB) Downloaded 539 times

My Office Version: Microsoft Office 365 ProPlus Version 1902.

Code below. Note: I was using XLS version 9.7, but I downloaded and tested XLS version 9.9 and I am getting the same results.

Public Sub WorkbookUpdate()

Dim workbook As Workbook '

Dim res As Integer
Dim sb As StringBuilder
Dim SpreadsheetPath As String
Dim CellColumn As Short
Dim CellBlank As Boolean
Dim mma_line As String

Dim CSVRowsArray() As String
Dim Pmin() As String
Dim Pmax() As String
Dim Pavg() As String
Dim Ptot() As String
Dim Dmin() As String
Dim Dmax() As String
Dim Davg() As String
Dim Dtot() As String
Dim Fmin() As String
Dim Fmax() As String
Dim Favg() As String
Dim Ftot() As String
Dim Fpeak() As String
Dim KWmin() As String
Dim KWmax() As String
Dim KWavg() As String
Dim KWtot() As String
Dim KWHmin() As String
Dim KWHmax() As String
Dim KWHavg() As String
Dim KWHtot() As String

Dim PYear As String
Dim PdateShrt As String
Dim PdateShrt2 As String
Dim PdateNorm As String
Dim MnthStr As String
Dim PDFname As String
Dim ContinueWithWorkbook As Boolean


sb = New StringBuilder(100)
ContinueWithWorkbook = True
PDFname = vbNullString

Try
'Read the INI file, to get the Spreadsheet name
res = GetPrivateProfileString("OperData", "ExcelWorkBookPath", "", sb, sb.Capacity, MyAppPath & "ManagAIR-Net.ini")
If sb.Length > 0 Then
If InStr(sb.ToString, ".xlsx") Then
PDFname = sb.ToString.Replace(".xlsx", ".pdf")
Else
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt1, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt1, " & Err.Description))
ContinueWithWorkbook = False
End If
Else
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt2, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt2, " & Err.Description))
ContinueWithWorkbook = False
End If

If ContinueWithWorkbook Then
workbook = New Workbook()

PYear = Year(Now.AddMonths(-1))
PdateShrt = Now.AddMonths(-1).ToString("M-yy")
PdateShrt2 = Now.AddMonths(-1).ToString("MM-yy")
PdateNorm = Now.AddMonths(-1).ToString("MM-yyyy")
MnthStr = MonthName(Month(Now.AddMonths(-1)), True).ToUpper

'Read in the Data from the .csv file
Try
' Open the file using a stream reader.
Using sr As New StreamReader(CStr(MyAppPath & "TextData\" & MnthStr & "\" & MnthStr & " " & PYear & " mma.csv"))
' Read the stream to a string.
mma_line = sr.ReadToEnd()

'Split the Data from the String
CSVRowsArray = mma_line.Split(vbCrLf)

'Verify that all the data was in the csv file.
If CSVRowsArray.Length = 21 Then
Pmin = CSVRowsArray(0).Split(",")
Pmax = CSVRowsArray(1).Split(",")
Pavg = CSVRowsArray(2).Split(",")
Ptot = CSVRowsArray(3).Split(",")
Dmin = CSVRowsArray(4).Split(",")
Dmax = CSVRowsArray(5).Split(",")
Davg = CSVRowsArray(6).Split(",")
Dtot = CSVRowsArray(7).Split(",")
Fmin = CSVRowsArray(8).Split(",")
Fmax = CSVRowsArray(9).Split(",")
Favg = CSVRowsArray(10).Split(",")
Ftot = CSVRowsArray(11).Split(",")
Fpeak = CSVRowsArray(12).Split(",")
KWmin = CSVRowsArray(13).Split(",")
KWmax = CSVRowsArray(14).Split(",")
KWavg = CSVRowsArray(15).Split(",")
KWtot = CSVRowsArray(16).Split(",")
KWHmin = CSVRowsArray(17).Split(",")
KWHmax = CSVRowsArray(18).Split(",")
KWHavg = CSVRowsArray(19).Split(",")
KWHtot = CSVRowsArray(20).Split(",")


'Load workbook from disk.
SpreadsheetPath = CStr(MyAppPath & "TextData\" & PYear & " - " & sb.ToString())
If File.Exists(SpreadsheetPath) Then
Try
workbook.LoadFromFile(SpreadsheetPath)
'Initailize worksheet
Dim SheetName As String = PYear & " - DATA"
Dim sheet As Worksheet = workbook.Worksheets.Item(SheetName)

'Examples for writing to Cells.
'Writes number
'sheet.Range("L7").NumberValue = 89
'Writes string
'sheet.Range("L10").Text = "Hello World"
'Writes date
'sheet.Range("L11").DateTimeValue = System.DateTime.Now
'Writes formula
'sheet.Range("L12").Formula = "=1111*11111"

'Set the Column to write to based on the Month.
CellColumn = (Month(Now.AddMonths(-1)) + 1)

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(7, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then
sheet.Range(7, CellColumn).NumberValue = Pmin(0) 'Minimum Pressure
'If (Pmin(1) <> "") And (Pmin(1) <> "NA") Then
' sheet.Range(7, CellColumn).Comment.Text = Pmin(1) 'TimeStamp of Minimum Pressure
' sheet.Range(7, CellColumn).Comment.Height = 45
'End If
End If

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(8, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(8, CellColumn).NumberValue = Pmax(0) 'Maximum Pressure

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(9, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(9, CellColumn).NumberValue = Pavg(0) 'Average Pressure


'Check to see if the Cell is Blank.
CellBlank = sheet.Range(13, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(13, CellColumn).NumberValue = Dmin(0) 'Minimum DewPoint

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(14, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then
sheet.Range(14, CellColumn).NumberValue = Dmax(0) 'Maximum DewPoint
'If (Dmax(1) <> "") And (Dmax(1) <> "NA") Then
' sheet.Range(14, CellColumn).Comment.Text = Dmax(1) 'TimeStamp of Maximum DewPoint
' sheet.Range(14, CellColumn).Comment.Height = 45
'End If
End If

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(15, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(15, CellColumn).NumberValue = Davg(0) 'Average DewPoint


'Check to see if the Cell is Blank.
CellBlank = sheet.Range(19, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(19, CellColumn).NumberValue = Fmin(0) 'Minimum Flowrate

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(20, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then
sheet.Range(20, CellColumn).NumberValue = Fmax(0) 'Maximum Flowrate
'If (Fmax(1) <> "") And (Fmax(1) <> "NA") Then
' sheet.Range(20, CellColumn).Comment.Text = Fmax(1) 'TimeStamp of Maximum Flowrate
' sheet.Range(20, CellColumn).Comment.Height = 45
'End If
End If

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(21, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(21, CellColumn).NumberValue = Favg(0) 'Average Flowrate


'Check to see if the Cell is Blank.
CellBlank = sheet.Range(24, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(24, CellColumn).NumberValue = Ftot(0) 'MCF, Flow Total

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(25, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(25, CellColumn).NumberValue = Fpeak(0) 'Average of 8 hourly Peaks

'Check to see if the Cell is Blank.
CellBlank = sheet.Range(27, CellColumn).IsBlank
'Write Value to appropriate Cell
If CellBlank = True Then sheet.Range(27, CellColumn).NumberValue = KWHtot(0) 'KWH

workbook.Save()
Catch excptn As Exception
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt3, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt3, " & Err.Description))
ContinueWithWorkbook = False
End Try

If ContinueWithWorkbook Then
If Not String.IsNullOrEmpty(PDFname) Then
'Load workbook from disk.
SpreadsheetPath = CStr(MyAppPath & "TextData\" & PYear & " - " & sb.ToString())
If File.Exists(CStr(MyAppPath & "TextData\" & PdateShrt2 & " - " & PDFname)) Then
'Do Nothing, PDF file already created.
Else
Try
workbook.LoadFromFile(SpreadsheetPath)
'Initailize worksheet
Dim SheetName2 As String = PdateShrt
Dim sheet2 As Worksheet = workbook.Worksheets.Item(SheetName2)
sheet2.SaveToPdf(CStr(MyAppPath & "TextData\" & PdateShrt2 & " - " & PDFname))
Catch excptn As Exception
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt4, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt4, " & Err.Description))
ContinueWithWorkbook = False
End Try
End If
End If
End If

If ContinueWithWorkbook Then
If Not String.IsNullOrEmpty(PdateNorm) Then
'Convert 15 Min Avg CSV file to Excel File
If File.Exists(CStr(MyAppPath & "TextData\" & PdateNorm & " 15MinAvg.xlsx")) Then
'Do Nothing, xlsx file already created.
Else
Try
'Import the csv data into excel.
workbook.LoadFromFile(MyAppPath & "TextData\" & MnthStr & "\" & PdateNorm & " 15MinAvg.csv", ", ", 1, 1, ExcelVersion.Version2010)
'Name the Worksheet
Dim sheet As Worksheet = workbook.Worksheets(0)
sheet.Name = PdateNorm & " 15MinAvg"

'Format the Number cells.
sheet.Range(2, 2, sheet.LastRow, 5).NumberFormat = "####0"
sheet.Range(2, 6, sheet.LastRow, 11).NumberFormat = "####0.00"
sheet.Range(2, 12, sheet.LastRow, 17).NumberFormat = "####0"

sheet.Range(2, 2, sheet.LastRow, sheet.LastColumn).IgnoreErrorOptions = IgnoreErrorType.NumberAsText

'Set Conditional background formatting for low pressure, high dewpoints, and high Flows.
'Pressure vs. Pressure Guarantee
'Dim objCond As Spire.Xls.ConditionalFormatWrapper
'objCond = sheet.Range(2, 2, sheet.LastRow, 2).ConditionalFormats.AddCondition()
'objCond.FormatType = ConditionalFormatType.Formula
'objCond.FirstFormula = "=($B2<$L2)"
'objCond.BackColor = Color.LightCoral
'Flow vs. Flow Guarantee
'objCond = sheet.Range(2, 3, sheet.LastRow, 3).ConditionalFormats.AddCondition()
'objCond.FormatType = ConditionalFormatType.Formula
'objCond.FirstFormula = "=($C2>$N2)"
'objCond.BackColor = Color.LightSkyBlue
'DewPoint vs. DewPoint Guarantee
'objCond = sheet.Range(2, 5, sheet.LastRow, 5).ConditionalFormats.AddCondition()
'objCond.FormatType = ConditionalFormatType.Formula
'objCond.FirstFormula = "=($E2>$M2)"
'objCond.BackColor = Color.PaleGreen

'Save Spreadsheet
workbook.SaveToFile(MyAppPath & "TextData\" & PdateNorm & " 15MinAvg.xlsx", ExcelVersion.Version2010)

Catch excptn As Exception
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt5, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt5, " & Err.Description))
ContinueWithWorkbook = False
End Try
End If
End If
End If
End If
End If
End Using
'If ContinueWithWorkbook Then
' FrmLabelErrMess2.LabelErrMess.Text = "Workbook Update Complete, " & DateTime.Now.ToString()
'End If
Catch excptn As Exception
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt6, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt6, " & Err.Description))
End Try
End If
Catch excptn As Exception
FrmLabelErrMess2.LabelErrMess.Text = Err.Description & " Workbook Error Pnt7, " & DateTime.Now.ToString()
Call EncrFileRout(CStr("MAFileBU\BackUpFrm\WorkbookUpdate Error Pnt7, " & Err.Description))
End Try

workbook = Nothing 'testing

End Sub
User avatar

tsnelling
 
Posts: 14
Joined: Thu Jan 07, 2016 2:40 pm

Wed Sep 04, 2019 6:47 pm

In addition to my earlier post, describing the issue when opening the Spreadsheet with Office 365.
I have also now opened the Spreadsheet in Office 2013, and the results are the same. The Cells with the formulas are not Automatically Calculating.

Thanks,
Tim Snelling
User avatar

tsnelling
 
Posts: 14
Joined: Thu Jan 07, 2016 2:40 pm

Thu Sep 05, 2019 7:11 am

Hi,

Thanks for your inquiry.
Please try the code below to calculate all the formulas before saving workbook.

Code: Select all
workbook.CalculateAllValue()


Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Sep 05, 2019 10:27 am

Thanks Amber,
The "workbook.CalculateAllValue()" has resolved my issue.

Thanks,
Tim Snelling
User avatar

tsnelling
 
Posts: 14
Joined: Thu Jan 07, 2016 2:40 pm

Fri Sep 06, 2019 1:01 am

Hi Tim,

Thanks for your reply.
Any question, welcome to contact us.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue May 21, 2024 3:29 pm

Hello,
I have a similar problem in python but using CalculateAllValue() doesnt seem to fix it, but if i open the excel and run Ctrl + Alt + F9 (recalculate) it works

dstomps96
 
Posts: 14
Joined: Mon Oct 30, 2023 4:30 pm

Wed May 22, 2024 8:31 am

Hi,


Thanks for your message.
Can you send the test code and test file to us at 'support@e-iceblue.com' to assist us in further investigating this issue? Thanks in advance!

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 409
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.XLS