Skip to main content
Participant
April 28, 2020
Answered

I need help putting this excel formula into Adobe Acrobat DC

  • April 28, 2020
  • 1 reply
  • 268 views

How to I take this fomula and put it into a text box in Adobe Acrobat DC

(SUM(G3:G16)-14)/56

I have item1 through to item14 in my pdf  

I do not know how to create the javascript for the calculation. 

Can someone please create this for me on this forum. Thank you 

This topic has been closed for replies.
Correct answer ls_rbls

Hi,

 

Create an array to perform a SUM of the text fields 1 through 14.

 

There is an example script that shows how to declare a variable in order to array the fields found in the following reference guide: "Developing Acrobat Applications Using JavaScript"   https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_developer_guide.pdf

 

An example of the custom calculation script is found in pages 84-85 shown below:

 

 

var aNumFields = new Array("Text1.0", "Text1.1", "Text1.2","Text1.3",
"Text1.4");
myAverageFunction(aNumFields);

function myAverageFunction(aNumFields)
{
// n = number of fields that have a numerical value
var n=0, sum = 0;
for ( var i=0; i<aNumFields.length; i++) {
var v = this.getField(aNumFields[i]).value;
if ( v != "" ) {
n++;
sum += v;
}
}
if ( n == 0 ) event.value = "";
else event.value = sum/n;
}

 

1 reply

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
April 28, 2020

Hi,

 

Create an array to perform a SUM of the text fields 1 through 14.

 

There is an example script that shows how to declare a variable in order to array the fields found in the following reference guide: "Developing Acrobat Applications Using JavaScript"   https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_developer_guide.pdf

 

An example of the custom calculation script is found in pages 84-85 shown below:

 

 

var aNumFields = new Array("Text1.0", "Text1.1", "Text1.2","Text1.3",
"Text1.4");
myAverageFunction(aNumFields);

function myAverageFunction(aNumFields)
{
// n = number of fields that have a numerical value
var n=0, sum = 0;
for ( var i=0; i<aNumFields.length; i++) {
var v = this.getField(aNumFields[i]).value;
if ( v != "" ) {
n++;
sum += v;
}
}
if ( n == 0 ) event.value = "";
else event.value = sum/n;
}