I am creating an excel spreadsheet which will eventually be emailed as an attachment. Within the spreadsheet I want to add a formulae to sum a group of fields. No matter what I do the field is always set to 4 when I view it in the email?
B4X:
Dim strY As String
strY = x
SummaryCell.InitializeFormula(6, x+1, "sum(G1:G" & strY & ")")
SummarySheet.AddCell(SummaryCell)
Log( "sum(G1:G" & strY)
x is the end value from a for/next loop and G1 to Gx are the cells I want to sum.
Still no joy on this. Still puts "4" in the sum cell.
I have attached a simple program as suggested. You will need to set the email address and postcode to something appropriate to you.
Additional Info.. When I download the spreadsheet the cell contains "#N/A" and gives an error message saying "A value is not available to the formula or function" . Up until now I have been looking at it directly via the email.
sb.Append("SUM(")
For i = 1 To 5
If i > 1 Then sb.Append(",")
sb.Append("Test!G").Append(i)
Next
sb.Append(")")
tc.InitializeFormula(6, 6, sb.ToString)
Applied the changes you have suggested and finally got the correct totals being reported... sort of...
As the spreadsheet is sent as an attachment to an email it is quite possible for the spreadsheet to be viewed online, certainly for Outlook users anyway. When viewed online the cell still contains "4" but if you download the spreadsheet and look at it directly via Excel the cell contains the correct calculated value. So to ensure the user will always see the correct value I will have to do all the calculations within the program. Not a major problem but it would have been nice for Excel to do some of the work.