Skip to main content
abdallam73011229
Known Participant
December 25, 2021
Answered

extract data from excel as a specific script

  • December 25, 2021
  • 3 replies
  • 3504 views

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 

This topic has been closed for replies.
Correct answer try67

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

 

3 replies

Dave Creamer of IDEAS
Community Expert
Community Expert
December 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)
Participant
December 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

 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 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

 

abdallam73011229
Known Participant
December 25, 2021

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

Thom Parker
Community Expert
Community Expert
December 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 PDFScriptingUse the Acrobat JavaScript Reference early and often