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

JavaScript interaction with Excel/Txt Files

New Here ,
Aug 16, 2018 Aug 16, 2018

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

660

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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.

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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!

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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).

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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!

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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.

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

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.

Votes

Translate

Translate

Report

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 ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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