Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Converting Excel document to PDF manually (halfway there)...

New Here ,
Oct 08, 2022 Oct 08, 2022

Good day,

 

I would like to convert an existing Excel spreadsheet (Expense Claim Sheet) containing formulas and linked data to a fillable PDF form retaining all the functionality of the formulas.  I know there is no direct conversion so I have begun doing this manually with Acrobat Javascript derived from other forum posts searched here as I am not a programmer at all.

 

Please if someone can assist with the below issues I would greatly appreciate it or advise if the Excel document should just be used instead, as I cannot find solutions to the below with the knowledge I have; I can provide links to the original Excel file and PDF file I'm still working on if required - thanks:

 

  1. Firstly, my intention with the "Department" dropdown list is to populate the "Expense Account Description" dropdown with a specific list dependant on the specific department chosen.  Once the list is populated, you must be able to then choose an account from the dropdown which will automatically insert the respective account number in the next column for "Expense Acc. No."  Also, for a new line, a unique Expense Account Description with it's respective Expense Acc. No. must be able to be selected.  I've managed this with the below code under 'custom keystroke script' under the 'format' tab in 'properties' (these are for the first three lines of the form - i.e. supplier X,Y,Z, there are more items in the lists to be added in the code, these are only a sample), but is there a simpler way to code this than what I have done (screenshots below code)?

 

var Itemlist = this.getField("Expense Account Description.0");

var Price = this.getField("Expense Account No.0");

if(event.willCommit)
{
switch(event.value){

case "Production":
  Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]); 
  Price.value = "";
  break;

case "Maintenance":
  Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]); 
  Price.value = "";
  break;

default:
  Itemlist.setItems([""]); 
  Price.value = "";
  break;


}

}

var Itemlist = this.getField("Expense Account Description.1");

var Price = this.getField("Expense Account No.1");

if(event.willCommit)
{
switch(event.value){

case "Production":
  Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]); 
  Price.value = "";
  break;

case "Maintenance":
  Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]); 
  Price.value = "";
  break;

default:
  Itemlist.setItems([""]); 
  Price.value = "";
  break;


}

}

var Itemlist = this.getField("Expense Account Description.2");

var Price = this.getField("Expense Account No.2");

if(event.willCommit)
{
switch(event.value){

case "Production":
  Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]); 
  Price.value = "";
  break;

case "Maintenance":
  Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]); 
  Price.value = "";
  break;

default:
  Itemlist.setItems([""]); 
  Price.value = "";
  break;


}

}

 

ss1.jpgss2.jpgss3.jpgss4.jpg2. Secondly, the amounts in the "Amount Excl." and "VAT" column do not update to the correct amounts as they should when for instance the value is changed in the "Amount Incl." column and the "Yes" option was initially checked under the "VAT?" dropdown (they do however update automatically).  The dropdown needs to be clicked "No" / "blank" and then clicked "Yes" for a second time for the columns to then update to the correct amounts (VAT needs to remain consistent at 15% of the “Amount Excl.”) - this is done automatically in Excel.

 

Can this be fixed to auto-update correctly in the code? And where?

 

This poses a problem if, say someone entered the incorrect amount initially and selected "Yes" for "VAT" and then wanted to change that amount before completing the form, but wasn't aware that they needed to click through the options again to ensure the correct “VAT” and “Amount Excl.” amounts were displayed and neglected to check the percentage. (see below code for "VAT?" dropdown under 'custom keystroke script' under the 'format' tab in 'properties' and screenshots below):

 

if(event.willCommit)
{
console.println(event.value);
	switch(event.value)
	{
		 case "Yes":
				this.getField("VATRow1.0").value = this.getField("Amount InclRow1.0").value / 1.15 * 0.15;
				break;
		 case "No":
				this.getField("VATRow1.0").value = 0;
				break;
		 default:
				this.getField("VATRow1.0").value = 0;
				break;
	
	}
}

 

ssv1.jpgssv2.jpgssv3.jpg 

TOPICS
JavaScript , PDF forms
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2022 Oct 12, 2022

In dropdown fields properties under 'Options' tab check 'Commit selected value immediately', also if you have issue with delay select 'Prepare form' tool, click on 'More' then on 'Set field calculation order' and make sure fields that calculate firsts are on top.

If it would be helpful to you, you could set account number as an export value so when an account is selected the number is automatically populated, something like this:

Itemlist.setItems([["-Select Production Account-",""],["Purchases Design Consumables","710001"],["Production Consumables - Roll","710100"]]);

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2022 Oct 12, 2022

Hi, thanks for the reply.

I had already done what you've suggested for the dropdown fields - I'll leave as is as it works although it takes some time to load each field in "Expense Account Description" once "Department" is selected.

For the calculations: I had already set the field calculation order as you mentioned and it still behaves the same way (not auto-updating), I also tried it in reverse just to see if it changed: you still need to click another dropdown option and then click 'yes' again in order for the correct amount to appear in the "Amount Excl." and "VAT" columns.  Is there anything else I could try?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2022 Oct 12, 2022

Please share your file. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 12, 2022 Oct 12, 2022

...the links to the PDF, as well as the original Excel file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2022 Oct 12, 2022

Calculation is not updating because you use script as custom keystroke so if you select "Yes" and then change 'Account incl' you need to go back and reselect yes, so instead of custom keystroke script use this as custom calculation script:

if(event.value == "1")
this.getField("VATRow1.0").value = Number(this.getField("Amount InclRow1.0").valueAsString) / 1.15 * 0.15;
else
this.getField("VATRow1.0").value = 0;

 

Instead of using that big script in "Department" you could use a loop to go through all fields or set function in document level script and then call it in "Department" field, it would most likely speed up the process.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2022 Oct 19, 2022
LATEST

Hi, 

I've done as you've suggested with the custom calculation script and that part works perfectly now - thanks!  I don't know how to use a loop/document level script and tried researching, but not sure how to go about it.  I've got the document to work as intended, although when selecting a 'department' in that dropdown list - for a large list of items - it can take up to 25 seconds to load the list.  Would you be able to assist with code that may be able to quicken that part of the process?  Here's the link to the latest file. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines