joshbtn / excelFormulaUtilitiesJS

This library contains methods to beautify an excel formula. This library also contains functions to convert an excel formula to JavaScript (ECMAScript) or C# and python.
http://excelformulabeautifier.com/
Other
395 stars 101 forks source link

Excel Function to JavaScript using blank cells in a "IF Then" context #20

Closed Jtabakman closed 11 years ago

Jtabakman commented 11 years ago

I have an Excel function which reads =IF(Q11="","",Q11*S11) that I'm trying to convert to JavaScript in an Adobe Acrobat Form. In the Form, Q11 is labeled "QuantityRow1", S11 is labeled "AmountRow1" with the Function residing in "TotalRow1" I have the same function duplicated for 16 rows which then total up all the sub totals in a simple sum formula that Adobe accepts. I'm assuming that somehow I need to put those labels into the JavaScript. Is that correct, and if so, what is the correct syntax. TIA

joshbtn commented 11 years ago

I'm not familiar with Adobe Acrobat scripting. From a quick glance at the documentation the output from the js conversion should probably be modified to look something like this.

this.getField("TotalRow1").value = (this.getField("QuantityRow1").value === "" ? "" : this.getField("QuantityRow1").value * this.getField("AmountRow1").value)

Or this is the same thing withough ternary statements...

if (this.getField("QuantityRow1").value === "") {
    this.getField("TotalRow1").value = "";
} else {
    this.getField("TotalRow1").value = this.getField("QuantityRow1").value * this.getField("AmountRow1").value);
}

The other option might be to leave the output the way it is and set variables equal to the fields' values

var Q11 = this.getField("QuantityRow1").value,
    S11 = this.getField("AmountRow1").value;

this.getField("TotalRow1").value = (Q11 === "" ? "" : Q11 * S11)

Hope this helps.

Jtabakman commented 11 years ago

Good Evening Josh,

Thank you so much for your help. My client has to have this done by Sunday. He originally wanted it all in Excel which was easy to program. Then, after 8 months, he asked if everything could just out of Adobe instead of using two programs. For two of his forms that was not an issue. In fact, I'm really impressed how easy it is to create forms. Then JavaScript came into the picture :(. I'll have a shot at the task tomorrow, and let you know what happens. It's really wonderful to see somebody volunteering their time, and knowledge to help another human being. I'm on the west coast (Oregon), so hopefully you will be awake when I respond. I'll do my best to get it done before 4:00 pm PST. Thank you.....Jon

On Fri, Sep 27, 2013 at 1:57 PM, Josh Bennett notifications@github.comwrote:

I'm not familiar with Adobe Acrobat scripting. From a quick glance at the documentationhttp://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdfThe output from the js conversion should probably be modified to look something like this.

this.getField("TotalRow1").value = (this.getField("QuantityRow1").value === "" ? "" : this.getField("QuantityRow1").value * this.getField("AmountRow1"**).value)

Or this is the same thing withough ternary statements...

if (this.getField("QuantityRow1").value === "") { this.getField("TotalRow1").value = "";} else { this.getField("TotalRow1").value = this.getField("QuantityRow1").value * this.getField("AmountRow1").value);}

The other option might be to leave the output the way it is and set variables equal to the fields values

var Q11 = this.getField("QuantityRow1").value, S11 = this.getField("AmountRow1").value; this.getField("TotalRow1").value = (Q11 === "" ? "" : Q11 * S11)

Hope this helps.

— Reply to this email directly or view it on GitHubhttps://github.com/joshatjben/excelFormulaUtilitiesJS/issues/20#issuecomment-25276776 .

joshbtn commented 11 years ago

You're welcome. I'm on the east coast, but drop me a line if you get too stuck, chances are I'll still be up. Hopefully my earlier comment made sense and got you going in the right direction. Let me know how it goes, Good luck!

Jtabakman commented 11 years ago

Good Afternoon Josh,

It sort of worked. The second script worked, but when I cleared the inputs, or just deleted one or more inputs, and then re-entered the data, the grand totals were off, usually by 1. So, we have three columns. The QuantityRow column, the AmountRow column, and the TotalRow column. The script is in the TotalRow column. There are 16 rows. If I enter "1" 16 times to populate both the QuantityRow, and the AmountRow columns, the result computes to $16.00. If I then clear the form, and enter them again, the result computes to $15.00. If I just clear one, or two entries, then enter them again, the result computes to $15.00.

I checked everything. I erased, and re-entered the script. Nothing I did resolved the problem. Because of time constraints, I decided to clear the form, and will tell the user to manually enter whatever figures he wants which will total correctly at the "Material Total" box. It's not a deal breaker because we are not talking about a trade that has multiples of whatever it is they are billing. They don't have 17 bolts to bill. It's usually 1 capacitor, or 1 heat pump...that sort of thing.

If you want to play around with it (I will be doing the same), I can email you the Form. I just need to know your private email address.....or you can log in to my computer using TeamViewer (great program, and free for private use). I'm fine with either option, although I have to be here when you wish to remote in.

Regards,

Jon

On Fri, Sep 27, 2013 at 5:01 PM, Josh Bennett notifications@github.comwrote:

You're welcome. I'm on the east coast, but drop me a line if you get too stuck, chances are I'll still be up. Hopefully my earlier comment made sense and got you going in the right direction. Let me know how it goes, Good luck!

— Reply to this email directly or view it on GitHubhttps://github.com/joshatjben/excelFormulaUtilitiesJS/issues/20#issuecomment-25285426 .

joshbtn commented 11 years ago

Hey, sorry you didn't get that working. If you're still interested in messing with it I wouldn't mind taking a look. You can email the file to support at j-ben dot com. I am going to go ahead and close this issue.