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

extract data from excel as a specific script

Community Beginner ,
Dec 24, 2021 Dec 24, 2021

i have excel file has just 2 colomns but contains 3000 names and thier ID, it will be difficult to put all this data mnually in my script:

 

function PopulateFlightCrewCode() { for (var i=1; i<9; i++) { this.getField("code." + i).setItems([

["", ""],

["75428", "ABDALLAH BAHEY"],

]); } }

 

can i find way to extract automatically the data from the excel sheet as the underlined script ?

thanks in advance 

TOPICS
JavaScript , PDF forms
2.9K
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 25, 2021 Dec 25, 2021

Copy the contents of the Excel spreadsheet to a plain-text file. I recommend using something like Notepad++. Then use the Search and Replace command (with Reg Exp option enabled) and replace all instances of [\t] with [", "], and [\r\n] with ["],\r\n["] (search terms are in red square brackets).

Then fix the first and last lines, and your code is ready!

 

Another option is to use a script to do it directly. For example, this (paid-for) tool I've created will allow you to import the contents of a spreadsheet (after you saved it as a plain-text file) to the drop-down, including export values, if you wish to do so: https://www.try67.com/tool/acrobat-import-items-from-a-text-file-to-a-combo-box-or-list-field

 

View solution in original post

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 ,
Dec 25, 2021 Dec 25, 2021

Copy the contents of the Excel spreadsheet to a plain-text file. I recommend using something like Notepad++. Then use the Search and Replace command (with Reg Exp option enabled) and replace all instances of [\t] with [", "], and [\r\n] with ["],\r\n["] (search terms are in red square brackets).

Then fix the first and last lines, and your code is ready!

 

Another option is to use a script to do it directly. For example, this (paid-for) tool I've created will allow you to import the contents of a spreadsheet (after you saved it as a plain-text file) to the drop-down, including export values, if you wish to do so: https://www.try67.com/tool/acrobat-import-items-from-a-text-file-to-a-combo-box-or-list-field

 

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 Beginner ,
Dec 25, 2021 Dec 25, 2021

where i can find [\t] in the notepad++ ?

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 ,
Dec 25, 2021 Dec 25, 2021

\t just means tabs.  Remove the tabs using the find and replace tool. 

 

There is also a free PDF file here that contains code for loading copied and pasted text into a list/dropdown field. Which is a good place to  keep this kind of data.

 

https://www.pdfscripting.com/public/Free-Sample-PDF-Files-with-scripts.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Dec 25, 2021 Dec 25, 2021

thank you mr thom, but i want to put this in one loop script not in the dropdown list, because i want to populate this data for 20 dropdown list.

if i used your file, i have to insert the value manually for each item, which will be more time

i am trying to use this sccript to get the item and the value at the same time

but i can not enter the 3000 name with ID from the excel sheet automatically in the brackets 

 

function PopulateFlightCrewCode() { for (var i=1; i<9; i++) { this.getField("code." + i).setItems([

["", ""],

["75428", "ABDALLAH BAHEY"],

]); } }

 

 

 

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 ,
Dec 25, 2021 Dec 25, 2021

Well actually, the idea is just to get the data in a form that can be used by Acrobt JavaScript. Whether it's hard coded in a script, or in a form field.  Either way you can then use a script to copy the data somewhere else. That's the beauty of code. You can make it do almost anything you want automatically, so you don't have to do things manaually. 

 

So the free PDF file contains code for copying the data out of a text field and into a dropdown. It's pretty close to exactly the code you need. You would benefit greatly from downloading the file and examining the script.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 25, 2021 Dec 25, 2021

You don't find it, you enter it, like this:

 

try67_0-1640463047365.pngexpand image

 

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 Beginner ,
Dec 25, 2021 Dec 25, 2021

abdallam73011229_0-1640464380951.pngexpand image

thank you so much but i am really can not do this, if you please give me another help

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 ,
Dec 25, 2021 Dec 25, 2021

This is not Notepad++, which isn't available for Macs. I can't help you further, since I'm not a Mac guy and don't know what the equivalent there would be.

If you want I can do it for you, for a small fee. You can contact me privately via [try6767 at gmail.com] to discuss it further, if you wish.

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 ,
Dec 25, 2021 Dec 25, 2021

Probably the closest you will get to Notepad++ is BBEdit. 

https://www.barebones.com/products/bbedit/

After the trial runs out, you can still run it with limited functions (but still powerful).

David Creamer: Community Expert (ACI and ACE 1995-2023)
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 Beginner ,
Dec 25, 2021 Dec 25, 2021
LATEST

it works, it did it by windows

thank you so much

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 ,
Dec 25, 2021 Dec 25, 2021
quote

i have excel file has just 2 colomns but contains 3000 names and thier ID, it will be difficult to put all this data mnually in my script:

 

function PopulateFlightCrewCode() { for (var i=1; i<9; i++) { this.getField("code." + i).setItems([

["", ""],

["75428", "ABDALLAH BAHEY"],

]); } }

 

can i find way to extract automatically the data from the excel sheet as the underlined script ?

thanks in advance 


By abdallam73011229

 

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 ,
Dec 25, 2021 Dec 25, 2021

>>it will be difficult to put all this data mnually...

I don't know what you want these to look like in InDesign, but you could just move the columns together, create a named region in Excel, and place the named region. 

David Creamer: Community Expert (ACI and ACE 1995-2023)
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