Copy link to clipboard
Copied
Hello! I am very new to JavaScript programming within Adobe and am trying to pull an external list of strings (format can change, however, pulling from an Excel file would be most efficient) into an Adobe Pro DC JavaScript as an array, in order to search for that list of strings through the PDF. I have the code working so that I can hard code the strings into the JavaScript. Please let me know if you have any direction or can help me with this. Thank you very much for your time in advance!
Chris
Copy link to clipboard
Copied
You can't read data directly from an Excel file, as it is not a plain-text file. You will need to first convert it to something like a tab-delimited text file, a CSV file, or even an XML file, and then you would be able to read it directly using a script.
Copy link to clipboard
Copied
I'm able to manually copy the Excel (or really, probably write a VBA script that saves certain cells into a CSV file). Once I do that, how can I import that CSV into an array? Thank you for the quick response!
Copy link to clipboard
Copied
You can use a method like readFileIntoStream of the util object, or even import the file as a data-object (importDataObject), read its contents (getDataObjectContents) and then remove it (removeDataObject, all under the Document object).
Copy link to clipboard
Copied
So I got the readFileIntoStream file explorer to work, but am struggling in understanding how to store that data as an array within my code?
var StringArray = util.readFileIntoStream();
and then later in the code I have
for (var m = 0; m < stringArray.length; m++)
{
if (string == stringArray
Action
break }
}
Am I doing this incorrectly? Thank you!
Copy link to clipboard
Copied
You need to read the documentation of these methods carefully. The readFileIntoStream method returns a Stream object, which you then need to convert into a String, which in turn you can parse by splitting it two times: Once, converting it into an array of lines, and then another time, converting each line to an array of the individual items in it.
Copy link to clipboard
Copied
As I said, I'm brand new to JavaScript and coding in general. I appreciate the help, and just as a point of feedback, telling me to read the documentation carefully comes across as condescending to a new user. I read the documentation but didn't understand a vast majority of it. Thank you. Have a good day.
Copy link to clipboard
Copied
Did you expect me to write your full code for you? As you've seen, this is not a simple task. I'm happy to do it for you, for a fee.
You can contact me privately (try6767 at gmail.com) and we could discuss it further.
I'm sorry if it came over as condescending, but I believe I've provided you a lot of valuable information about how this can be achieved, and reading the documentation (which also contains code samples) is truly the best way to learn how to do it for yourself.